| 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 // This code was auto-generated, is not intended to be edited, and is subject to | 5 // This code was auto-generated, is not intended to be edited, and is subject to |
| 6 // significant change. Please see the README file for more information. | 6 // significant change. Please see the README file for more information. |
| 7 | 7 |
| 8 library engine.scanner_test; | 8 library engine.scanner_test; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_core.dart'; | 10 import 'package:analyzer/src/generated/java_core.dart'; |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 295 builder.append(token.lexeme); | 295 builder.append(token.lexeme); |
| 296 builder.append("', "); | 296 builder.append("', "); |
| 297 builder.append(token.offset); | 297 builder.append(token.offset); |
| 298 builder.append(", "); | 298 builder.append(", "); |
| 299 builder.append(token.length); | 299 builder.append(token.length); |
| 300 builder.append("]"); | 300 builder.append("]"); |
| 301 } | 301 } |
| 302 } | 302 } |
| 303 | 303 |
| 304 class ScannerTest extends JUnitTestCase { | 304 class ScannerTest extends JUnitTestCase { |
| 305 void fail_incomplete_string_interpolation() { |
| 306 // https://code.google.com/p/dart/issues/detail?id=18073 |
| 307 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, "\"fo
o \${bar", [ |
| 308 new StringToken(TokenType.STRING, "\"foo ", 0), |
| 309 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5), |
| 310 new StringToken(TokenType.IDENTIFIER, "bar", 7)]); |
| 311 } |
| 312 |
| 305 void test_ampersand() { | 313 void test_ampersand() { |
| 306 _assertToken(TokenType.AMPERSAND, "&"); | 314 _assertToken(TokenType.AMPERSAND, "&"); |
| 307 } | 315 } |
| 308 | 316 |
| 309 void test_ampersand_ampersand() { | 317 void test_ampersand_ampersand() { |
| 310 _assertToken(TokenType.AMPERSAND_AMPERSAND, "&&"); | 318 _assertToken(TokenType.AMPERSAND_AMPERSAND, "&&"); |
| 311 } | 319 } |
| 312 | 320 |
| 313 void test_ampersand_eq() { | 321 void test_ampersand_eq() { |
| 314 _assertToken(TokenType.AMPERSAND_EQ, "&="); | 322 _assertToken(TokenType.AMPERSAND_EQ, "&="); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 | 472 |
| 465 void test_hexidecimal_missingDigit() { | 473 void test_hexidecimal_missingDigit() { |
| 466 _assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 1, "0x"); | 474 _assertError(ScannerErrorCode.MISSING_HEX_DIGIT, 1, "0x"); |
| 467 } | 475 } |
| 468 | 476 |
| 469 void test_identifier() { | 477 void test_identifier() { |
| 470 _assertToken(TokenType.IDENTIFIER, "result"); | 478 _assertToken(TokenType.IDENTIFIER, "result"); |
| 471 } | 479 } |
| 472 | 480 |
| 473 void test_illegalChar_cyrillicLetter_middle() { | 481 void test_illegalChar_cyrillicLetter_middle() { |
| 474 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "Shche\u0433lov"); | 482 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 5, "Shche\u0433lov"); |
| 475 } | 483 } |
| 476 | 484 |
| 477 void test_illegalChar_cyrillicLetter_start() { | 485 void test_illegalChar_cyrillicLetter_start() { |
| 478 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "\u0429"); | 486 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "\u0429"); |
| 479 } | 487 } |
| 480 | 488 |
| 481 void test_illegalChar_nbsp() { | 489 void test_illegalChar_nbsp() { |
| 482 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "\u00A0"); | 490 _assertError(ScannerErrorCode.ILLEGAL_CHARACTER, 0, "\u00A0"); |
| 483 } | 491 } |
| 484 | 492 |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 535 } | 543 } |
| 536 | 544 |
| 537 void test_keyword_continue() { | 545 void test_keyword_continue() { |
| 538 _assertKeywordToken("continue"); | 546 _assertKeywordToken("continue"); |
| 539 } | 547 } |
| 540 | 548 |
| 541 void test_keyword_default() { | 549 void test_keyword_default() { |
| 542 _assertKeywordToken("default"); | 550 _assertKeywordToken("default"); |
| 543 } | 551 } |
| 544 | 552 |
| 553 void test_keyword_deferred() { |
| 554 _assertKeywordToken("deferred"); |
| 555 } |
| 556 |
| 545 void test_keyword_do() { | 557 void test_keyword_do() { |
| 546 _assertKeywordToken("do"); | 558 _assertKeywordToken("do"); |
| 547 } | 559 } |
| 548 | 560 |
| 549 void test_keyword_dynamic() { | 561 void test_keyword_dynamic() { |
| 550 _assertKeywordToken("dynamic"); | 562 _assertKeywordToken("dynamic"); |
| 551 } | 563 } |
| 552 | 564 |
| 553 void test_keyword_else() { | 565 void test_keyword_else() { |
| 554 _assertKeywordToken("else"); | 566 _assertKeywordToken("else"); |
| (...skipping 530 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 * @param i | 1097 * @param i |
| 1086 * @param source the source to be scanned to produce the error | 1098 * @param source the source to be scanned to produce the error |
| 1087 */ | 1099 */ |
| 1088 void _assertError(ScannerErrorCode expectedError, int expectedOffset, String s
ource) { | 1100 void _assertError(ScannerErrorCode expectedError, int expectedOffset, String s
ource) { |
| 1089 GatheringErrorListener listener = new GatheringErrorListener(); | 1101 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1090 _scanWithListener(source, listener); | 1102 _scanWithListener(source, listener); |
| 1091 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [source.codeUnitAt(expectedOffset)])]); | 1103 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [source.codeUnitAt(expectedOffset)])]); |
| 1092 } | 1104 } |
| 1093 | 1105 |
| 1094 /** | 1106 /** |
| 1107 * Assert that scanning the given source produces an error with the given code
, and also produces |
| 1108 * the given tokens. |
| 1109 * |
| 1110 * @param expectedError the error that should be produced |
| 1111 * @param expectedOffset the string offset that should be associated with the
error |
| 1112 * @param source the source to be scanned to produce the error |
| 1113 * @param expectedTokens the tokens that are expected to be in the source |
| 1114 */ |
| 1115 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset,
String source, List<Token> expectedTokens) { |
| 1116 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1117 Token token = _scanWithListener(source, listener); |
| 1118 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [source.codeUnitAt(expectedOffset)])]); |
| 1119 _checkTokens(token, expectedTokens); |
| 1120 } |
| 1121 |
| 1122 /** |
| 1095 * Assert that when scanned the given source contains a single keyword token w
ith the same lexeme | 1123 * Assert that when scanned the given source contains a single keyword token w
ith the same lexeme |
| 1096 * as the original source. | 1124 * as the original source. |
| 1097 * | 1125 * |
| 1098 * @param source the source to be scanned | 1126 * @param source the source to be scanned |
| 1099 */ | 1127 */ |
| 1100 void _assertKeywordToken(String source) { | 1128 void _assertKeywordToken(String source) { |
| 1101 Token token = _scan(source); | 1129 Token token = _scan(source); |
| 1102 JUnitTestCase.assertNotNull(token); | 1130 JUnitTestCase.assertNotNull(token); |
| 1103 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | 1131 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); |
| 1104 JUnitTestCase.assertEquals(0, token.offset); | 1132 JUnitTestCase.assertEquals(0, token.offset); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 | 1211 |
| 1184 /** | 1212 /** |
| 1185 * Assert that when scanned the given source contains a sequence of tokens ide
ntical to the given | 1213 * Assert that when scanned the given source contains a sequence of tokens ide
ntical to the given |
| 1186 * tokens. | 1214 * tokens. |
| 1187 * | 1215 * |
| 1188 * @param source the source to be scanned | 1216 * @param source the source to be scanned |
| 1189 * @param expectedTokens the tokens that are expected to be in the source | 1217 * @param expectedTokens the tokens that are expected to be in the source |
| 1190 */ | 1218 */ |
| 1191 void _assertTokens(String source, List<Token> expectedTokens) { | 1219 void _assertTokens(String source, List<Token> expectedTokens) { |
| 1192 Token token = _scan(source); | 1220 Token token = _scan(source); |
| 1193 JUnitTestCase.assertNotNull(token); | 1221 _checkTokens(token, expectedTokens); |
| 1222 } |
| 1223 |
| 1224 void _checkTokens(Token firstToken, List<Token> expectedTokens) { |
| 1225 JUnitTestCase.assertNotNull(firstToken); |
| 1226 Token token = firstToken; |
| 1194 for (int i = 0; i < expectedTokens.length; i++) { | 1227 for (int i = 0; i < expectedTokens.length; i++) { |
| 1195 Token expectedToken = expectedTokens[i]; | 1228 Token expectedToken = expectedTokens[i]; |
| 1196 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t
ype, token.type); | 1229 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t
ype, token.type); |
| 1197 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken
.offset, token.offset); | 1230 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken
.offset, token.offset); |
| 1198 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken
.length, token.length); | 1231 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken
.length, token.length); |
| 1199 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken
.lexeme, token.lexeme); | 1232 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken
.lexeme, token.lexeme); |
| 1200 token = token.next; | 1233 token = token.next; |
| 1201 JUnitTestCase.assertNotNull(token); | 1234 JUnitTestCase.assertNotNull(token); |
| 1202 } | 1235 } |
| 1203 JUnitTestCase.assertEquals(TokenType.EOF, token.type); | 1236 JUnitTestCase.assertEquals(TokenType.EOF, token.type); |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1448 runJUnitTest(__test, __test.test_keyword_const); | 1481 runJUnitTest(__test, __test.test_keyword_const); |
| 1449 }); | 1482 }); |
| 1450 _ut.test('test_keyword_continue', () { | 1483 _ut.test('test_keyword_continue', () { |
| 1451 final __test = new ScannerTest(); | 1484 final __test = new ScannerTest(); |
| 1452 runJUnitTest(__test, __test.test_keyword_continue); | 1485 runJUnitTest(__test, __test.test_keyword_continue); |
| 1453 }); | 1486 }); |
| 1454 _ut.test('test_keyword_default', () { | 1487 _ut.test('test_keyword_default', () { |
| 1455 final __test = new ScannerTest(); | 1488 final __test = new ScannerTest(); |
| 1456 runJUnitTest(__test, __test.test_keyword_default); | 1489 runJUnitTest(__test, __test.test_keyword_default); |
| 1457 }); | 1490 }); |
| 1491 _ut.test('test_keyword_deferred', () { |
| 1492 final __test = new ScannerTest(); |
| 1493 runJUnitTest(__test, __test.test_keyword_deferred); |
| 1494 }); |
| 1458 _ut.test('test_keyword_do', () { | 1495 _ut.test('test_keyword_do', () { |
| 1459 final __test = new ScannerTest(); | 1496 final __test = new ScannerTest(); |
| 1460 runJUnitTest(__test, __test.test_keyword_do); | 1497 runJUnitTest(__test, __test.test_keyword_do); |
| 1461 }); | 1498 }); |
| 1462 _ut.test('test_keyword_dynamic', () { | 1499 _ut.test('test_keyword_dynamic', () { |
| 1463 final __test = new ScannerTest(); | 1500 final __test = new ScannerTest(); |
| 1464 runJUnitTest(__test, __test.test_keyword_dynamic); | 1501 runJUnitTest(__test, __test.test_keyword_dynamic); |
| 1465 }); | 1502 }); |
| 1466 _ut.test('test_keyword_else', () { | 1503 _ut.test('test_keyword_else', () { |
| 1467 final __test = new ScannerTest(); | 1504 final __test = new ScannerTest(); |
| (...skipping 942 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2410 } | 2447 } |
| 2411 } | 2448 } |
| 2412 | 2449 |
| 2413 main() { | 2450 main() { |
| 2414 CharSequenceReaderTest.dartSuite(); | 2451 CharSequenceReaderTest.dartSuite(); |
| 2415 IncrementalScannerTest.dartSuite(); | 2452 IncrementalScannerTest.dartSuite(); |
| 2416 KeywordStateTest.dartSuite(); | 2453 KeywordStateTest.dartSuite(); |
| 2417 ScannerTest.dartSuite(); | 2454 ScannerTest.dartSuite(); |
| 2418 TokenTypeTest.dartSuite(); | 2455 TokenTypeTest.dartSuite(); |
| 2419 } | 2456 } |
| OLD | NEW |