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

Side by Side Diff: pkg/analyzer_experimental/test/generated/scanner_test.dart

Issue 16337007: Version 0.5.13.1 . (Closed) Base URL: http://dart.googlecode.com/svn/trunk/dart/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.scanner_test; 4 library engine.scanner_test;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'package:analyzer_experimental/src/generated/java_core.dart'; 7 import 'package:analyzer_experimental/src/generated/java_core.dart';
8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; 8 import 'package:analyzer_experimental/src/generated/java_engine.dart';
9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 9 import 'package:analyzer_experimental/src/generated/java_junit.dart';
10 import 'package:analyzer_experimental/src/generated/source.dart'; 10 import 'package:analyzer_experimental/src/generated/source.dart';
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 final __test = new TokenTypeTest(); 124 final __test = new TokenTypeTest();
125 runJUnitTest(__test, __test.test_isOperator); 125 runJUnitTest(__test, __test.test_isOperator);
126 }); 126 });
127 _ut.test('test_isUserDefinableOperator', () { 127 _ut.test('test_isUserDefinableOperator', () {
128 final __test = new TokenTypeTest(); 128 final __test = new TokenTypeTest();
129 runJUnitTest(__test, __test.test_isUserDefinableOperator); 129 runJUnitTest(__test, __test.test_isUserDefinableOperator);
130 }); 130 });
131 }); 131 });
132 } 132 }
133 } 133 }
134
134 /** 135 /**
135 * The class {@code TokenFactory} defines utility methods that can be used to cr eate tokens. 136 * The class {@code TokenFactory} defines utility methods that can be used to cr eate tokens.
136 */ 137 */
137 class TokenFactory { 138 class TokenFactory {
138 static Token token(Keyword keyword) => new KeywordToken(keyword, 0); 139 static Token token(Keyword keyword) => new KeywordToken(keyword, 0);
139 static Token token2(String lexeme) => new StringToken(TokenType.STRING, lexeme , 0); 140 static Token token2(String lexeme) => new StringToken(TokenType.STRING, lexeme , 0);
140 static Token token3(TokenType type) => new Token(type, 0); 141 static Token token3(TokenType type) => new Token(type, 0);
141 static Token token4(TokenType type, String lexeme) => new StringToken(type, le xeme, 0); 142 static Token token4(TokenType type, String lexeme) => new StringToken(type, le xeme, 0);
142 /**
143 * Prevent the creation of instances of this class.
144 */
145 TokenFactory() {
146 }
147 } 143 }
148 class CharBufferScannerTest extends AbstractScannerTest { 144 class CharBufferScannerTest extends AbstractScannerTest {
149 Token scan(String source, GatheringErrorListener listener) { 145 Token scan(String source, GatheringErrorListener listener) {
150 CharBuffer buffer = CharBuffer.wrap(source); 146 CharBuffer buffer = CharBuffer.wrap(source);
151 CharBufferScanner scanner = new CharBufferScanner(null, buffer, listener); 147 CharBufferScanner scanner = new CharBufferScanner(null, buffer, listener);
152 Token result = scanner.tokenize(); 148 Token result = scanner.tokenize();
153 listener.setLineInfo(new TestSource(), scanner.lineStarts); 149 listener.setLineInfo(new TestSource(), scanner.lineStarts);
154 return result; 150 return result;
155 } 151 }
156 static dartSuite() { 152 static dartSuite() {
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 runJUnitTest(__test, __test.test_keyword_void); 544 runJUnitTest(__test, __test.test_keyword_void);
549 }); 545 });
550 _ut.test('test_keyword_while', () { 546 _ut.test('test_keyword_while', () {
551 final __test = new CharBufferScannerTest(); 547 final __test = new CharBufferScannerTest();
552 runJUnitTest(__test, __test.test_keyword_while); 548 runJUnitTest(__test, __test.test_keyword_while);
553 }); 549 });
554 _ut.test('test_keyword_with', () { 550 _ut.test('test_keyword_with', () {
555 final __test = new CharBufferScannerTest(); 551 final __test = new CharBufferScannerTest();
556 runJUnitTest(__test, __test.test_keyword_with); 552 runJUnitTest(__test, __test.test_keyword_with);
557 }); 553 });
558 _ut.test('test_lineInfo', () { 554 _ut.test('test_lineInfo_multilineComment', () {
559 final __test = new CharBufferScannerTest(); 555 final __test = new CharBufferScannerTest();
560 runJUnitTest(__test, __test.test_lineInfo); 556 runJUnitTest(__test, __test.test_lineInfo_multilineComment);
557 });
558 _ut.test('test_lineInfo_simpleClass', () {
559 final __test = new CharBufferScannerTest();
560 runJUnitTest(__test, __test.test_lineInfo_simpleClass);
561 });
562 _ut.test('test_lineInfo_slashN', () {
563 final __test = new CharBufferScannerTest();
564 runJUnitTest(__test, __test.test_lineInfo_slashN);
561 }); 565 });
562 _ut.test('test_lt', () { 566 _ut.test('test_lt', () {
563 final __test = new CharBufferScannerTest(); 567 final __test = new CharBufferScannerTest();
564 runJUnitTest(__test, __test.test_lt); 568 runJUnitTest(__test, __test.test_lt);
565 }); 569 });
566 _ut.test('test_lt_eq', () { 570 _ut.test('test_lt_eq', () {
567 final __test = new CharBufferScannerTest(); 571 final __test = new CharBufferScannerTest();
568 runJUnitTest(__test, __test.test_lt_eq); 572 runJUnitTest(__test, __test.test_lt_eq);
569 }); 573 });
570 _ut.test('test_lt_lt', () { 574 _ut.test('test_lt_lt', () {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol); 736 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol);
733 }); 737 });
734 _ut.test('test_string_simple_double', () { 738 _ut.test('test_string_simple_double', () {
735 final __test = new CharBufferScannerTest(); 739 final __test = new CharBufferScannerTest();
736 runJUnitTest(__test, __test.test_string_simple_double); 740 runJUnitTest(__test, __test.test_string_simple_double);
737 }); 741 });
738 _ut.test('test_string_simple_escapedDollar', () { 742 _ut.test('test_string_simple_escapedDollar', () {
739 final __test = new CharBufferScannerTest(); 743 final __test = new CharBufferScannerTest();
740 runJUnitTest(__test, __test.test_string_simple_escapedDollar); 744 runJUnitTest(__test, __test.test_string_simple_escapedDollar);
741 }); 745 });
746 _ut.test('test_string_simple_interpolation_adjacentIdentifiers', () {
747 final __test = new CharBufferScannerTest();
748 runJUnitTest(__test, __test.test_string_simple_interpolation_adjacentIde ntifiers);
749 });
742 _ut.test('test_string_simple_interpolation_block', () { 750 _ut.test('test_string_simple_interpolation_block', () {
743 final __test = new CharBufferScannerTest(); 751 final __test = new CharBufferScannerTest();
744 runJUnitTest(__test, __test.test_string_simple_interpolation_block); 752 runJUnitTest(__test, __test.test_string_simple_interpolation_block);
745 }); 753 });
746 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () { 754 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () {
747 final __test = new CharBufferScannerTest(); 755 final __test = new CharBufferScannerTest();
748 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe stedMap); 756 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe stedMap);
749 }); 757 });
750 _ut.test('test_string_simple_interpolation_firstAndLast', () { 758 _ut.test('test_string_simple_interpolation_firstAndLast', () {
751 final __test = new CharBufferScannerTest(); 759 final __test = new CharBufferScannerTest();
752 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas t); 760 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas t);
753 }); 761 });
754 _ut.test('test_string_simple_interpolation_identifier', () { 762 _ut.test('test_string_simple_interpolation_identifier', () {
755 final __test = new CharBufferScannerTest(); 763 final __test = new CharBufferScannerTest();
756 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier) ; 764 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier) ;
757 }); 765 });
766 _ut.test('test_string_simple_interpolation_missingIdentifier', () {
767 final __test = new CharBufferScannerTest();
768 runJUnitTest(__test, __test.test_string_simple_interpolation_missingIden tifier);
769 });
770 _ut.test('test_string_simple_interpolation_nonIdentifier', () {
771 final __test = new CharBufferScannerTest();
772 runJUnitTest(__test, __test.test_string_simple_interpolation_nonIdentifi er);
773 });
758 _ut.test('test_string_simple_single', () { 774 _ut.test('test_string_simple_single', () {
759 final __test = new CharBufferScannerTest(); 775 final __test = new CharBufferScannerTest();
760 runJUnitTest(__test, __test.test_string_simple_single); 776 runJUnitTest(__test, __test.test_string_simple_single);
761 }); 777 });
762 _ut.test('test_string_simple_unterminated_eof', () { 778 _ut.test('test_string_simple_unterminated_eof', () {
763 final __test = new CharBufferScannerTest(); 779 final __test = new CharBufferScannerTest();
764 runJUnitTest(__test, __test.test_string_simple_unterminated_eof); 780 runJUnitTest(__test, __test.test_string_simple_unterminated_eof);
765 }); 781 });
766 _ut.test('test_string_simple_unterminated_eol', () { 782 _ut.test('test_string_simple_unterminated_eol', () {
767 final __test = new CharBufferScannerTest(); 783 final __test = new CharBufferScannerTest();
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 runJUnitTest(__test, __test.test_keyword_void); 1215 runJUnitTest(__test, __test.test_keyword_void);
1200 }); 1216 });
1201 _ut.test('test_keyword_while', () { 1217 _ut.test('test_keyword_while', () {
1202 final __test = new StringScannerTest(); 1218 final __test = new StringScannerTest();
1203 runJUnitTest(__test, __test.test_keyword_while); 1219 runJUnitTest(__test, __test.test_keyword_while);
1204 }); 1220 });
1205 _ut.test('test_keyword_with', () { 1221 _ut.test('test_keyword_with', () {
1206 final __test = new StringScannerTest(); 1222 final __test = new StringScannerTest();
1207 runJUnitTest(__test, __test.test_keyword_with); 1223 runJUnitTest(__test, __test.test_keyword_with);
1208 }); 1224 });
1209 _ut.test('test_lineInfo', () { 1225 _ut.test('test_lineInfo_multilineComment', () {
1210 final __test = new StringScannerTest(); 1226 final __test = new StringScannerTest();
1211 runJUnitTest(__test, __test.test_lineInfo); 1227 runJUnitTest(__test, __test.test_lineInfo_multilineComment);
1228 });
1229 _ut.test('test_lineInfo_simpleClass', () {
1230 final __test = new StringScannerTest();
1231 runJUnitTest(__test, __test.test_lineInfo_simpleClass);
1232 });
1233 _ut.test('test_lineInfo_slashN', () {
1234 final __test = new StringScannerTest();
1235 runJUnitTest(__test, __test.test_lineInfo_slashN);
1212 }); 1236 });
1213 _ut.test('test_lt', () { 1237 _ut.test('test_lt', () {
1214 final __test = new StringScannerTest(); 1238 final __test = new StringScannerTest();
1215 runJUnitTest(__test, __test.test_lt); 1239 runJUnitTest(__test, __test.test_lt);
1216 }); 1240 });
1217 _ut.test('test_lt_eq', () { 1241 _ut.test('test_lt_eq', () {
1218 final __test = new StringScannerTest(); 1242 final __test = new StringScannerTest();
1219 runJUnitTest(__test, __test.test_lt_eq); 1243 runJUnitTest(__test, __test.test_lt_eq);
1220 }); 1244 });
1221 _ut.test('test_lt_lt', () { 1245 _ut.test('test_lt_lt', () {
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol); 1411 runJUnitTest(__test, __test.test_string_raw_simple_unterminated_eol);
1388 }); 1412 });
1389 _ut.test('test_string_simple_double', () { 1413 _ut.test('test_string_simple_double', () {
1390 final __test = new StringScannerTest(); 1414 final __test = new StringScannerTest();
1391 runJUnitTest(__test, __test.test_string_simple_double); 1415 runJUnitTest(__test, __test.test_string_simple_double);
1392 }); 1416 });
1393 _ut.test('test_string_simple_escapedDollar', () { 1417 _ut.test('test_string_simple_escapedDollar', () {
1394 final __test = new StringScannerTest(); 1418 final __test = new StringScannerTest();
1395 runJUnitTest(__test, __test.test_string_simple_escapedDollar); 1419 runJUnitTest(__test, __test.test_string_simple_escapedDollar);
1396 }); 1420 });
1421 _ut.test('test_string_simple_interpolation_adjacentIdentifiers', () {
1422 final __test = new StringScannerTest();
1423 runJUnitTest(__test, __test.test_string_simple_interpolation_adjacentIde ntifiers);
1424 });
1397 _ut.test('test_string_simple_interpolation_block', () { 1425 _ut.test('test_string_simple_interpolation_block', () {
1398 final __test = new StringScannerTest(); 1426 final __test = new StringScannerTest();
1399 runJUnitTest(__test, __test.test_string_simple_interpolation_block); 1427 runJUnitTest(__test, __test.test_string_simple_interpolation_block);
1400 }); 1428 });
1401 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () { 1429 _ut.test('test_string_simple_interpolation_blockWithNestedMap', () {
1402 final __test = new StringScannerTest(); 1430 final __test = new StringScannerTest();
1403 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe stedMap); 1431 runJUnitTest(__test, __test.test_string_simple_interpolation_blockWithNe stedMap);
1404 }); 1432 });
1405 _ut.test('test_string_simple_interpolation_firstAndLast', () { 1433 _ut.test('test_string_simple_interpolation_firstAndLast', () {
1406 final __test = new StringScannerTest(); 1434 final __test = new StringScannerTest();
1407 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas t); 1435 runJUnitTest(__test, __test.test_string_simple_interpolation_firstAndLas t);
1408 }); 1436 });
1409 _ut.test('test_string_simple_interpolation_identifier', () { 1437 _ut.test('test_string_simple_interpolation_identifier', () {
1410 final __test = new StringScannerTest(); 1438 final __test = new StringScannerTest();
1411 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier) ; 1439 runJUnitTest(__test, __test.test_string_simple_interpolation_identifier) ;
1412 }); 1440 });
1441 _ut.test('test_string_simple_interpolation_missingIdentifier', () {
1442 final __test = new StringScannerTest();
1443 runJUnitTest(__test, __test.test_string_simple_interpolation_missingIden tifier);
1444 });
1445 _ut.test('test_string_simple_interpolation_nonIdentifier', () {
1446 final __test = new StringScannerTest();
1447 runJUnitTest(__test, __test.test_string_simple_interpolation_nonIdentifi er);
1448 });
1413 _ut.test('test_string_simple_single', () { 1449 _ut.test('test_string_simple_single', () {
1414 final __test = new StringScannerTest(); 1450 final __test = new StringScannerTest();
1415 runJUnitTest(__test, __test.test_string_simple_single); 1451 runJUnitTest(__test, __test.test_string_simple_single);
1416 }); 1452 });
1417 _ut.test('test_string_simple_unterminated_eof', () { 1453 _ut.test('test_string_simple_unterminated_eof', () {
1418 final __test = new StringScannerTest(); 1454 final __test = new StringScannerTest();
1419 runJUnitTest(__test, __test.test_string_simple_unterminated_eof); 1455 runJUnitTest(__test, __test.test_string_simple_unterminated_eof);
1420 }); 1456 });
1421 _ut.test('test_string_simple_unterminated_eol', () { 1457 _ut.test('test_string_simple_unterminated_eol', () {
1422 final __test = new StringScannerTest(); 1458 final __test = new StringScannerTest();
(...skipping 11 matching lines...) Expand all
1434 final __test = new StringScannerTest(); 1470 final __test = new StringScannerTest();
1435 runJUnitTest(__test, __test.test_tilde_slash_eq); 1471 runJUnitTest(__test, __test.test_tilde_slash_eq);
1436 }); 1472 });
1437 _ut.test('test_unclosedPairInInterpolation', () { 1473 _ut.test('test_unclosedPairInInterpolation', () {
1438 final __test = new StringScannerTest(); 1474 final __test = new StringScannerTest();
1439 runJUnitTest(__test, __test.test_unclosedPairInInterpolation); 1475 runJUnitTest(__test, __test.test_unclosedPairInInterpolation);
1440 }); 1476 });
1441 }); 1477 });
1442 } 1478 }
1443 } 1479 }
1480
1444 /** 1481 /**
1445 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction 1482 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction
1446 * of a stream of tokens. 1483 * of a stream of tokens.
1447 */ 1484 */
1448 class TokenStreamValidator { 1485 class TokenStreamValidator {
1486
1449 /** 1487 /**
1450 * Validate that the stream of tokens that starts with the given token is corr ect. 1488 * Validate that the stream of tokens that starts with the given token is corr ect.
1451 * @param token the first token in the stream of tokens to be validated 1489 * @param token the first token in the stream of tokens to be validated
1452 */ 1490 */
1453 void validate(Token token) { 1491 void validate(Token token) {
1454 JavaStringBuilder builder = new JavaStringBuilder(); 1492 JavaStringBuilder builder = new JavaStringBuilder();
1455 validateStream(builder, token); 1493 validateStream(builder, token);
1456 if (builder.length > 0) { 1494 if (builder.length > 0) {
1457 JUnitTestCase.fail(builder.toString()); 1495 JUnitTestCase.fail(builder.toString());
1458 } 1496 }
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1795 } 1833 }
1796 void test_keyword_void() { 1834 void test_keyword_void() {
1797 assertKeywordToken("void"); 1835 assertKeywordToken("void");
1798 } 1836 }
1799 void test_keyword_while() { 1837 void test_keyword_while() {
1800 assertKeywordToken("while"); 1838 assertKeywordToken("while");
1801 } 1839 }
1802 void test_keyword_with() { 1840 void test_keyword_with() {
1803 assertKeywordToken("with"); 1841 assertKeywordToken("with");
1804 } 1842 }
1805 void test_lineInfo() { 1843 void test_lineInfo_multilineComment() {
1806 String source = "/*\r *\r */"; 1844 String source = "/*\r *\r */";
1807 GatheringErrorListener listener = new GatheringErrorListener(); 1845 assertLineInfo(source, [new AbstractScannerTest_ExpectedLocation(0, 1, 1), n ew AbstractScannerTest_ExpectedLocation(4, 2, 2), new AbstractScannerTest_Expect edLocation(source.length - 1, 3, 3)]);
1808 Token token = scan(source, listener); 1846 }
1809 JUnitTestCase.assertSame(TokenType.MULTI_LINE_COMMENT, token.precedingCommen ts.type); 1847 void test_lineInfo_simpleClass() {
1810 listener.assertNoErrors(); 1848 String source = "class Test {\r\n String s = '...';\r\n int get x => s .MISSING_GETTER;\r\n}";
1811 LineInfo info = listener.getLineInfo(new TestSource()); 1849 assertLineInfo(source, [new AbstractScannerTest_ExpectedLocation(0, 1, 1), n ew AbstractScannerTest_ExpectedLocation(source.indexOf("MISSING_GETTER"), 3, 20) , new AbstractScannerTest_ExpectedLocation(source.length - 1, 4, 1)]);
1812 JUnitTestCase.assertNotNull(info); 1850 }
1813 JUnitTestCase.assertEquals(3, info.getLocation(source.length - 1).lineNumber ); 1851 void test_lineInfo_slashN() {
1852 String source = "class Test {\n}";
1853 assertLineInfo(source, [new AbstractScannerTest_ExpectedLocation(0, 1, 1), n ew AbstractScannerTest_ExpectedLocation(source.indexOf("}"), 2, 1)]);
1814 } 1854 }
1815 void test_lt() { 1855 void test_lt() {
1816 assertToken(TokenType.LT, "<"); 1856 assertToken(TokenType.LT, "<");
1817 } 1857 }
1818 void test_lt_eq() { 1858 void test_lt_eq() {
1819 assertToken(TokenType.LT_EQ, "<="); 1859 assertToken(TokenType.LT_EQ, "<=");
1820 } 1860 }
1821 void test_lt_lt() { 1861 void test_lt_lt() {
1822 assertToken(TokenType.LT_LT, "<<"); 1862 assertToken(TokenType.LT_LT, "<<");
1823 } 1863 }
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
1946 } 1986 }
1947 void test_string_raw_simple_unterminated_eol() { 1987 void test_string_raw_simple_unterminated_eol() {
1948 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "r'string\n"); 1988 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "r'string\n");
1949 } 1989 }
1950 void test_string_simple_double() { 1990 void test_string_simple_double() {
1951 assertToken(TokenType.STRING, "\"string\""); 1991 assertToken(TokenType.STRING, "\"string\"");
1952 } 1992 }
1953 void test_string_simple_escapedDollar() { 1993 void test_string_simple_escapedDollar() {
1954 assertToken(TokenType.STRING, "'a\\\$b'"); 1994 assertToken(TokenType.STRING, "'a\\\$b'");
1955 } 1995 }
1996 void test_string_simple_interpolation_adjacentIdentifiers() {
1997 assertTokens("'\$a\$b'", [new StringToken(TokenType.STRING, "'", 0), new Str ingToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new StringToken(To kenType.IDENTIFIER, "a", 2), new StringToken(TokenType.STRING, "", 3), new Strin gToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 3), new StringToken(Toke nType.IDENTIFIER, "b", 4), new StringToken(TokenType.STRING, "'", 5)]);
1998 }
1956 void test_string_simple_interpolation_block() { 1999 void test_string_simple_interpolation_block() {
1957 assertTokens("'Hello \${name}!'", [new StringToken(TokenType.STRING, "'Hello ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7), ne w StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CURLY_ BRACKET, 13), new StringToken(TokenType.STRING, "!'", 14)]); 2000 assertTokens("'Hello \${name}!'", [new StringToken(TokenType.STRING, "'Hello ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7), ne w StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CURLY_ BRACKET, 13), new StringToken(TokenType.STRING, "!'", 14)]);
1958 } 2001 }
1959 void test_string_simple_interpolation_blockWithNestedMap() { 2002 void test_string_simple_interpolation_blockWithNestedMap() {
1960 assertTokens("'a \${f({'b' : 'c'})} d'", [new StringToken(TokenType.STRING, "'a ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3), new StringToken(TokenType.IDENTIFIER, "f", 5), new Token(TokenType.OPEN_PAREN, 6), new Token(TokenType.OPEN_CURLY_BRACKET, 7), new StringToken(TokenType.STRING , "'b'", 8), new Token(TokenType.COLON, 12), new StringToken(TokenType.STRING, " 'c'", 14), new Token(TokenType.CLOSE_CURLY_BRACKET, 17), new Token(TokenType.CLO SE_PAREN, 18), new Token(TokenType.CLOSE_CURLY_BRACKET, 19), new StringToken(Tok enType.STRING, " d'", 20)]); 2003 assertTokens("'a \${f({'b' : 'c'})} d'", [new StringToken(TokenType.STRING, "'a ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 3), new StringToken(TokenType.IDENTIFIER, "f", 5), new Token(TokenType.OPEN_PAREN, 6), new Token(TokenType.OPEN_CURLY_BRACKET, 7), new StringToken(TokenType.STRING , "'b'", 8), new Token(TokenType.COLON, 12), new StringToken(TokenType.STRING, " 'c'", 14), new Token(TokenType.CLOSE_CURLY_BRACKET, 17), new Token(TokenType.CLO SE_PAREN, 18), new Token(TokenType.CLOSE_CURLY_BRACKET, 19), new StringToken(Tok enType.STRING, " d'", 20)]);
1961 } 2004 }
1962 void test_string_simple_interpolation_firstAndLast() { 2005 void test_string_simple_interpolation_firstAndLast() {
1963 assertTokens("'\$greeting \$name'", [new StringToken(TokenType.STRING, "'", 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new Str ingToken(TokenType.IDENTIFIER, "greeting", 2), new StringToken(TokenType.STRING, " ", 10), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 11), new StringToken(TokenType.IDENTIFIER, "name", 12), new StringToken(TokenType.ST RING, "'", 16)]); 2006 assertTokens("'\$greeting \$name'", [new StringToken(TokenType.STRING, "'", 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new Str ingToken(TokenType.IDENTIFIER, "greeting", 2), new StringToken(TokenType.STRING, " ", 10), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 11), new StringToken(TokenType.IDENTIFIER, "name", 12), new StringToken(TokenType.ST RING, "'", 16)]);
1964 } 2007 }
1965 void test_string_simple_interpolation_identifier() { 2008 void test_string_simple_interpolation_identifier() {
1966 assertTokens("'Hello \$name!'", [new StringToken(TokenType.STRING, "'Hello " , 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), new S tringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING, " !'", 12)]); 2009 assertTokens("'Hello \$name!'", [new StringToken(TokenType.STRING, "'Hello " , 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), new S tringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING, " !'", 12)]);
1967 } 2010 }
2011 void test_string_simple_interpolation_missingIdentifier() {
2012 assertTokens("'\$x\$'", [new StringToken(TokenType.STRING, "'", 0), new Stri ngToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new StringToken(Tok enType.IDENTIFIER, "x", 2), new StringToken(TokenType.STRING, "", 3), new String Token(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 3), new StringToken(Token Type.STRING, "'", 4)]);
2013 }
2014 void test_string_simple_interpolation_nonIdentifier() {
2015 assertTokens("'\$1'", [new StringToken(TokenType.STRING, "'", 0), new String Token(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), new StringToken(Token Type.STRING, "1'", 2)]);
2016 }
1968 void test_string_simple_single() { 2017 void test_string_simple_single() {
1969 assertToken(TokenType.STRING, "'string'"); 2018 assertToken(TokenType.STRING, "'string'");
1970 } 2019 }
1971 void test_string_simple_unterminated_eof() { 2020 void test_string_simple_unterminated_eof() {
1972 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'string"); 2021 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'string");
1973 } 2022 }
1974 void test_string_simple_unterminated_eol() { 2023 void test_string_simple_unterminated_eol() {
1975 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "'string\r"); 2024 assertError(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "'string\r");
1976 } 2025 }
1977 void test_tilde() { 2026 void test_tilde() {
(...skipping 14 matching lines...) Expand all
1992 Token token = scan2(source); 2041 Token token = scan2(source);
1993 JUnitTestCase.assertNotNull(token); 2042 JUnitTestCase.assertNotNull(token);
1994 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 2043 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
1995 Token comment = token.precedingComments; 2044 Token comment = token.precedingComments;
1996 JUnitTestCase.assertNotNull(comment); 2045 JUnitTestCase.assertNotNull(comment);
1997 JUnitTestCase.assertEquals(commentType, comment.type); 2046 JUnitTestCase.assertEquals(commentType, comment.type);
1998 JUnitTestCase.assertEquals(0, comment.offset); 2047 JUnitTestCase.assertEquals(0, comment.offset);
1999 JUnitTestCase.assertEquals(source.length, comment.length); 2048 JUnitTestCase.assertEquals(source.length, comment.length);
2000 JUnitTestCase.assertEquals(source, comment.lexeme); 2049 JUnitTestCase.assertEquals(source, comment.lexeme);
2001 } 2050 }
2051
2002 /** 2052 /**
2003 * Assert that scanning the given source produces an error with the given code . 2053 * Assert that scanning the given source produces an error with the given code .
2004 * @param illegalCharacter 2054 * @param illegalCharacter
2005 * @param i 2055 * @param i
2006 * @param source the source to be scanned to produce the error 2056 * @param source the source to be scanned to produce the error
2007 */ 2057 */
2008 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so urce) { 2058 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so urce) {
2009 GatheringErrorListener listener = new GatheringErrorListener(); 2059 GatheringErrorListener listener = new GatheringErrorListener();
2010 scan(source, listener); 2060 scan(source, listener);
2011 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec tedError, [(source.codeUnitAt(expectedOffset) as int)])]); 2061 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec tedError, [(source.codeUnitAt(expectedOffset) as int)])]);
2012 } 2062 }
2063
2013 /** 2064 /**
2014 * Assert that when scanned the given source contains a single keyword token w ith the same lexeme 2065 * Assert that when scanned the given source contains a single keyword token w ith the same lexeme
2015 * as the original source. 2066 * as the original source.
2016 * @param source the source to be scanned 2067 * @param source the source to be scanned
2017 */ 2068 */
2018 void assertKeywordToken(String source) { 2069 void assertKeywordToken(String source) {
2019 Token token = scan2(source); 2070 Token token = scan2(source);
2020 JUnitTestCase.assertNotNull(token); 2071 JUnitTestCase.assertNotNull(token);
2021 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); 2072 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type);
2022 JUnitTestCase.assertEquals(0, token.offset); 2073 JUnitTestCase.assertEquals(0, token.offset);
2023 JUnitTestCase.assertEquals(source.length, token.length); 2074 JUnitTestCase.assertEquals(source.length, token.length);
2024 JUnitTestCase.assertEquals(source, token.lexeme); 2075 JUnitTestCase.assertEquals(source, token.lexeme);
2025 Object value2 = token.value(); 2076 Object value2 = token.value();
2026 JUnitTestCase.assertTrue(value2 is Keyword); 2077 JUnitTestCase.assertTrue(value2 is Keyword);
2027 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax); 2078 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax);
2028 token = scan2(" ${source} "); 2079 token = scan2(" ${source} ");
2029 JUnitTestCase.assertNotNull(token); 2080 JUnitTestCase.assertNotNull(token);
2030 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); 2081 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type);
2031 JUnitTestCase.assertEquals(1, token.offset); 2082 JUnitTestCase.assertEquals(1, token.offset);
2032 JUnitTestCase.assertEquals(source.length, token.length); 2083 JUnitTestCase.assertEquals(source.length, token.length);
2033 JUnitTestCase.assertEquals(source, token.lexeme); 2084 JUnitTestCase.assertEquals(source, token.lexeme);
2034 value2 = token.value(); 2085 value2 = token.value();
2035 JUnitTestCase.assertTrue(value2 is Keyword); 2086 JUnitTestCase.assertTrue(value2 is Keyword);
2036 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax); 2087 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax);
2037 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); 2088 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type);
2038 } 2089 }
2090 void assertLineInfo(String source, List<AbstractScannerTest_ExpectedLocation> expectedLocations) {
2091 GatheringErrorListener listener = new GatheringErrorListener();
2092 scan(source, listener);
2093 listener.assertNoErrors();
2094 LineInfo info = listener.getLineInfo(new TestSource());
2095 JUnitTestCase.assertNotNull(info);
2096 for (AbstractScannerTest_ExpectedLocation expectedLocation in expectedLocati ons) {
2097 LineInfo_Location location = info.getLocation(expectedLocation._offset);
2098 JUnitTestCase.assertEquals(expectedLocation._lineNumber, location.lineNumb er);
2099 JUnitTestCase.assertEquals(expectedLocation._columnNumber, location.column Number);
2100 }
2101 }
2102
2039 /** 2103 /**
2040 * Assert that the token scanned from the given source has the expected type. 2104 * Assert that the token scanned from the given source has the expected type.
2041 * @param expectedType the expected type of the token 2105 * @param expectedType the expected type of the token
2042 * @param source the source to be scanned to produce the actual token 2106 * @param source the source to be scanned to produce the actual token
2043 */ 2107 */
2044 Token assertToken(TokenType expectedType, String source) { 2108 Token assertToken(TokenType expectedType, String source) {
2045 Token originalToken = scan2(source); 2109 Token originalToken = scan2(source);
2046 JUnitTestCase.assertNotNull(originalToken); 2110 JUnitTestCase.assertNotNull(originalToken);
2047 JUnitTestCase.assertEquals(expectedType, originalToken.type); 2111 JUnitTestCase.assertEquals(expectedType, originalToken.type);
2048 JUnitTestCase.assertEquals(0, originalToken.offset); 2112 JUnitTestCase.assertEquals(0, originalToken.offset);
(...skipping 12 matching lines...) Expand all
2061 } 2125 }
2062 Token tokenWithSpaces = scan2(" ${source} "); 2126 Token tokenWithSpaces = scan2(" ${source} ");
2063 JUnitTestCase.assertNotNull(tokenWithSpaces); 2127 JUnitTestCase.assertNotNull(tokenWithSpaces);
2064 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); 2128 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type);
2065 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); 2129 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset);
2066 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); 2130 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length);
2067 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); 2131 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme);
2068 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type); 2132 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type);
2069 return originalToken; 2133 return originalToken;
2070 } 2134 }
2135
2071 /** 2136 /**
2072 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given 2137 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given
2073 * tokens. 2138 * tokens.
2074 * @param source the source to be scanned 2139 * @param source the source to be scanned
2075 * @param expectedTokens the tokens that are expected to be in the source 2140 * @param expectedTokens the tokens that are expected to be in the source
2076 */ 2141 */
2077 void assertTokens(String source, List<Token> expectedTokens) { 2142 void assertTokens(String source, List<Token> expectedTokens) {
2078 Token token = scan2(source); 2143 Token token = scan2(source);
2079 JUnitTestCase.assertNotNull(token); 2144 JUnitTestCase.assertNotNull(token);
2080 for (int i = 0; i < expectedTokens.length; i++) { 2145 for (int i = 0; i < expectedTokens.length; i++) {
2081 Token expectedToken = expectedTokens[i]; 2146 Token expectedToken = expectedTokens[i];
2082 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t ype, token.type); 2147 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t ype, token.type);
2083 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken .offset, token.offset); 2148 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken .offset, token.offset);
2084 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken .length, token.length); 2149 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken .length, token.length);
2085 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken .lexeme, token.lexeme); 2150 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken .lexeme, token.lexeme);
2086 token = token.next; 2151 token = token.next;
2087 JUnitTestCase.assertNotNull(token); 2152 JUnitTestCase.assertNotNull(token);
2088 } 2153 }
2089 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 2154 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
2090 } 2155 }
2091 Token scan2(String source) { 2156 Token scan2(String source) {
2092 GatheringErrorListener listener = new GatheringErrorListener(); 2157 GatheringErrorListener listener = new GatheringErrorListener();
2093 Token token = scan(source, listener); 2158 Token token = scan(source, listener);
2094 listener.assertNoErrors(); 2159 listener.assertNoErrors();
2095 return token; 2160 return token;
2096 } 2161 }
2097 } 2162 }
2163
2164 /**
2165 * Instances of the class {@code ExpectedLocation} encode information about the expected location
2166 * of a given offset in source code.
2167 */
2168 class AbstractScannerTest_ExpectedLocation {
2169 int _offset = 0;
2170 int _lineNumber = 0;
2171 int _columnNumber = 0;
2172 AbstractScannerTest_ExpectedLocation(int offset, int lineNumber, int columnNum ber) {
2173 this._offset = offset;
2174 this._lineNumber = lineNumber;
2175 this._columnNumber = columnNumber;
2176 }
2177 }
2098 main() { 2178 main() {
2099 CharBufferScannerTest.dartSuite(); 2179 CharBufferScannerTest.dartSuite();
2100 KeywordStateTest.dartSuite(); 2180 KeywordStateTest.dartSuite();
2101 StringScannerTest.dartSuite(); 2181 StringScannerTest.dartSuite();
2102 TokenTypeTest.dartSuite(); 2182 TokenTypeTest.dartSuite();
2103 } 2183 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698