| 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'; |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 } | 660 } |
| 661 void validateStream(StringBuffer builder, Token token) { | 661 void validateStream(StringBuffer builder, Token token) { |
| 662 if (token == null) { | 662 if (token == null) { |
| 663 return; | 663 return; |
| 664 } | 664 } |
| 665 Token previousToken = null; | 665 Token previousToken = null; |
| 666 int previousEnd = -1; | 666 int previousEnd = -1; |
| 667 Token currentToken = token; | 667 Token currentToken = token; |
| 668 while (currentToken != null && currentToken.type != TokenType.EOF) { | 668 while (currentToken != null && currentToken.type != TokenType.EOF) { |
| 669 validateStream(builder, currentToken.precedingComments); | 669 validateStream(builder, currentToken.precedingComments); |
| 670 TokenType type21 = currentToken.type; | 670 TokenType type23 = currentToken.type; |
| 671 if (type21 == TokenType.OPEN_CURLY_BRACKET || type21 == TokenType.OPEN_PAR
EN || type21 == TokenType.OPEN_SQUARE_BRACKET || type21 == TokenType.STRING_INTE
RPOLATION_EXPRESSION) { | 671 if (identical(type23, TokenType.OPEN_CURLY_BRACKET) || identical(type23, T
okenType.OPEN_PAREN) || identical(type23, TokenType.OPEN_SQUARE_BRACKET) || iden
tical(type23, TokenType.STRING_INTERPOLATION_EXPRESSION)) { |
| 672 if (currentToken is! BeginToken) { | 672 if (currentToken is! BeginToken) { |
| 673 builder.add("\r\nExpected BeginToken, found "); | 673 builder.add("\r\nExpected BeginToken, found "); |
| 674 builder.add(currentToken.runtimeType.toString()); | 674 builder.add(currentToken.runtimeType.toString()); |
| 675 builder.add(" "); | 675 builder.add(" "); |
| 676 writeToken(builder, currentToken); | 676 writeToken(builder, currentToken); |
| 677 } | 677 } |
| 678 } | 678 } |
| 679 int currentStart = currentToken.offset; | 679 int currentStart = currentToken.offset; |
| 680 int currentLength = currentToken.length; | 680 int currentLength = currentToken.length; |
| 681 int currentEnd = currentStart + currentLength - 1; | 681 int currentEnd = currentStart + currentLength - 1; |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 */ | 792 */ |
| 793 TokenFactory() { | 793 TokenFactory() { |
| 794 } | 794 } |
| 795 } | 795 } |
| 796 class KeywordStateTest extends JUnitTestCase { | 796 class KeywordStateTest extends JUnitTestCase { |
| 797 void test_KeywordState() { | 797 void test_KeywordState() { |
| 798 List<Keyword> keywords = Keyword.values; | 798 List<Keyword> keywords = Keyword.values; |
| 799 int keywordCount = keywords.length; | 799 int keywordCount = keywords.length; |
| 800 List<String> textToTest = new List<String>.fixedLength(keywordCount * 3); | 800 List<String> textToTest = new List<String>.fixedLength(keywordCount * 3); |
| 801 for (int i = 0; i < keywordCount; i++) { | 801 for (int i = 0; i < keywordCount; i++) { |
| 802 String syntax2 = keywords[i].syntax; | 802 String syntax3 = keywords[i].syntax; |
| 803 textToTest[i] = syntax2; | 803 textToTest[i] = syntax3; |
| 804 textToTest[i + keywordCount] = "${syntax2}x"; | 804 textToTest[i + keywordCount] = "${syntax3}x"; |
| 805 textToTest[i + keywordCount * 2] = syntax2.substring(0, syntax2.length - 1
); | 805 textToTest[i + keywordCount * 2] = syntax3.substring(0, syntax3.length - 1
); |
| 806 } | 806 } |
| 807 KeywordState firstState = KeywordState.KEYWORD_STATE; | 807 KeywordState firstState = KeywordState.KEYWORD_STATE; |
| 808 for (int i = 0; i < textToTest.length; i++) { | 808 for (int i = 0; i < textToTest.length; i++) { |
| 809 String text = textToTest[i]; | 809 String text = textToTest[i]; |
| 810 int index = 0; | 810 int index = 0; |
| 811 int length9 = text.length; | 811 int length10 = text.length; |
| 812 KeywordState state = firstState; | 812 KeywordState state = firstState; |
| 813 while (index < length9 && state != null) { | 813 while (index < length10 && state != null) { |
| 814 state = state.next(text.charCodeAt(index)); | 814 state = state.next(text.codeUnitAt(index)); |
| 815 index++; | 815 index++; |
| 816 } | 816 } |
| 817 if (i < keywordCount) { | 817 if (i < keywordCount) { |
| 818 JUnitTestCase.assertNotNull(state); | 818 JUnitTestCase.assertNotNull(state); |
| 819 JUnitTestCase.assertNotNull(state.keyword()); | 819 JUnitTestCase.assertNotNull(state.keyword()); |
| 820 JUnitTestCase.assertEquals(keywords[i], state.keyword()); | 820 JUnitTestCase.assertEquals(keywords[i], state.keyword()); |
| 821 } else if (i < keywordCount * 2) { | 821 } else if (i < keywordCount * 2) { |
| 822 JUnitTestCase.assertNull(state); | 822 JUnitTestCase.assertNull(state); |
| 823 } else { | 823 } else { |
| 824 JUnitTestCase.assertNotNull(state); | 824 JUnitTestCase.assertNotNull(state); |
| (...skipping 1035 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1860 assertToken(TokenType.STAR, "*"); | 1860 assertToken(TokenType.STAR, "*"); |
| 1861 } | 1861 } |
| 1862 void test_star_eq() { | 1862 void test_star_eq() { |
| 1863 assertToken(TokenType.STAR_EQ, "*="); | 1863 assertToken(TokenType.STAR_EQ, "*="); |
| 1864 } | 1864 } |
| 1865 void test_startAndEnd() { | 1865 void test_startAndEnd() { |
| 1866 Token token = scan2("a"); | 1866 Token token = scan2("a"); |
| 1867 Token previous3 = token.previous; | 1867 Token previous3 = token.previous; |
| 1868 JUnitTestCase.assertEquals(token, previous3.next); | 1868 JUnitTestCase.assertEquals(token, previous3.next); |
| 1869 JUnitTestCase.assertEquals(previous3, previous3.previous); | 1869 JUnitTestCase.assertEquals(previous3, previous3.previous); |
| 1870 Token next6 = token.next; | 1870 Token next7 = token.next; |
| 1871 JUnitTestCase.assertEquals(next6, next6.next); | 1871 JUnitTestCase.assertEquals(next7, next7.next); |
| 1872 JUnitTestCase.assertEquals(token, next6.previous); | 1872 JUnitTestCase.assertEquals(token, next7.previous); |
| 1873 } | 1873 } |
| 1874 void test_string_multi_double() { | 1874 void test_string_multi_double() { |
| 1875 assertToken(TokenType.STRING, "\"\"\"multi-line\nstring\"\"\""); | 1875 assertToken(TokenType.STRING, "\"\"\"multi-line\nstring\"\"\""); |
| 1876 } | 1876 } |
| 1877 void test_string_multi_interpolation_block() { | 1877 void test_string_multi_interpolation_block() { |
| 1878 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)]); | 1878 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)]); |
| 1879 } | 1879 } |
| 1880 void test_string_multi_interpolation_identifier() { | 1880 void test_string_multi_interpolation_identifier() { |
| 1881 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)]); | 1881 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)]); |
| 1882 } | 1882 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1961 } | 1961 } |
| 1962 /** | 1962 /** |
| 1963 * Assert that scanning the given source produces an error with the given code
. | 1963 * Assert that scanning the given source produces an error with the given code
. |
| 1964 * @param illegalCharacter | 1964 * @param illegalCharacter |
| 1965 * @param i | 1965 * @param i |
| 1966 * @param source the source to be scanned to produce the error | 1966 * @param source the source to be scanned to produce the error |
| 1967 */ | 1967 */ |
| 1968 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so
urce) { | 1968 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so
urce) { |
| 1969 GatheringErrorListener listener = new GatheringErrorListener(); | 1969 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1970 scan(source, listener); | 1970 scan(source, listener); |
| 1971 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [source.charCodeAt(expectedOffset) as int])]); | 1971 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec
tedError, [(source.codeUnitAt(expectedOffset) as int)])]); |
| 1972 } | 1972 } |
| 1973 /** | 1973 /** |
| 1974 * Assert that when scanned the given source contains a single keyword token w
ith the same lexeme | 1974 * Assert that when scanned the given source contains a single keyword token w
ith the same lexeme |
| 1975 * as the original source. | 1975 * as the original source. |
| 1976 * @param source the source to be scanned | 1976 * @param source the source to be scanned |
| 1977 */ | 1977 */ |
| 1978 void assertKeywordToken(String source) { | 1978 void assertKeywordToken(String source) { |
| 1979 Token token = scan2(source); | 1979 Token token = scan2(source); |
| 1980 JUnitTestCase.assertNotNull(token); | 1980 JUnitTestCase.assertNotNull(token); |
| 1981 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | 1981 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); |
| 1982 JUnitTestCase.assertEquals(0, token.offset); | 1982 JUnitTestCase.assertEquals(0, token.offset); |
| 1983 JUnitTestCase.assertEquals(source.length, token.length); | 1983 JUnitTestCase.assertEquals(source.length, token.length); |
| 1984 JUnitTestCase.assertEquals(source, token.lexeme); | 1984 JUnitTestCase.assertEquals(source, token.lexeme); |
| 1985 Object value3 = token.value(); | 1985 Object value3 = token.value(); |
| 1986 JUnitTestCase.assertTrue(value3 is Keyword); | 1986 JUnitTestCase.assertTrue(value3 is Keyword); |
| 1987 JUnitTestCase.assertEquals(source, (value3 as Keyword).syntax); | 1987 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); |
| 1988 token = scan2(" ${source} "); | 1988 token = scan2(" ${source} "); |
| 1989 JUnitTestCase.assertNotNull(token); | 1989 JUnitTestCase.assertNotNull(token); |
| 1990 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); | 1990 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); |
| 1991 JUnitTestCase.assertEquals(1, token.offset); | 1991 JUnitTestCase.assertEquals(1, token.offset); |
| 1992 JUnitTestCase.assertEquals(source.length, token.length); | 1992 JUnitTestCase.assertEquals(source.length, token.length); |
| 1993 JUnitTestCase.assertEquals(source, token.lexeme); | 1993 JUnitTestCase.assertEquals(source, token.lexeme); |
| 1994 value3 = token.value(); | 1994 value3 = token.value(); |
| 1995 JUnitTestCase.assertTrue(value3 is Keyword); | 1995 JUnitTestCase.assertTrue(value3 is Keyword); |
| 1996 JUnitTestCase.assertEquals(source, (value3 as Keyword).syntax); | 1996 JUnitTestCase.assertEquals(source, ((value3 as Keyword)).syntax); |
| 1997 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); | 1997 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); |
| 1998 } | 1998 } |
| 1999 /** | 1999 /** |
| 2000 * Assert that the token scanned from the given source has the expected type. | 2000 * Assert that the token scanned from the given source has the expected type. |
| 2001 * @param expectedType the expected type of the token | 2001 * @param expectedType the expected type of the token |
| 2002 * @param source the source to be scanned to produce the actual token | 2002 * @param source the source to be scanned to produce the actual token |
| 2003 */ | 2003 */ |
| 2004 Token assertToken(TokenType expectedType, String source) { | 2004 Token assertToken(TokenType expectedType, String source) { |
| 2005 Token originalToken = scan2(source); | 2005 Token originalToken = scan2(source); |
| 2006 JUnitTestCase.assertNotNull(originalToken); | 2006 JUnitTestCase.assertNotNull(originalToken); |
| 2007 JUnitTestCase.assertEquals(expectedType, originalToken.type); | 2007 JUnitTestCase.assertEquals(expectedType, originalToken.type); |
| 2008 JUnitTestCase.assertEquals(0, originalToken.offset); | 2008 JUnitTestCase.assertEquals(0, originalToken.offset); |
| 2009 JUnitTestCase.assertEquals(source.length, originalToken.length); | 2009 JUnitTestCase.assertEquals(source.length, originalToken.length); |
| 2010 JUnitTestCase.assertEquals(source, originalToken.lexeme); | 2010 JUnitTestCase.assertEquals(source, originalToken.lexeme); |
| 2011 if (expectedType == TokenType.SCRIPT_TAG) { | 2011 if (identical(expectedType, TokenType.SCRIPT_TAG)) { |
| 2012 return originalToken; | 2012 return originalToken; |
| 2013 } else if (expectedType == TokenType.SINGLE_LINE_COMMENT) { | 2013 } else if (identical(expectedType, TokenType.SINGLE_LINE_COMMENT)) { |
| 2014 Token tokenWithSpaces = scan2(" ${source}"); | 2014 Token tokenWithSpaces = scan2(" ${source}"); |
| 2015 JUnitTestCase.assertNotNull(tokenWithSpaces); | 2015 JUnitTestCase.assertNotNull(tokenWithSpaces); |
| 2016 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); | 2016 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); |
| 2017 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); | 2017 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); |
| 2018 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); | 2018 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); |
| 2019 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); | 2019 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); |
| 2020 return originalToken; | 2020 return originalToken; |
| 2021 } | 2021 } |
| 2022 Token tokenWithSpaces = scan2(" ${source} "); | 2022 Token tokenWithSpaces = scan2(" ${source} "); |
| 2023 JUnitTestCase.assertNotNull(tokenWithSpaces); | 2023 JUnitTestCase.assertNotNull(tokenWithSpaces); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 2054 listener.assertNoErrors(); | 2054 listener.assertNoErrors(); |
| 2055 return token; | 2055 return token; |
| 2056 } | 2056 } |
| 2057 } | 2057 } |
| 2058 main() { | 2058 main() { |
| 2059 CharBufferScannerTest.dartSuite(); | 2059 CharBufferScannerTest.dartSuite(); |
| 2060 KeywordStateTest.dartSuite(); | 2060 KeywordStateTest.dartSuite(); |
| 2061 StringScannerTest.dartSuite(); | 2061 StringScannerTest.dartSuite(); |
| 2062 TokenTypeTest.dartSuite(); | 2062 TokenTypeTest.dartSuite(); |
| 2063 } | 2063 } |
| OLD | NEW |