OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.scanner_test; | 5 library engine.scanner_test; |
6 | 6 |
7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
8 import 'package:analyzer/src/generated/scanner.dart'; | 8 import 'package:analyzer/src/generated/scanner.dart'; |
9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
11 | 11 |
12 import '../reflective_tests.dart'; | 12 import '../reflective_tests.dart'; |
13 import 'test_support.dart'; | 13 import 'test_support.dart'; |
14 | 14 |
15 main() { | 15 main() { |
16 groupSep = ' | '; | 16 groupSep = ' | '; |
17 runReflectiveTests(CharSequenceReaderTest); | 17 runReflectiveTests(CharSequenceReaderTest); |
18 runReflectiveTests(KeywordStateTest); | 18 runReflectiveTests(KeywordStateTest); |
19 runReflectiveTests(ScannerTest); | 19 runReflectiveTests(ScannerTest); |
20 runReflectiveTests(TokenTypeTest); | 20 runReflectiveTests(TokenTypeTest); |
21 } | 21 } |
22 | 22 |
23 @reflectiveTest | |
24 class CharSequenceReaderTest { | |
25 void test_advance() { | |
26 CharSequenceReader reader = new CharSequenceReader("x"); | |
27 expect(reader.advance(), 0x78); | |
28 expect(reader.advance(), -1); | |
29 expect(reader.advance(), -1); | |
30 } | |
31 | |
32 void test_creation() { | |
33 expect(new CharSequenceReader("x"), isNotNull); | |
34 } | |
35 | |
36 void test_getOffset() { | |
37 CharSequenceReader reader = new CharSequenceReader("x"); | |
38 expect(reader.offset, -1); | |
39 reader.advance(); | |
40 expect(reader.offset, 0); | |
41 reader.advance(); | |
42 expect(reader.offset, 0); | |
43 } | |
44 | |
45 void test_getString() { | |
46 CharSequenceReader reader = new CharSequenceReader("xyzzy"); | |
47 reader.offset = 3; | |
48 expect(reader.getString(1, 0), "yzz"); | |
49 expect(reader.getString(2, 1), "zzy"); | |
50 } | |
51 | |
52 void test_peek() { | |
53 CharSequenceReader reader = new CharSequenceReader("xy"); | |
54 expect(reader.peek(), 0x78); | |
55 expect(reader.peek(), 0x78); | |
56 reader.advance(); | |
57 expect(reader.peek(), 0x79); | |
58 expect(reader.peek(), 0x79); | |
59 reader.advance(); | |
60 expect(reader.peek(), -1); | |
61 expect(reader.peek(), -1); | |
62 } | |
63 | |
64 void test_setOffset() { | |
65 CharSequenceReader reader = new CharSequenceReader("xyz"); | |
66 reader.offset = 2; | |
67 expect(reader.offset, 2); | |
68 } | |
69 } | |
70 | |
71 class CharacterRangeReaderTest extends EngineTestCase { | 23 class CharacterRangeReaderTest extends EngineTestCase { |
72 void test_advance() { | 24 void test_advance() { |
73 CharSequenceReader baseReader = new CharSequenceReader("xyzzy"); | 25 CharSequenceReader baseReader = new CharSequenceReader("xyzzy"); |
74 CharacterRangeReader reader = new CharacterRangeReader(baseReader, 1, 4); | 26 CharacterRangeReader reader = new CharacterRangeReader(baseReader, 1, 4); |
75 expect(reader.advance(), 0x79); | 27 expect(reader.advance(), 0x79); |
76 expect(reader.advance(), 0x80); | 28 expect(reader.advance(), 0x80); |
77 expect(reader.advance(), 0x80); | 29 expect(reader.advance(), 0x80); |
78 expect(reader.advance(), -1); | 30 expect(reader.advance(), -1); |
79 expect(reader.advance(), -1); | 31 expect(reader.advance(), -1); |
80 } | 32 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 expect(reader.peek(), -1); | 67 expect(reader.peek(), -1); |
116 expect(reader.peek(), -1); | 68 expect(reader.peek(), -1); |
117 } | 69 } |
118 | 70 |
119 void test_setOffset() { | 71 void test_setOffset() { |
120 CharSequenceReader baseReader = new CharSequenceReader("xyzzy"); | 72 CharSequenceReader baseReader = new CharSequenceReader("xyzzy"); |
121 CharacterRangeReader reader = new CharacterRangeReader(baseReader, 1, 4); | 73 CharacterRangeReader reader = new CharacterRangeReader(baseReader, 1, 4); |
122 reader.offset = 2; | 74 reader.offset = 2; |
123 expect(reader.offset, 2); | 75 expect(reader.offset, 2); |
124 } | 76 } |
| 77 } |
| 78 |
| 79 @reflectiveTest |
| 80 class CharSequenceReaderTest { |
| 81 void test_advance() { |
| 82 CharSequenceReader reader = new CharSequenceReader("x"); |
| 83 expect(reader.advance(), 0x78); |
| 84 expect(reader.advance(), -1); |
| 85 expect(reader.advance(), -1); |
| 86 } |
| 87 |
| 88 void test_creation() { |
| 89 expect(new CharSequenceReader("x"), isNotNull); |
| 90 } |
| 91 |
| 92 void test_getOffset() { |
| 93 CharSequenceReader reader = new CharSequenceReader("x"); |
| 94 expect(reader.offset, -1); |
| 95 reader.advance(); |
| 96 expect(reader.offset, 0); |
| 97 reader.advance(); |
| 98 expect(reader.offset, 0); |
| 99 } |
| 100 |
| 101 void test_getString() { |
| 102 CharSequenceReader reader = new CharSequenceReader("xyzzy"); |
| 103 reader.offset = 3; |
| 104 expect(reader.getString(1, 0), "yzz"); |
| 105 expect(reader.getString(2, 1), "zzy"); |
| 106 } |
| 107 |
| 108 void test_peek() { |
| 109 CharSequenceReader reader = new CharSequenceReader("xy"); |
| 110 expect(reader.peek(), 0x78); |
| 111 expect(reader.peek(), 0x78); |
| 112 reader.advance(); |
| 113 expect(reader.peek(), 0x79); |
| 114 expect(reader.peek(), 0x79); |
| 115 reader.advance(); |
| 116 expect(reader.peek(), -1); |
| 117 expect(reader.peek(), -1); |
| 118 } |
| 119 |
| 120 void test_setOffset() { |
| 121 CharSequenceReader reader = new CharSequenceReader("xyz"); |
| 122 reader.offset = 2; |
| 123 expect(reader.offset, 2); |
| 124 } |
125 } | 125 } |
126 | 126 |
127 @reflectiveTest | 127 @reflectiveTest |
128 class KeywordStateTest { | 128 class KeywordStateTest { |
129 void test_KeywordState() { | 129 void test_KeywordState() { |
130 // | 130 // |
131 // Generate the test data to be scanned. | 131 // Generate the test data to be scanned. |
132 // | 132 // |
133 List<Keyword> keywords = Keyword.values; | 133 List<Keyword> keywords = Keyword.values; |
134 int keywordCount = keywords.length; | 134 int keywordCount = keywords.length; |
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 | 586 |
587 void test_lineInfo_multilineString() { | 587 void test_lineInfo_multilineString() { |
588 String source = "'''a\r\nbc\r\nd'''"; | 588 String source = "'''a\r\nbc\r\nd'''"; |
589 _assertLineInfo(source, [ | 589 _assertLineInfo(source, [ |
590 new ScannerTest_ExpectedLocation(0, 1, 1), | 590 new ScannerTest_ExpectedLocation(0, 1, 1), |
591 new ScannerTest_ExpectedLocation(7, 2, 2), | 591 new ScannerTest_ExpectedLocation(7, 2, 2), |
592 new ScannerTest_ExpectedLocation(source.length - 1, 3, 4) | 592 new ScannerTest_ExpectedLocation(source.length - 1, 3, 4) |
593 ]); | 593 ]); |
594 } | 594 } |
595 | 595 |
| 596 void test_lineInfo_multilineString_raw() { |
| 597 String source = "var a = r'''\nblah\n''';\n\nfoo"; |
| 598 _assertLineInfo(source, [ |
| 599 new ScannerTest_ExpectedLocation(0, 1, 1), |
| 600 new ScannerTest_ExpectedLocation(14, 2, 2), |
| 601 new ScannerTest_ExpectedLocation(source.length - 2, 5, 2) |
| 602 ]); |
| 603 } |
| 604 |
596 void test_lineInfo_simpleClass() { | 605 void test_lineInfo_simpleClass() { |
597 String source = | 606 String source = |
598 "class Test {\r\n String s = '...';\r\n int get x => s.MISSING_GET
TER;\r\n}"; | 607 "class Test {\r\n String s = '...';\r\n int get x => s.MISSING_GET
TER;\r\n}"; |
599 _assertLineInfo(source, [ | 608 _assertLineInfo(source, [ |
600 new ScannerTest_ExpectedLocation(0, 1, 1), | 609 new ScannerTest_ExpectedLocation(0, 1, 1), |
601 new ScannerTest_ExpectedLocation(source.indexOf("MISSING_GETTER"), 3, 20), | 610 new ScannerTest_ExpectedLocation(source.indexOf("MISSING_GETTER"), 3, 20), |
602 new ScannerTest_ExpectedLocation(source.length - 1, 4, 1) | 611 new ScannerTest_ExpectedLocation(source.length - 1, 4, 1) |
603 ]); | 612 ]); |
604 } | 613 } |
605 | 614 |
(...skipping 26 matching lines...) Expand all Loading... |
632 } | 641 } |
633 | 642 |
634 void test_minus_eq() { | 643 void test_minus_eq() { |
635 _assertToken(TokenType.MINUS_EQ, "-="); | 644 _assertToken(TokenType.MINUS_EQ, "-="); |
636 } | 645 } |
637 | 646 |
638 void test_minus_minus() { | 647 void test_minus_minus() { |
639 _assertToken(TokenType.MINUS_MINUS, "--"); | 648 _assertToken(TokenType.MINUS_MINUS, "--"); |
640 } | 649 } |
641 | 650 |
642 void test_openSquareBracket() { | |
643 _assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); | |
644 } | |
645 | |
646 void test_open_curly_bracket() { | 651 void test_open_curly_bracket() { |
647 _assertToken(TokenType.OPEN_CURLY_BRACKET, "{"); | 652 _assertToken(TokenType.OPEN_CURLY_BRACKET, "{"); |
648 } | 653 } |
649 | 654 |
650 void test_open_paren() { | 655 void test_open_paren() { |
651 _assertToken(TokenType.OPEN_PAREN, "("); | 656 _assertToken(TokenType.OPEN_PAREN, "("); |
652 } | 657 } |
653 | 658 |
654 void test_open_square_bracket() { | 659 void test_open_square_bracket() { |
655 _assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); | 660 _assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); |
656 } | 661 } |
657 | 662 |
| 663 void test_openSquareBracket() { |
| 664 _assertToken(TokenType.OPEN_SQUARE_BRACKET, "["); |
| 665 } |
| 666 |
658 void test_percent() { | 667 void test_percent() { |
659 _assertToken(TokenType.PERCENT, "%"); | 668 _assertToken(TokenType.PERCENT, "%"); |
660 } | 669 } |
661 | 670 |
662 void test_percent_eq() { | 671 void test_percent_eq() { |
663 _assertToken(TokenType.PERCENT_EQ, "%="); | 672 _assertToken(TokenType.PERCENT_EQ, "%="); |
664 } | 673 } |
665 | 674 |
666 void test_period() { | 675 void test_period() { |
667 _assertToken(TokenType.PERIOD, "."); | 676 _assertToken(TokenType.PERIOD, "."); |
668 } | 677 } |
669 | 678 |
| 679 void test_period_period() { |
| 680 _assertToken(TokenType.PERIOD_PERIOD, ".."); |
| 681 } |
| 682 |
| 683 void test_period_period_period() { |
| 684 _assertToken(TokenType.PERIOD_PERIOD_PERIOD, "..."); |
| 685 } |
| 686 |
670 void test_periodAfterNumberNotIncluded_identifier() { | 687 void test_periodAfterNumberNotIncluded_identifier() { |
671 _assertTokens("42.isEven()", [ | 688 _assertTokens("42.isEven()", [ |
672 new StringToken(TokenType.INT, "42", 0), | 689 new StringToken(TokenType.INT, "42", 0), |
673 new Token(TokenType.PERIOD, 2), | 690 new Token(TokenType.PERIOD, 2), |
674 new StringToken(TokenType.IDENTIFIER, "isEven", 3), | 691 new StringToken(TokenType.IDENTIFIER, "isEven", 3), |
675 new Token(TokenType.OPEN_PAREN, 9), | 692 new Token(TokenType.OPEN_PAREN, 9), |
676 new Token(TokenType.CLOSE_PAREN, 10) | 693 new Token(TokenType.CLOSE_PAREN, 10) |
677 ]); | 694 ]); |
678 } | 695 } |
679 | 696 |
680 void test_periodAfterNumberNotIncluded_period() { | 697 void test_periodAfterNumberNotIncluded_period() { |
681 _assertTokens("42..isEven()", [ | 698 _assertTokens("42..isEven()", [ |
682 new StringToken(TokenType.INT, "42", 0), | 699 new StringToken(TokenType.INT, "42", 0), |
683 new Token(TokenType.PERIOD_PERIOD, 2), | 700 new Token(TokenType.PERIOD_PERIOD, 2), |
684 new StringToken(TokenType.IDENTIFIER, "isEven", 4), | 701 new StringToken(TokenType.IDENTIFIER, "isEven", 4), |
685 new Token(TokenType.OPEN_PAREN, 10), | 702 new Token(TokenType.OPEN_PAREN, 10), |
686 new Token(TokenType.CLOSE_PAREN, 11) | 703 new Token(TokenType.CLOSE_PAREN, 11) |
687 ]); | 704 ]); |
688 } | 705 } |
689 | 706 |
690 void test_period_period() { | |
691 _assertToken(TokenType.PERIOD_PERIOD, ".."); | |
692 } | |
693 | |
694 void test_period_period_period() { | |
695 _assertToken(TokenType.PERIOD_PERIOD_PERIOD, "..."); | |
696 } | |
697 | |
698 void test_plus() { | 707 void test_plus() { |
699 _assertToken(TokenType.PLUS, "+"); | 708 _assertToken(TokenType.PLUS, "+"); |
700 } | 709 } |
701 | 710 |
702 void test_plus_eq() { | 711 void test_plus_eq() { |
703 _assertToken(TokenType.PLUS_EQ, "+="); | 712 _assertToken(TokenType.PLUS_EQ, "+="); |
704 } | 713 } |
705 | 714 |
706 void test_plus_plus() { | 715 void test_plus_plus() { |
707 _assertToken(TokenType.PLUS_PLUS, "++"); | 716 _assertToken(TokenType.PLUS_PLUS, "++"); |
708 } | 717 } |
709 | 718 |
710 void test_question() { | 719 void test_question() { |
711 _assertToken(TokenType.QUESTION, "?"); | 720 _assertToken(TokenType.QUESTION, "?"); |
712 } | 721 } |
713 | 722 |
714 void test_scriptTag_withArgs() { | 723 void test_scriptTag_withArgs() { |
715 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); | 724 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); |
716 } | 725 } |
717 | 726 |
| 727 void test_scriptTag_withoutSpace() { |
| 728 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); |
| 729 } |
| 730 |
718 void test_scriptTag_withSpace() { | 731 void test_scriptTag_withSpace() { |
719 _assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart"); | 732 _assertToken(TokenType.SCRIPT_TAG, "#! /bin/dart"); |
720 } | 733 } |
721 | 734 |
722 void test_scriptTag_withoutSpace() { | |
723 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); | |
724 } | |
725 | |
726 void test_semicolon() { | 735 void test_semicolon() { |
727 _assertToken(TokenType.SEMICOLON, ";"); | 736 _assertToken(TokenType.SEMICOLON, ";"); |
728 } | 737 } |
729 | 738 |
730 void test_setSourceStart() { | 739 void test_setSourceStart() { |
731 int offsetDelta = 42; | 740 int offsetDelta = 42; |
732 GatheringErrorListener listener = new GatheringErrorListener(); | 741 GatheringErrorListener listener = new GatheringErrorListener(); |
733 Scanner scanner = | 742 Scanner scanner = |
734 new Scanner(null, new SubSequenceReader("a", offsetDelta), listener); | 743 new Scanner(null, new SubSequenceReader("a", offsetDelta), listener); |
735 scanner.setSourceStart(3, 9); | 744 scanner.setSourceStart(3, 9); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
833 void test_string_raw_multi_double() { | 842 void test_string_raw_multi_double() { |
834 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\""); | 843 _assertToken(TokenType.STRING, "r\"\"\"line1\nline2\"\"\""); |
835 } | 844 } |
836 | 845 |
837 void test_string_raw_multi_single() { | 846 void test_string_raw_multi_single() { |
838 _assertToken(TokenType.STRING, "r'''string'''"); | 847 _assertToken(TokenType.STRING, "r'''string'''"); |
839 } | 848 } |
840 | 849 |
841 void test_string_raw_multi_unterminated() { | 850 void test_string_raw_multi_unterminated() { |
842 String source = "r'''string"; | 851 String source = "r'''string"; |
843 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 852 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, |
844 9, source, [new StringToken(TokenType.STRING, source, 0)]); | 853 source, [new StringToken(TokenType.STRING, source, 0)]); |
845 } | 854 } |
846 | 855 |
847 void test_string_raw_simple_double() { | 856 void test_string_raw_simple_double() { |
848 _assertToken(TokenType.STRING, "r\"string\""); | 857 _assertToken(TokenType.STRING, "r\"string\""); |
849 } | 858 } |
850 | 859 |
851 void test_string_raw_simple_single() { | 860 void test_string_raw_simple_single() { |
852 _assertToken(TokenType.STRING, "r'string'"); | 861 _assertToken(TokenType.STRING, "r'string'"); |
853 } | 862 } |
854 | 863 |
855 void test_string_raw_simple_unterminated_eof() { | 864 void test_string_raw_simple_unterminated_eof() { |
856 String source = "r'string"; | 865 String source = "r'string"; |
857 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 866 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, |
858 7, source, [new StringToken(TokenType.STRING, source, 0)]); | 867 source, [new StringToken(TokenType.STRING, source, 0)]); |
859 } | 868 } |
860 | 869 |
861 void test_string_raw_simple_unterminated_eol() { | 870 void test_string_raw_simple_unterminated_eol() { |
862 String source = "r'string"; | 871 String source = "r'string"; |
863 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 872 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, |
864 8, "$source\n", [new StringToken(TokenType.STRING, source, 0)]); | 873 "$source\n", [new StringToken(TokenType.STRING, source, 0)]); |
865 } | 874 } |
866 | 875 |
867 void test_string_simple_double() { | 876 void test_string_simple_double() { |
868 _assertToken(TokenType.STRING, "\"string\""); | 877 _assertToken(TokenType.STRING, "\"string\""); |
869 } | 878 } |
870 | 879 |
871 void test_string_simple_escapedDollar() { | 880 void test_string_simple_escapedDollar() { |
872 _assertToken(TokenType.STRING, "'a\\\$b'"); | 881 _assertToken(TokenType.STRING, "'a\\\$b'"); |
873 } | 882 } |
874 | 883 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 new StringToken(TokenType.STRING, "1'", 2) | 959 new StringToken(TokenType.STRING, "1'", 2) |
951 ]); | 960 ]); |
952 } | 961 } |
953 | 962 |
954 void test_string_simple_single() { | 963 void test_string_simple_single() { |
955 _assertToken(TokenType.STRING, "'string'"); | 964 _assertToken(TokenType.STRING, "'string'"); |
956 } | 965 } |
957 | 966 |
958 void test_string_simple_unterminated_eof() { | 967 void test_string_simple_unterminated_eof() { |
959 String source = "'string"; | 968 String source = "'string"; |
960 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 969 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, |
961 6, source, [new StringToken(TokenType.STRING, source, 0)]); | 970 source, [new StringToken(TokenType.STRING, source, 0)]); |
962 } | 971 } |
963 | 972 |
964 void test_string_simple_unterminated_eol() { | 973 void test_string_simple_unterminated_eol() { |
965 String source = "'string"; | 974 String source = "'string"; |
966 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, | 975 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, |
967 7, "$source\r", [new StringToken(TokenType.STRING, source, 0)]); | 976 "$source\r", [new StringToken(TokenType.STRING, source, 0)]); |
968 } | 977 } |
969 | 978 |
970 void test_string_simple_unterminated_interpolation_block() { | 979 void test_string_simple_unterminated_interpolation_block() { |
971 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, | 980 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, |
972 "'\${name", [ | 981 "'\${name", [ |
973 new StringToken(TokenType.STRING, "'", 0), | 982 new StringToken(TokenType.STRING, "'", 0), |
974 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), | 983 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), |
975 new StringToken(TokenType.IDENTIFIER, "name", 3), | 984 new StringToken(TokenType.IDENTIFIER, "name", 3), |
976 new StringToken(TokenType.STRING, "", 7) | 985 new StringToken(TokenType.STRING, "", 7) |
977 ]); | 986 ]); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1037 * | 1046 * |
1038 * [expectedError] the error that should be produced | 1047 * [expectedError] the error that should be produced |
1039 * [expectedOffset] the string offset that should be associated with the error | 1048 * [expectedOffset] the string offset that should be associated with the error |
1040 * [source] the source to be scanned to produce the error | 1049 * [source] the source to be scanned to produce the error |
1041 */ | 1050 */ |
1042 void _assertError( | 1051 void _assertError( |
1043 ScannerErrorCode expectedError, int expectedOffset, String source) { | 1052 ScannerErrorCode expectedError, int expectedOffset, String source) { |
1044 GatheringErrorListener listener = new GatheringErrorListener(); | 1053 GatheringErrorListener listener = new GatheringErrorListener(); |
1045 _scanWithListener(source, listener); | 1054 _scanWithListener(source, listener); |
1046 listener.assertErrors([ | 1055 listener.assertErrors([ |
1047 new AnalysisError.con2(null, expectedOffset, 1, expectedError, [ | 1056 new AnalysisError.con2(null, expectedOffset, 1, expectedError, |
1048 source.codeUnitAt(expectedOffset) | 1057 [source.codeUnitAt(expectedOffset)]) |
1049 ]) | |
1050 ]); | 1058 ]); |
1051 } | 1059 } |
1052 | 1060 |
1053 /** | 1061 /** |
1054 * Assert that scanning the given [source] produces an error with the given | 1062 * Assert that scanning the given [source] produces an error with the given |
1055 * code, and also produces the given tokens. | 1063 * code, and also produces the given tokens. |
1056 * | 1064 * |
1057 * [expectedError] the error that should be produced | 1065 * [expectedError] the error that should be produced |
1058 * [expectedOffset] the string offset that should be associated with the error | 1066 * [expectedOffset] the string offset that should be associated with the error |
1059 * [source] the source to be scanned to produce the error | 1067 * [source] the source to be scanned to produce the error |
1060 * [expectedTokens] the tokens that are expected to be in the source | 1068 * [expectedTokens] the tokens that are expected to be in the source |
1061 */ | 1069 */ |
1062 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset, | 1070 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset, |
1063 String source, List<Token> expectedTokens) { | 1071 String source, List<Token> expectedTokens) { |
1064 GatheringErrorListener listener = new GatheringErrorListener(); | 1072 GatheringErrorListener listener = new GatheringErrorListener(); |
1065 Token token = _scanWithListener(source, listener); | 1073 Token token = _scanWithListener(source, listener); |
1066 listener.assertErrors([ | 1074 listener.assertErrors([ |
1067 new AnalysisError.con2(null, expectedOffset, 1, expectedError, [ | 1075 new AnalysisError.con2(null, expectedOffset, 1, expectedError, |
1068 source.codeUnitAt(expectedOffset) | 1076 [source.codeUnitAt(expectedOffset)]) |
1069 ]) | |
1070 ]); | 1077 ]); |
1071 _checkTokens(token, expectedTokens); | 1078 _checkTokens(token, expectedTokens); |
1072 } | 1079 } |
1073 | 1080 |
1074 /** | 1081 /** |
1075 * Assert that when scanned the given [source] contains a single keyword token | 1082 * Assert that when scanned the given [source] contains a single keyword token |
1076 * with the same lexeme as the original source. | 1083 * with the same lexeme as the original source. |
1077 */ | 1084 */ |
1078 void _assertKeywordToken(String source) { | 1085 void _assertKeywordToken(String source) { |
1079 Token token = _scan(source); | 1086 Token token = _scan(source); |
(...skipping 17 matching lines...) Expand all Loading... |
1097 expect(token.next.type, TokenType.EOF); | 1104 expect(token.next.type, TokenType.EOF); |
1098 } | 1105 } |
1099 | 1106 |
1100 void _assertLineInfo( | 1107 void _assertLineInfo( |
1101 String source, List<ScannerTest_ExpectedLocation> expectedLocations) { | 1108 String source, List<ScannerTest_ExpectedLocation> expectedLocations) { |
1102 GatheringErrorListener listener = new GatheringErrorListener(); | 1109 GatheringErrorListener listener = new GatheringErrorListener(); |
1103 _scanWithListener(source, listener); | 1110 _scanWithListener(source, listener); |
1104 listener.assertNoErrors(); | 1111 listener.assertNoErrors(); |
1105 LineInfo info = listener.getLineInfo(new TestSource()); | 1112 LineInfo info = listener.getLineInfo(new TestSource()); |
1106 expect(info, isNotNull); | 1113 expect(info, isNotNull); |
1107 for (ScannerTest_ExpectedLocation expectedLocation in expectedLocations) { | 1114 int count = expectedLocations.length; |
| 1115 for (int i = 0; i < count; i++) { |
| 1116 ScannerTest_ExpectedLocation expectedLocation = expectedLocations[i]; |
1108 LineInfo_Location location = info.getLocation(expectedLocation._offset); | 1117 LineInfo_Location location = info.getLocation(expectedLocation._offset); |
1109 expect(location.lineNumber, expectedLocation._lineNumber); | 1118 expect(location.lineNumber, expectedLocation._lineNumber, |
1110 expect(location.columnNumber, expectedLocation._columnNumber); | 1119 reason: 'Line number in location $i'); |
| 1120 expect(location.columnNumber, expectedLocation._columnNumber, |
| 1121 reason: 'Column number in location $i'); |
1111 } | 1122 } |
1112 } | 1123 } |
1113 | 1124 |
1114 /** | 1125 /** |
1115 * Assert that the token scanned from the given [source] has the | 1126 * Assert that the token scanned from the given [source] has the |
1116 * [expectedType]. | 1127 * [expectedType]. |
1117 */ | 1128 */ |
1118 Token _assertToken(TokenType expectedType, String source) { | 1129 Token _assertToken(TokenType expectedType, String source) { |
1119 Token originalToken = _scan(source); | 1130 Token originalToken = _scan(source); |
1120 expect(originalToken, isNotNull); | 1131 expect(originalToken, isNotNull); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1344 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); | 1355 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); |
1345 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); | 1356 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); |
1346 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); | 1357 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); |
1347 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); | 1358 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); |
1348 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); | 1359 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); |
1349 expect(TokenType.STAR.isUserDefinableOperator, isTrue); | 1360 expect(TokenType.STAR.isUserDefinableOperator, isTrue); |
1350 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); | 1361 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); |
1351 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); | 1362 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); |
1352 } | 1363 } |
1353 } | 1364 } |
OLD | NEW |