Skip to content

Commit bfe8fb7

Browse files
author
Dnld
committed
adds tests for subscript additions/reassignment of dictionary and array values
1 parent 26de3ce commit bfe8fb7

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

tests/lexerTests/lexerTestsFirstMilestone.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,35 @@ describe('Lexer: First milestone', function() {
285285
];
286286
expect(lexer(input)).to.deep.equal(output);
287287
});
288+
289+
it('should handle addition/reassignment of array items via subscript', function () {
290+
input = String.raw `var arr = [2,2,3,4,5]; arr[0] = 1`;
291+
output = [
292+
{ type: "DECLARATION_KEYWORD", value: "var" },
293+
{ type: "IDENTIFIER", value: "arr" },
294+
{ type: "OPERATOR", value: "=" },
295+
{ type: "ARRAY_START", value: "[" },
296+
{ type: "NUMBER", value: "2" },
297+
{ type: "PUNCTUATION", value: "," },
298+
{ type: "NUMBER", value: "2" },
299+
{ type: "PUNCTUATION", value: "," },
300+
{ type: "NUMBER", value: "3" },
301+
{ type: "PUNCTUATION", value: "," },
302+
{ type: "NUMBER", value: "4" },
303+
{ type: "PUNCTUATION", value: "," },
304+
{ type: "NUMBER", value: "5" },
305+
{ type: "ARRAY_END", value: "]" },
306+
{ type: "PUNCTUATION", value: ";" },
307+
{ type: "IDENTIFIER", value: "arr" },
308+
{ type: "SUBSCRIPT_LOOKUP_START", value: "[" },
309+
{ type: "NUMBER", value: "0" },
310+
{ type: "SUBSCRIPT_LOOKUP_END", value: "]" },
311+
{ type: "OPERATOR", value: "=" },
312+
{ type: "NUMBER", value: "1" },
313+
{ type: "TERMINATOR", value: "EOF" }
314+
];
315+
expect(lexer(input)).to.deep.equal(output);
316+
});
288317

289318
it('should handle appending items to an array with the addition assignment operator', function () {
290319
input = String.raw`var arr = [Int](); arr += [1,2,3];`;
@@ -338,6 +367,37 @@ describe('Lexer: First milestone', function() {
338367
expect(lexer(input)).to.deep.equal(output);
339368
});
340369

370+
it('should handle the addition/reassignment of dictionary items via subscript', function () {
371+
input = String.raw `var f = ["one": 1, "two": 2, "three": 3]; f["four"] = 4`;
372+
output = [
373+
{ type: "DECLARATION_KEYWORD", value: "var" },
374+
{ type: "IDENTIFIER", value: "f" },
375+
{ type: "OPERATOR", value: "=" },
376+
{ type: "DICTIONARY_START", value: "[" },
377+
{ type: "STRING", value: "one" },
378+
{ type: "PUNCTUATION", value: ":" },
379+
{ type: "NUMBER", value: "1" },
380+
{ type: "PUNCTUATION", value: "," },
381+
{ type: "STRING", value: "two" },
382+
{ type: "PUNCTUATION", value: ":" },
383+
{ type: "NUMBER", value: "2" },
384+
{ type: "PUNCTUATION", value: "," },
385+
{ type: "STRING", value: "three" },
386+
{ type: "PUNCTUATION", value: ":" },
387+
{ type: "NUMBER", value: "3" },
388+
{ type: "DICTIONARY_END", value: "]" },
389+
{ type: "PUNCTUATION", value: ";" },
390+
{ type: "IDENTIFIER", value: "f" },
391+
{ type: "SUBSCRIPT_LOOKUP_START", value: "[" },
392+
{ type: "STRING", value: "four" },
393+
{ type: "SUBSCRIPT_LOOKUP_END", value: "]" },
394+
{ type: "OPERATOR", value: "=" },
395+
{ type: "NUMBER", value: "4" },
396+
{ type: "TERMINATOR", value: "EOF" }
397+
];
398+
expect(lexer(input)).to.deep.equal(output);
399+
});
400+
341401
it('should handle tuples', function () {
342402
input = String.raw`var error = (404, "not found")`;
343403
output = [

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