Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: pkg/front_end/test/scanner_test.dart

Issue 2799133003: enhance analyzer to parse uppercase and built-in/pseudo keywords (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 import 'package:front_end/src/base/errors.dart'; 5 import 'package:front_end/src/base/errors.dart';
6 import 'package:front_end/src/base/jenkins_smi_hash.dart'; 6 import 'package:front_end/src/base/jenkins_smi_hash.dart';
7 import 'package:front_end/src/scanner/errors.dart'; 7 import 'package:front_end/src/scanner/errors.dart';
8 import 'package:front_end/src/scanner/reader.dart'; 8 import 'package:front_end/src/scanner/reader.dart';
9 import 'package:front_end/src/scanner/scanner.dart'; 9 import 'package:front_end/src/scanner/scanner.dart';
10 import 'package:front_end/src/scanner/token.dart'; 10 import 'package:front_end/src/scanner/token.dart';
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Analyzer's token streams don't consider "<" to be an opener 173 // Analyzer's token streams don't consider "<" to be an opener
174 // but fasta does. 174 // but fasta does.
175 if (lessThan is BeginToken) { 175 if (lessThan is BeginToken) {
176 expect(lessThan.endToken, greaterThan); 176 expect(lessThan.endToken, greaterThan);
177 } 177 }
178 expect(greaterThan, isNot(new isInstanceOf<BeginToken>())); 178 expect(greaterThan, isNot(new isInstanceOf<BeginToken>()));
179 } 179 }
180 180
181 void test_async_star() { 181 void test_async_star() {
182 Token token = _scan("async*"); 182 Token token = _scan("async*");
183 expect(token.type, TokenType.IDENTIFIER); 183 expect(token.type, TokenType.KEYWORD);
184 expect(token.lexeme, 'async'); 184 expect(token.lexeme, 'async');
185 expect(token.next.type, TokenType.STAR); 185 expect(token.next.type, TokenType.STAR);
186 expect(token.next.next.type, TokenType.EOF); 186 expect(token.next.next.type, TokenType.EOF);
187 } 187 }
188 188
189 void test_at() { 189 void test_at() {
190 _assertToken(TokenType.AT, "@"); 190 _assertToken(TokenType.AT, "@");
191 } 191 }
192 192
193 void test_backping() { 193 void test_backping() {
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 464
465 void test_keyword_as() { 465 void test_keyword_as() {
466 _assertKeywordToken("as"); 466 _assertKeywordToken("as");
467 } 467 }
468 468
469 void test_keyword_assert() { 469 void test_keyword_assert() {
470 _assertKeywordToken("assert"); 470 _assertKeywordToken("assert");
471 } 471 }
472 472
473 void test_keyword_async() { 473 void test_keyword_async() {
474 _assertIdentifierToken("async"); 474 _assertKeywordToken("async");
475 } 475 }
476 476
477 void test_keyword_await() { 477 void test_keyword_await() {
478 _assertIdentifierToken("await"); 478 _assertKeywordToken("await");
479 } 479 }
480 480
481 void test_keyword_break() { 481 void test_keyword_break() {
482 _assertKeywordToken("break"); 482 _assertKeywordToken("break");
483 } 483 }
484 484
485 void test_keyword_case() { 485 void test_keyword_case() {
486 _assertKeywordToken("case"); 486 _assertKeywordToken("case");
487 } 487 }
488 488
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 552
553 void test_keyword_for() { 553 void test_keyword_for() {
554 _assertKeywordToken("for"); 554 _assertKeywordToken("for");
555 } 555 }
556 556
557 void test_keyword_get() { 557 void test_keyword_get() {
558 _assertKeywordToken("get"); 558 _assertKeywordToken("get");
559 } 559 }
560 560
561 void test_keyword_hide() { 561 void test_keyword_hide() {
562 _assertIdentifierToken("hide"); 562 _assertKeywordToken("hide");
563 } 563 }
564 564
565 void test_keyword_if() { 565 void test_keyword_if() {
566 _assertKeywordToken("if"); 566 _assertKeywordToken("if");
567 } 567 }
568 568
569 void test_keyword_implements() { 569 void test_keyword_implements() {
570 _assertKeywordToken("implements"); 570 _assertKeywordToken("implements");
571 } 571 }
572 572
573 void test_keyword_import() { 573 void test_keyword_import() {
574 _assertKeywordToken("import"); 574 _assertKeywordToken("import");
575 } 575 }
576 576
577 void test_keyword_in() { 577 void test_keyword_in() {
578 _assertKeywordToken("in"); 578 _assertKeywordToken("in");
579 } 579 }
580 580
581 void test_keyword_is() { 581 void test_keyword_is() {
582 _assertKeywordToken("is"); 582 _assertKeywordToken("is");
583 } 583 }
584 584
585 void test_keyword_library() { 585 void test_keyword_library() {
586 _assertKeywordToken("library"); 586 _assertKeywordToken("library");
587 } 587 }
588 588
589 void test_keyword_native() { 589 void test_keyword_native() {
590 _assertIdentifierToken("native"); 590 _assertKeywordToken("native");
591 } 591 }
592 592
593 void test_keyword_new() { 593 void test_keyword_new() {
594 _assertKeywordToken("new"); 594 _assertKeywordToken("new");
595 } 595 }
596 596
597 void test_keyword_null() { 597 void test_keyword_null() {
598 _assertKeywordToken("null"); 598 _assertKeywordToken("null");
599 } 599 }
600 600
601 void test_keyword_of() { 601 void test_keyword_of() {
602 _assertIdentifierToken("of"); 602 _assertKeywordToken("of");
603 } 603 }
604 604
605 void test_keyword_on() { 605 void test_keyword_on() {
606 _assertIdentifierToken("on"); 606 _assertKeywordToken("on");
607 } 607 }
608 608
609 void test_keyword_operator() { 609 void test_keyword_operator() {
610 _assertKeywordToken("operator"); 610 _assertKeywordToken("operator");
611 } 611 }
612 612
613 void test_keyword_part() { 613 void test_keyword_part() {
614 _assertKeywordToken("part"); 614 _assertKeywordToken("part");
615 } 615 }
616 616
617 void test_keyword_patch() { 617 void test_keyword_patch() {
618 _assertIdentifierToken("patch"); 618 _assertKeywordToken("patch");
619 } 619 }
620 620
621 void test_keyword_rethrow() { 621 void test_keyword_rethrow() {
622 _assertKeywordToken("rethrow"); 622 _assertKeywordToken("rethrow");
623 } 623 }
624 624
625 void test_keyword_return() { 625 void test_keyword_return() {
626 _assertKeywordToken("return"); 626 _assertKeywordToken("return");
627 } 627 }
628 628
629 void test_keyword_set() { 629 void test_keyword_set() {
630 _assertKeywordToken("set"); 630 _assertKeywordToken("set");
631 } 631 }
632 632
633 void test_keyword_show() { 633 void test_keyword_show() {
634 _assertIdentifierToken("show"); 634 _assertKeywordToken("show");
635 } 635 }
636 636
637 void test_keyword_source() { 637 void test_keyword_source() {
638 _assertIdentifierToken("source"); 638 _assertKeywordToken("source");
639 } 639 }
640 640
641 void test_keyword_static() { 641 void test_keyword_static() {
642 _assertKeywordToken("static"); 642 _assertKeywordToken("static");
643 } 643 }
644 644
645 void test_keyword_super() { 645 void test_keyword_super() {
646 _assertKeywordToken("super"); 646 _assertKeywordToken("super");
647 } 647 }
648 648
649 void test_keyword_switch() { 649 void test_keyword_switch() {
650 _assertKeywordToken("switch"); 650 _assertKeywordToken("switch");
651 } 651 }
652 652
653 void test_keyword_sync() { 653 void test_keyword_sync() {
654 _assertIdentifierToken("sync"); 654 _assertKeywordToken("sync");
655 } 655 }
656 656
657 void test_keyword_this() { 657 void test_keyword_this() {
658 _assertKeywordToken("this"); 658 _assertKeywordToken("this");
659 } 659 }
660 660
661 void test_keyword_throw() { 661 void test_keyword_throw() {
662 _assertKeywordToken("throw"); 662 _assertKeywordToken("throw");
663 } 663 }
664 664
(...skipping 19 matching lines...) Expand all
684 684
685 void test_keyword_while() { 685 void test_keyword_while() {
686 _assertKeywordToken("while"); 686 _assertKeywordToken("while");
687 } 687 }
688 688
689 void test_keyword_with() { 689 void test_keyword_with() {
690 _assertKeywordToken("with"); 690 _assertKeywordToken("with");
691 } 691 }
692 692
693 void test_keyword_yield() { 693 void test_keyword_yield() {
694 _assertIdentifierToken("yield"); 694 _assertKeywordToken("yield");
695 } 695 }
696 696
697 void test_lt() { 697 void test_lt() {
698 _assertToken(TokenType.LT, "<"); 698 _assertToken(TokenType.LT, "<");
699 } 699 }
700 700
701 void test_lt_eq() { 701 void test_lt_eq() {
702 _assertToken(TokenType.LT_EQ, "<="); 702 _assertToken(TokenType.LT_EQ, "<=");
703 } 703 }
704 704
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [ 1161 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [
1162 new StringToken(TokenType.STRING, "'", 0), 1162 new StringToken(TokenType.STRING, "'", 0),
1163 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), 1163 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1),
1164 new StringToken(TokenType.IDENTIFIER, "name", 2), 1164 new StringToken(TokenType.IDENTIFIER, "name", 2),
1165 new StringToken(TokenType.STRING, "", 6) 1165 new StringToken(TokenType.STRING, "", 6)
1166 ]); 1166 ]);
1167 } 1167 }
1168 1168
1169 void test_sync_star() { 1169 void test_sync_star() {
1170 Token token = _scan("sync*"); 1170 Token token = _scan("sync*");
1171 expect(token.type, TokenType.IDENTIFIER); 1171 expect(token.type, TokenType.KEYWORD);
1172 expect(token.lexeme, 'sync'); 1172 expect(token.lexeme, 'sync');
1173 expect(token.next.type, TokenType.STAR); 1173 expect(token.next.type, TokenType.STAR);
1174 expect(token.next.next.type, TokenType.EOF); 1174 expect(token.next.next.type, TokenType.EOF);
1175 } 1175 }
1176 1176
1177 void test_tilde() { 1177 void test_tilde() {
1178 _assertToken(TokenType.TILDE, "~"); 1178 _assertToken(TokenType.TILDE, "~");
1179 } 1179 }
1180 1180
1181 void test_tilde_slash() { 1181 void test_tilde_slash() {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 */ 1257 */
1258 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset, 1258 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset,
1259 String source, List<Token> expectedTokens) { 1259 String source, List<Token> expectedTokens) {
1260 ErrorListener listener = new ErrorListener(); 1260 ErrorListener listener = new ErrorListener();
1261 Token token = scanWithListener(source, listener); 1261 Token token = scanWithListener(source, listener);
1262 listener.assertErrors([new TestError(expectedOffset, expectedError, null)]); 1262 listener.assertErrors([new TestError(expectedOffset, expectedError, null)]);
1263 _checkTokens(token, expectedTokens); 1263 _checkTokens(token, expectedTokens);
1264 } 1264 }
1265 1265
1266 /** 1266 /**
1267 * Assert that when scanned the given [source] contains a single identifier
1268 * token with the same lexeme as the original source.
1269 */
1270 void _assertIdentifierToken(String source) {
1271 void check(String s, int expectedOffset) {
1272 Token token = _scan(s);
1273 expect(token, isNotNull);
1274 expect(token.type, TokenType.IDENTIFIER);
1275 expect(token.offset, expectedOffset);
1276 expect(token.length, source.length);
1277 expect(token.lexeme, source);
1278 expect(token.value(), source);
1279 expect(token.next.type, TokenType.EOF);
1280 }
1281
1282 check(source, 0);
1283 check(' $source ', 1);
1284 }
1285
1286 /**
1287 * Assert that when scanned the given [source] contains a single keyword token 1267 * Assert that when scanned the given [source] contains a single keyword token
1288 * with the same lexeme as the original source. 1268 * with the same lexeme as the original source.
1289 */ 1269 */
1290 void _assertKeywordToken(String source) { 1270 void _assertKeywordToken(String source) {
1291 Token token = _scan(source); 1271 Token token = _scan(source);
1292 expect(token, isNotNull); 1272 expect(token, isNotNull);
1293 expect(token.type, TokenType.KEYWORD); 1273 expect(token.type, TokenType.KEYWORD);
1294 expect(token.offset, 0); 1274 expect(token.offset, 0);
1295 expect(token.length, source.length); 1275 expect(token.length, source.length);
1296 expect(token.lexeme, source); 1276 expect(token.lexeme, source);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1519 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader); 1499 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader);
1520 1500
1521 @override 1501 @override
1522 void reportError( 1502 void reportError(
1523 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1503 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1524 if (listener != null) { 1504 if (listener != null) {
1525 listener.errors.add(new TestError(offset, errorCode, arguments)); 1505 listener.errors.add(new TestError(offset, errorCode, arguments));
1526 } 1506 }
1527 } 1507 }
1528 } 1508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698