Skip to content

Commit 73522ad

Browse files
author
Dnld
committed
handles starts with method, adds appropriate tests
1 parent 554b085 commit 73522ad

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed

tests/lexerTests/lexerTestsThirdMilestone.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5124,6 +5124,62 @@ describe('Lexer: Third Milestone', function() {
51245124
expect(lexer(input)).to.deep.equal(output);
51255125
});
51265126

5127+
it('should handle the starts with method', function () {
5128+
input = String.raw `var arr = [1,2,3,4,5]
5129+
var yes = arr.startsWith([1,2,3])
5130+
var no = arr.startsWith([2,3])`;
5131+
output = [
5132+
{ type: "DECLARATION_KEYWORD", value: "var" },
5133+
{ type: "IDENTIFIER", value: "arr" },
5134+
{ type: "OPERATOR", value: "=" },
5135+
{ type: "ARRAY_START", value: "[" },
5136+
{ type: "NUMBER", value: "1" },
5137+
{ type: "PUNCTUATION", value: "," },
5138+
{ type: "NUMBER", value: "2" },
5139+
{ type: "PUNCTUATION", value: "," },
5140+
{ type: "NUMBER", value: "3" },
5141+
{ type: "PUNCTUATION", value: "," },
5142+
{ type: "NUMBER", value: "4" },
5143+
{ type: "PUNCTUATION", value: "," },
5144+
{ type: "NUMBER", value: "5" },
5145+
{ type: "ARRAY_END", value: "]" },
5146+
{ type: "TERMINATOR", value: "\\n"},
5147+
5148+
{ type: "DECLARATION_KEYWORD", value: "var" },
5149+
{ type: "IDENTIFIER", value: "yes" },
5150+
{ type: "OPERATOR", value: "=" },
5151+
{ type: "IDENTIFIER", value: "arr" },
5152+
{ type: "DOT_SYNTAX", value: "." },
5153+
{ type: "NATIVE_METHOD", value: "startsWith" },
5154+
{ type: "INVOCATION_START", value: "(" },
5155+
{ type: "ARRAY_START", value: "[" },
5156+
{ type: "NUMBER", value: "1" },
5157+
{ type: "PUNCTUATION", value: "," },
5158+
{ type: "NUMBER", value: "2" },
5159+
{ type: "PUNCTUATION", value: "," },
5160+
{ type: "NUMBER", value: "3" },
5161+
{ type: "ARRAY_END", value: "]" },
5162+
{ type: "INVOCATION_END", value: ")" },
5163+
{ type: "TERMINATOR", value: "\\n"},
5164+
5165+
{ type: "DECLARATION_KEYWORD", value: "var" },
5166+
{ type: "IDENTIFIER", value: "no" },
5167+
{ type: "OPERATOR", value: "=" },
5168+
{ type: "IDENTIFIER", value: "arr" },
5169+
{ type: "DOT_SYNTAX", value: "." },
5170+
{ type: "NATIVE_METHOD", value: "startsWith" },
5171+
{ type: "INVOCATION_START", value: "(" },
5172+
{ type: "ARRAY_START", value: "[" },
5173+
{ type: "NUMBER", value: "2" },
5174+
{ type: "PUNCTUATION", value: "," },
5175+
{ type: "NUMBER", value: "3" },
5176+
{ type: "ARRAY_END", value: "]" },
5177+
{ type: "INVOCATION_END", value: ")" },
5178+
{ type: "TERMINATOR", value: "EOF" }
5179+
];
5180+
expect(lexer(input)).to.deep.equal(output);
5181+
});
5182+
51275183
});
51285184

51295185
});

transpiler/lexer/lexicalTypes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ module.exports = {
3333
'removeValueForKey': 'NATIVE_METHOD',
3434
'replaceRange': 'NATIVE_METHOD',
3535
'successor': 'NATIVE_METHOD',
36+
'startsWith': 'NATIVE_METHOD',
3637
'updateValue': 'NATIVE_METHOD',
3738
},
3839

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy