Skip to content

Commit 5fbe1a4

Browse files
author
Dnld
committed
adds tests to cover tuple reassignment
1 parent bfe8fb7 commit 5fbe1a4

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

tests/lexerTests/lexerTestsFirstMilestone.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,28 @@ describe('Lexer: First milestone', function() {
413413
];
414414
expect(lexer(input)).to.deep.equal(output);
415415
});
416+
417+
it('should handle the reassignment of tuple items via dot notation', function () {
418+
input = String.raw `var randNumString = (4, "hello"); randNumString.0 = 5`;
419+
output = [
420+
{ type: "DECLARATION_KEYWORD", value: "var" },
421+
{ type: "IDENTIFIER", value: "randNumString" },
422+
{ type: "OPERATOR", value: "=" },
423+
{ type: "TUPLE_START", value: "("},
424+
{ type: "NUMBER", value: "4"},
425+
{ type: "PUNCTUATION", value: "," },
426+
{ type: "STRING", value: "hello"},
427+
{ type: "TUPLE_END", value: ")"},
428+
{ type: "PUNCTUATION", value: ";" },
429+
{ type: "IDENTIFIER", value: "randNumString" },
430+
{ type: "DOT_SYNTAX", value: "." },
431+
{ type: "NUMBER", value: "0"},
432+
{ type: "OPERATOR", value: "=" },
433+
{ type: "NUMBER", value: "5"},
434+
{ type: "TERMINATOR", value: "EOF" }
435+
];
436+
expect(lexer(input)).to.deep.equal(output);
437+
});
416438

417439
it('should handle tuples with element names', function () {
418440
input = String.raw`let http200Status = (statusCode: 200, description: "OK");`;
@@ -435,6 +457,32 @@ describe('Lexer: First milestone', function() {
435457
expect(lexer(input)).to.deep.equal(output);
436458
});
437459

460+
it('should handle the reassignment of tuple items identified by element name via dot notation', function () {
461+
input = String.raw`var randNumString = (num: 4, str: "hello"); randNumString.num = 5`;
462+
output = [
463+
{ type: "DECLARATION_KEYWORD", value: "var" },
464+
{ type: "IDENTIFIER", value: "randNumString" },
465+
{ type: "OPERATOR", value: "=" },
466+
{ type: "TUPLE_START", value: "("},
467+
{ type: "TUPLE_ELEMENT_NAME", value: "num"},
468+
{ type: "PUNCTUATION", value: ":" },
469+
{ type: "NUMBER", value: "4"},
470+
{ type: "PUNCTUATION", value: "," },
471+
{ type: "TUPLE_ELEMENT_NAME", value: "str"},
472+
{ type: "PUNCTUATION", value: ":" },
473+
{ type: "STRING", value: "hello"},
474+
{ type: "TUPLE_END", value: ")"},
475+
{ type: "PUNCTUATION", value: ";" },
476+
{ type: "IDENTIFIER", value: "randNumString" },
477+
{ type: "DOT_SYNTAX", value: "." },
478+
{ type: "TUPLE_ELEMENT_NAME", value: "num"},
479+
{ type: "OPERATOR", value: "=" },
480+
{ type: "NUMBER", value: "5"},
481+
{ type: "TERMINATOR", value: "EOF" }
482+
];
483+
expect(lexer(input)).to.deep.equal(output);
484+
});
485+
438486
it('should handle empty tuples', function () {
439487
input = String.raw`var empty = ()`;
440488
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