| OLD | NEW |
| 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'; |
| 11 import 'package:analyzer_experimental/src/generated/error.dart'; | 11 import 'package:analyzer_experimental/src/generated/error.dart'; |
| 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; | 12 import 'package:analyzer_experimental/src/generated/scanner.dart'; |
| 13 import 'package:unittest/unittest.dart' as _ut; | 13 import 'package:unittest/unittest.dart' as _ut; |
| 14 import 'test_support.dart'; | 14 import 'test_support.dart'; |
| 15 | 15 |
| 16 class KeywordStateTest extends JUnitTestCase { | 16 class KeywordStateTest extends JUnitTestCase { |
| 17 void test_KeywordState() { | 17 void test_KeywordState() { |
| 18 List<Keyword> keywords = Keyword.values; | 18 List<Keyword> keywords = Keyword.values; |
| 19 int keywordCount = keywords.length; | 19 int keywordCount = keywords.length; |
| 20 List<String> textToTest = new List<String>(keywordCount * 3); | 20 List<String> textToTest = new List<String>(keywordCount * 3); |
| 21 for (int i = 0; i < keywordCount; i++) { | 21 for (int i = 0; i < keywordCount; i++) { |
| 22 String syntax3 = keywords[i].syntax; | 22 String syntax2 = keywords[i].syntax; |
| 23 textToTest[i] = syntax3; | 23 textToTest[i] = syntax2; |
| 24 textToTest[i + keywordCount] = "${syntax3}x"; | 24 textToTest[i + keywordCount] = "${syntax2}x"; |
| 25 textToTest[i + keywordCount * 2] = syntax3.substring(0, syntax3.length - 1
); | 25 textToTest[i + keywordCount * 2] = syntax2.substring(0, syntax2.length - 1
); |
| 26 } | 26 } |
| 27 KeywordState firstState = KeywordState.KEYWORD_STATE; | 27 KeywordState firstState = KeywordState.KEYWORD_STATE; |
| 28 for (int i = 0; i < textToTest.length; i++) { | 28 for (int i = 0; i < textToTest.length; i++) { |
| 29 String text = textToTest[i]; | 29 String text = textToTest[i]; |
| 30 int index = 0; | 30 int index = 0; |
| 31 int length10 = text.length; | 31 int length2 = text.length; |
| 32 KeywordState state = firstState; | 32 KeywordState state = firstState; |
| 33 while (index < length10 && state != null) { | 33 while (index < length2 && state != null) { |
| 34 state = state.next(text.codeUnitAt(index)); | 34 state = state.next(text.codeUnitAt(index)); |
| 35 index++; | 35 index++; |
| 36 } | 36 } |
| 37 if (i < keywordCount) { | 37 if (i < keywordCount) { |
| 38 JUnitTestCase.assertNotNull(state); | 38 JUnitTestCase.assertNotNull(state); |
| 39 JUnitTestCase.assertNotNull(state.keyword()); | 39 JUnitTestCase.assertNotNull(state.keyword()); |
| 40 JUnitTestCase.assertEquals(keywords[i], state.keyword()); | 40 JUnitTestCase.assertEquals(keywords[i], state.keyword()); |
| 41 } else if (i < keywordCount * 2) { | 41 } else if (i < keywordCount * 2) { |
| 42 JUnitTestCase.assertNull(state); | 42 JUnitTestCase.assertNull(state); |
| 43 } else { | 43 } else { |
| (...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 786 }); | 786 }); |
| 787 } | 787 } |
| 788 } | 788 } |
| 789 class StringScannerTest extends AbstractScannerTest { | 789 class StringScannerTest extends AbstractScannerTest { |
| 790 void test_setSourceStart() { | 790 void test_setSourceStart() { |
| 791 int offsetDelta = 42; | 791 int offsetDelta = 42; |
| 792 GatheringErrorListener listener = new GatheringErrorListener(); | 792 GatheringErrorListener listener = new GatheringErrorListener(); |
| 793 StringScanner scanner = new StringScanner(null, "a", listener); | 793 StringScanner scanner = new StringScanner(null, "a", listener); |
| 794 scanner.setSourceStart(3, 9, offsetDelta); | 794 scanner.setSourceStart(3, 9, offsetDelta); |
| 795 scanner.tokenize(); | 795 scanner.tokenize(); |
| 796 List<int> lineStarts3 = scanner.lineStarts; | 796 List<int> lineStarts2 = scanner.lineStarts; |
| 797 JUnitTestCase.assertNotNull(lineStarts3); | 797 JUnitTestCase.assertNotNull(lineStarts2); |
| 798 JUnitTestCase.assertEquals(3, lineStarts3.length); | 798 JUnitTestCase.assertEquals(3, lineStarts2.length); |
| 799 JUnitTestCase.assertEquals(33, lineStarts3[2]); | 799 JUnitTestCase.assertEquals(33, lineStarts2[2]); |
| 800 } | 800 } |
| 801 Token scan(String source, GatheringErrorListener listener) { | 801 Token scan(String source, GatheringErrorListener listener) { |
| 802 StringScanner scanner = new StringScanner(null, source, listener); | 802 StringScanner scanner = new StringScanner(null, source, listener); |
| 803 Token result = scanner.tokenize(); | 803 Token result = scanner.tokenize(); |
| 804 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 804 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 805 return result; | 805 return result; |
| 806 } | 806 } |
| 807 static dartSuite() { | 807 static dartSuite() { |
| 808 _ut.group('StringScannerTest', () { | 808 _ut.group('StringScannerTest', () { |
| 809 _ut.test('test_ampersand', () { | 809 _ut.test('test_ampersand', () { |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1459 } | 1459 } |
| 1460 void validateStream(JavaStringBuilder builder, Token token) { | 1460 void validateStream(JavaStringBuilder builder, Token token) { |
| 1461 if (token == null) { | 1461 if (token == null) { |
| 1462 return; | 1462 return; |
| 1463 } | 1463 } |
| 1464 Token previousToken = null; | 1464 Token previousToken = null; |
| 1465 int previousEnd = -1; | 1465 int previousEnd = -1; |
| 1466 Token currentToken = token; | 1466 Token currentToken = token; |
| 1467 while (currentToken != null && currentToken.type != TokenType.EOF) { | 1467 while (currentToken != null && currentToken.type != TokenType.EOF) { |
| 1468 validateStream(builder, currentToken.precedingComments); | 1468 validateStream(builder, currentToken.precedingComments); |
| 1469 TokenType type38 = currentToken.type; | 1469 TokenType type2 = currentToken.type; |
| 1470 if (identical(type38, TokenType.OPEN_CURLY_BRACKET) || identical(type38, T
okenType.OPEN_PAREN) || identical(type38, TokenType.OPEN_SQUARE_BRACKET) || iden
tical(type38, TokenType.STRING_INTERPOLATION_EXPRESSION)) { | 1470 if (identical(type2, TokenType.OPEN_CURLY_BRACKET) || identical(type2, Tok
enType.OPEN_PAREN) || identical(type2, TokenType.OPEN_SQUARE_BRACKET) || identic
al(type2, TokenType.STRING_INTERPOLATION_EXPRESSION)) { |
| 1471 if (currentToken is! BeginToken) { | 1471 if (currentToken is! BeginToken) { |
| 1472 builder.append("\r\nExpected BeginToken, found "); | 1472 builder.append("\r\nExpected BeginToken, found "); |
| 1473 builder.append(currentToken.runtimeType.toString()); | 1473 builder.append(currentToken.runtimeType.toString()); |
| 1474 builder.append(" "); | 1474 builder.append(" "); |
| 1475 writeToken(builder, currentToken); | 1475 writeToken(builder, currentToken); |
| 1476 } | 1476 } |
| 1477 } | 1477 } |
| 1478 int currentStart = currentToken.offset; | 1478 int currentStart = currentToken.offset; |
| 1479 int currentLength = currentToken.length; | 1479 int currentLength = currentToken.length; |
| 1480 int currentEnd = currentStart + currentLength - 1; | 1480 int currentEnd = currentStart + currentLength - 1; |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1897 assertToken(TokenType.SLASH_EQ, "/="); | 1897 assertToken(TokenType.SLASH_EQ, "/="); |
| 1898 } | 1898 } |
| 1899 void test_star() { | 1899 void test_star() { |
| 1900 assertToken(TokenType.STAR, "*"); | 1900 assertToken(TokenType.STAR, "*"); |
| 1901 } | 1901 } |
| 1902 void test_star_eq() { | 1902 void test_star_eq() { |
| 1903 assertToken(TokenType.STAR_EQ, "*="); | 1903 assertToken(TokenType.STAR_EQ, "*="); |
| 1904 } | 1904 } |
| 1905 void test_startAndEnd() { | 1905 void test_startAndEnd() { |
| 1906 Token token = scan2("a"); | 1906 Token token = scan2("a"); |
| 1907 Token previous5 = token.previous; | 1907 Token previous2 = token.previous; |
| 1908 JUnitTestCase.assertEquals(token, previous5.next); | 1908 JUnitTestCase.assertEquals(token, previous2.next); |
| 1909 JUnitTestCase.assertEquals(previous5, previous5.previous); | 1909 JUnitTestCase.assertEquals(previous2, previous2.previous); |
| 1910 Token next7 = token.next; | 1910 Token next2 = token.next; |
| 1911 JUnitTestCase.assertEquals(next7, next7.next); | 1911 JUnitTestCase.assertEquals(next2, next2.next); |
| 1912 JUnitTestCase.assertEquals(token, next7.previous); | 1912 JUnitTestCase.assertEquals(token, next2.previous); |
| 1913 } | 1913 } |
| 1914 void test_string_multi_double() { | 1914 void test_string_multi_double() { |
| 1915 assertToken(TokenType.STRING, "\"\"\"multi-line\nstring\"\"\""); | 1915 assertToken(TokenType.STRING, "\"\"\"multi-line\nstring\"\"\""); |
| 1916 } | 1916 } |
| 1917 void test_string_multi_interpolation_block() { | 1917 void test_string_multi_interpolation_block() { |
| 1918 assertTokens("\"Hello \${name}!\"", [new StringToken(TokenType.STRING, "\"He
llo ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7),
new StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CUR
LY_BRACKET, 13), new StringToken(TokenType.STRING, "!\"", 14)]); | 1918 assertTokens("\"Hello \${name}!\"", [new StringToken(TokenType.STRING, "\"He
llo ", 0), new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 7),
new StringToken(TokenType.IDENTIFIER, "name", 9), new Token(TokenType.CLOSE_CUR
LY_BRACKET, 13), new StringToken(TokenType.STRING, "!\"", 14)]); |
| 1919 } | 1919 } |
| 1920 void test_string_multi_interpolation_identifier() { | 1920 void test_string_multi_interpolation_identifier() { |
| 1921 assertTokens("\"Hello \$name!\"", [new StringToken(TokenType.STRING, "\"Hell
o ", 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), ne
w StringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING
, "!\"", 12)]); | 1921 assertTokens("\"Hello \$name!\"", [new StringToken(TokenType.STRING, "\"Hell
o ", 0), new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 7), ne
w StringToken(TokenType.IDENTIFIER, "name", 8), new StringToken(TokenType.STRING
, "!\"", 12)]); |
| 1922 } | 1922 } |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2015 * as the original source. | 2015 * as the original source. |
| 2016 * @param source the source to be scanned | 2016 * @param source the source to be scanned |
| 2017 */ | 2017 */ |
| 2018 void assertKeywordToken(String source) { | 2018 void assertKeywordToken(String source) { |
| 2019 Token token = scan2(source); | 2019 Token token = scan2(source); |
| 2020 JUnitTestCase.assertNotNull(token); | 2020 JUnitTestCase.assertNotNull(token); |
| 2021 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | 2021 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); |
| 2022 JUnitTestCase.assertEquals(0, token.offset); | 2022 JUnitTestCase.assertEquals(0, token.offset); |
| 2023 JUnitTestCase.assertEquals(source.length, token.length); | 2023 JUnitTestCase.assertEquals(source.length, token.length); |
| 2024 JUnitTestCase.assertEquals(source, token.lexeme); | 2024 JUnitTestCase.assertEquals(source, token.lexeme); |
| 2025 Object value3 = token.value(); | 2025 Object value2 = token.value(); |
| 2026 JUnitTestCase.assertTrue(value3 is Keyword); | 2026 JUnitTestCase.assertTrue(value2 is Keyword); |
| 2027 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); | 2027 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax); |
| 2028 token = scan2(" ${source} "); | 2028 token = scan2(" ${source} "); |
| 2029 JUnitTestCase.assertNotNull(token); | 2029 JUnitTestCase.assertNotNull(token); |
| 2030 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | 2030 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); |
| 2031 JUnitTestCase.assertEquals(1, token.offset); | 2031 JUnitTestCase.assertEquals(1, token.offset); |
| 2032 JUnitTestCase.assertEquals(source.length, token.length); | 2032 JUnitTestCase.assertEquals(source.length, token.length); |
| 2033 JUnitTestCase.assertEquals(source, token.lexeme); | 2033 JUnitTestCase.assertEquals(source, token.lexeme); |
| 2034 value3 = token.value(); | 2034 value2 = token.value(); |
| 2035 JUnitTestCase.assertTrue(value3 is Keyword); | 2035 JUnitTestCase.assertTrue(value2 is Keyword); |
| 2036 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); | 2036 JUnitTestCase.assertEquals(source, ((value2 as Keyword)).syntax); |
| 2037 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); | 2037 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); |
| 2038 } | 2038 } |
| 2039 /** | 2039 /** |
| 2040 * Assert that the token scanned from the given source has the expected type. | 2040 * Assert that the token scanned from the given source has the expected type. |
| 2041 * @param expectedType the expected type of the token | 2041 * @param expectedType the expected type of the token |
| 2042 * @param source the source to be scanned to produce the actual token | 2042 * @param source the source to be scanned to produce the actual token |
| 2043 */ | 2043 */ |
| 2044 Token assertToken(TokenType expectedType, String source) { | 2044 Token assertToken(TokenType expectedType, String source) { |
| 2045 Token originalToken = scan2(source); | 2045 Token originalToken = scan2(source); |
| 2046 JUnitTestCase.assertNotNull(originalToken); | 2046 JUnitTestCase.assertNotNull(originalToken); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2094 listener.assertNoErrors(); | 2094 listener.assertNoErrors(); |
| 2095 return token; | 2095 return token; |
| 2096 } | 2096 } |
| 2097 } | 2097 } |
| 2098 main() { | 2098 main() { |
| 2099 CharBufferScannerTest.dartSuite(); | 2099 CharBufferScannerTest.dartSuite(); |
| 2100 KeywordStateTest.dartSuite(); | 2100 KeywordStateTest.dartSuite(); |
| 2101 StringScannerTest.dartSuite(); | 2101 StringScannerTest.dartSuite(); |
| 2102 TokenTypeTest.dartSuite(); | 2102 TokenTypeTest.dartSuite(); |
| 2103 } | 2103 } |
| OLD | NEW |