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

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

Issue 16256021: Remove trailing spaces in analyzer_experimental (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/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
4 library engine.scanner_test; 3 library engine.scanner_test;
5
6 import 'dart:collection'; 4 import 'dart:collection';
7 import 'package:analyzer_experimental/src/generated/java_core.dart'; 5 import 'package:analyzer_experimental/src/generated/java_core.dart';
8 import 'package:analyzer_experimental/src/generated/java_engine.dart'; 6 import 'package:analyzer_experimental/src/generated/java_engine.dart';
9 import 'package:analyzer_experimental/src/generated/java_junit.dart'; 7 import 'package:analyzer_experimental/src/generated/java_junit.dart';
10 import 'package:analyzer_experimental/src/generated/source.dart'; 8 import 'package:analyzer_experimental/src/generated/source.dart';
11 import 'package:analyzer_experimental/src/generated/error.dart'; 9 import 'package:analyzer_experimental/src/generated/error.dart';
12 import 'package:analyzer_experimental/src/generated/scanner.dart'; 10 import 'package:analyzer_experimental/src/generated/scanner.dart';
13 import 'package:unittest/unittest.dart' as _ut; 11 import 'package:unittest/unittest.dart' as _ut;
14 import 'test_support.dart'; 12 import 'test_support.dart';
15
16 class KeywordStateTest extends JUnitTestCase { 13 class KeywordStateTest extends JUnitTestCase {
17 void test_KeywordState() { 14 void test_KeywordState() {
18 List<Keyword> keywords = Keyword.values; 15 List<Keyword> keywords = Keyword.values;
19 int keywordCount = keywords.length; 16 int keywordCount = keywords.length;
20 List<String> textToTest = new List<String>(keywordCount * 3); 17 List<String> textToTest = new List<String>(keywordCount * 3);
21 for (int i = 0; i < keywordCount; i++) { 18 for (int i = 0; i < keywordCount; i++) {
22 String syntax2 = keywords[i].syntax; 19 String syntax2 = keywords[i].syntax;
23 textToTest[i] = syntax2; 20 textToTest[i] = syntax2;
24 textToTest[i + keywordCount] = "${syntax2}x"; 21 textToTest[i + keywordCount] = "${syntax2}x";
25 textToTest[i + keywordCount * 2] = syntax2.substring(0, syntax2.length - 1 ); 22 textToTest[i + keywordCount * 2] = syntax2.substring(0, syntax2.length - 1 );
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 final __test = new TokenTypeTest(); 121 final __test = new TokenTypeTest();
125 runJUnitTest(__test, __test.test_isOperator); 122 runJUnitTest(__test, __test.test_isOperator);
126 }); 123 });
127 _ut.test('test_isUserDefinableOperator', () { 124 _ut.test('test_isUserDefinableOperator', () {
128 final __test = new TokenTypeTest(); 125 final __test = new TokenTypeTest();
129 runJUnitTest(__test, __test.test_isUserDefinableOperator); 126 runJUnitTest(__test, __test.test_isUserDefinableOperator);
130 }); 127 });
131 }); 128 });
132 } 129 }
133 } 130 }
134
135 /** 131 /**
136 * The class {@code TokenFactory} defines utility methods that can be used to cr eate tokens. 132 * The class {@code TokenFactory} defines utility methods that can be used to cr eate tokens.
137 */ 133 */
138 class TokenFactory { 134 class TokenFactory {
139 static Token token(Keyword keyword) => new KeywordToken(keyword, 0); 135 static Token token(Keyword keyword) => new KeywordToken(keyword, 0);
140 static Token token2(String lexeme) => new StringToken(TokenType.STRING, lexeme , 0); 136 static Token token2(String lexeme) => new StringToken(TokenType.STRING, lexeme , 0);
141 static Token token3(TokenType type) => new Token(type, 0); 137 static Token token3(TokenType type) => new Token(type, 0);
142 static Token token4(TokenType type, String lexeme) => new StringToken(type, le xeme, 0); 138 static Token token4(TokenType type, String lexeme) => new StringToken(type, le xeme, 0);
143 } 139 }
144 class CharBufferScannerTest extends AbstractScannerTest { 140 class CharBufferScannerTest extends AbstractScannerTest {
(...skipping 1325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1470 final __test = new StringScannerTest(); 1466 final __test = new StringScannerTest();
1471 runJUnitTest(__test, __test.test_tilde_slash_eq); 1467 runJUnitTest(__test, __test.test_tilde_slash_eq);
1472 }); 1468 });
1473 _ut.test('test_unclosedPairInInterpolation', () { 1469 _ut.test('test_unclosedPairInInterpolation', () {
1474 final __test = new StringScannerTest(); 1470 final __test = new StringScannerTest();
1475 runJUnitTest(__test, __test.test_unclosedPairInInterpolation); 1471 runJUnitTest(__test, __test.test_unclosedPairInInterpolation);
1476 }); 1472 });
1477 }); 1473 });
1478 } 1474 }
1479 } 1475 }
1480
1481 /** 1476 /**
1482 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction 1477 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction
1483 * of a stream of tokens. 1478 * of a stream of tokens.
1484 */ 1479 */
1485 class TokenStreamValidator { 1480 class TokenStreamValidator {
1486 1481
1487 /** 1482 /**
1488 * Validate that the stream of tokens that starts with the given token is corr ect. 1483 * Validate that the stream of tokens that starts with the given token is corr ect.
1489 * @param token the first token in the stream of tokens to be validated 1484 * @param token the first token in the stream of tokens to be validated
1490 */ 1485 */
1491 void validate(Token token) { 1486 void validate(Token token) {
1492 JavaStringBuilder builder = new JavaStringBuilder(); 1487 JavaStringBuilder builder = new JavaStringBuilder();
1493 validateStream(builder, token); 1488 validateStream(builder, token);
1494 if (builder.length > 0) { 1489 if (builder.length > 0) {
1495 JUnitTestCase.fail(builder.toString()); 1490 JUnitTestCase.fail(builder.toString());
1496 } 1491 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
2041 Token token = scan2(source); 2036 Token token = scan2(source);
2042 JUnitTestCase.assertNotNull(token); 2037 JUnitTestCase.assertNotNull(token);
2043 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 2038 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
2044 Token comment = token.precedingComments; 2039 Token comment = token.precedingComments;
2045 JUnitTestCase.assertNotNull(comment); 2040 JUnitTestCase.assertNotNull(comment);
2046 JUnitTestCase.assertEquals(commentType, comment.type); 2041 JUnitTestCase.assertEquals(commentType, comment.type);
2047 JUnitTestCase.assertEquals(0, comment.offset); 2042 JUnitTestCase.assertEquals(0, comment.offset);
2048 JUnitTestCase.assertEquals(source.length, comment.length); 2043 JUnitTestCase.assertEquals(source.length, comment.length);
2049 JUnitTestCase.assertEquals(source, comment.lexeme); 2044 JUnitTestCase.assertEquals(source, comment.lexeme);
2050 } 2045 }
2051 2046
2052 /** 2047 /**
2053 * Assert that scanning the given source produces an error with the given code . 2048 * Assert that scanning the given source produces an error with the given code .
2054 * @param illegalCharacter 2049 * @param illegalCharacter
2055 * @param i 2050 * @param i
2056 * @param source the source to be scanned to produce the error 2051 * @param source the source to be scanned to produce the error
2057 */ 2052 */
2058 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so urce) { 2053 void assertError(ScannerErrorCode expectedError, int expectedOffset, String so urce) {
2059 GatheringErrorListener listener = new GatheringErrorListener(); 2054 GatheringErrorListener listener = new GatheringErrorListener();
2060 scan(source, listener); 2055 scan(source, listener);
2061 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec tedError, [(source.codeUnitAt(expectedOffset) as int)])]); 2056 listener.assertErrors([new AnalysisError.con2(null, expectedOffset, 1, expec tedError, [(source.codeUnitAt(expectedOffset) as int)])]);
2062 } 2057 }
2063 2058
2064 /** 2059 /**
2065 * Assert that when scanned the given source contains a single keyword token w ith the same lexeme 2060 * Assert that when scanned the given source contains a single keyword token w ith the same lexeme
2066 * as the original source. 2061 * as the original source.
2067 * @param source the source to be scanned 2062 * @param source the source to be scanned
2068 */ 2063 */
2069 void assertKeywordToken(String source) { 2064 void assertKeywordToken(String source) {
2070 Token token = scan2(source); 2065 Token token = scan2(source);
2071 JUnitTestCase.assertNotNull(token); 2066 JUnitTestCase.assertNotNull(token);
2072 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); 2067 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type);
2073 JUnitTestCase.assertEquals(0, token.offset); 2068 JUnitTestCase.assertEquals(0, token.offset);
(...skipping 18 matching lines...) Expand all
2092 scan(source, listener); 2087 scan(source, listener);
2093 listener.assertNoErrors(); 2088 listener.assertNoErrors();
2094 LineInfo info = listener.getLineInfo(new TestSource()); 2089 LineInfo info = listener.getLineInfo(new TestSource());
2095 JUnitTestCase.assertNotNull(info); 2090 JUnitTestCase.assertNotNull(info);
2096 for (AbstractScannerTest_ExpectedLocation expectedLocation in expectedLocati ons) { 2091 for (AbstractScannerTest_ExpectedLocation expectedLocation in expectedLocati ons) {
2097 LineInfo_Location location = info.getLocation(expectedLocation._offset); 2092 LineInfo_Location location = info.getLocation(expectedLocation._offset);
2098 JUnitTestCase.assertEquals(expectedLocation._lineNumber, location.lineNumb er); 2093 JUnitTestCase.assertEquals(expectedLocation._lineNumber, location.lineNumb er);
2099 JUnitTestCase.assertEquals(expectedLocation._columnNumber, location.column Number); 2094 JUnitTestCase.assertEquals(expectedLocation._columnNumber, location.column Number);
2100 } 2095 }
2101 } 2096 }
2102 2097
2103 /** 2098 /**
2104 * Assert that the token scanned from the given source has the expected type. 2099 * Assert that the token scanned from the given source has the expected type.
2105 * @param expectedType the expected type of the token 2100 * @param expectedType the expected type of the token
2106 * @param source the source to be scanned to produce the actual token 2101 * @param source the source to be scanned to produce the actual token
2107 */ 2102 */
2108 Token assertToken(TokenType expectedType, String source) { 2103 Token assertToken(TokenType expectedType, String source) {
2109 Token originalToken = scan2(source); 2104 Token originalToken = scan2(source);
2110 JUnitTestCase.assertNotNull(originalToken); 2105 JUnitTestCase.assertNotNull(originalToken);
2111 JUnitTestCase.assertEquals(expectedType, originalToken.type); 2106 JUnitTestCase.assertEquals(expectedType, originalToken.type);
2112 JUnitTestCase.assertEquals(0, originalToken.offset); 2107 JUnitTestCase.assertEquals(0, originalToken.offset);
(...skipping 12 matching lines...) Expand all
2125 } 2120 }
2126 Token tokenWithSpaces = scan2(" ${source} "); 2121 Token tokenWithSpaces = scan2(" ${source} ");
2127 JUnitTestCase.assertNotNull(tokenWithSpaces); 2122 JUnitTestCase.assertNotNull(tokenWithSpaces);
2128 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); 2123 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type);
2129 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); 2124 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset);
2130 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); 2125 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length);
2131 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); 2126 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme);
2132 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type); 2127 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type);
2133 return originalToken; 2128 return originalToken;
2134 } 2129 }
2135 2130
2136 /** 2131 /**
2137 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given 2132 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given
2138 * tokens. 2133 * tokens.
2139 * @param source the source to be scanned 2134 * @param source the source to be scanned
2140 * @param expectedTokens the tokens that are expected to be in the source 2135 * @param expectedTokens the tokens that are expected to be in the source
2141 */ 2136 */
2142 void assertTokens(String source, List<Token> expectedTokens) { 2137 void assertTokens(String source, List<Token> expectedTokens) {
2143 Token token = scan2(source); 2138 Token token = scan2(source);
2144 JUnitTestCase.assertNotNull(token); 2139 JUnitTestCase.assertNotNull(token);
2145 for (int i = 0; i < expectedTokens.length; i++) { 2140 for (int i = 0; i < expectedTokens.length; i++) {
2146 Token expectedToken = expectedTokens[i]; 2141 Token expectedToken = expectedTokens[i];
2147 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t ype, token.type); 2142 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t ype, token.type);
2148 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken .offset, token.offset); 2143 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken .offset, token.offset);
2149 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken .length, token.length); 2144 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken .length, token.length);
2150 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken .lexeme, token.lexeme); 2145 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken .lexeme, token.lexeme);
2151 token = token.next; 2146 token = token.next;
2152 JUnitTestCase.assertNotNull(token); 2147 JUnitTestCase.assertNotNull(token);
2153 } 2148 }
2154 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 2149 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
2155 } 2150 }
2156 Token scan2(String source) { 2151 Token scan2(String source) {
2157 GatheringErrorListener listener = new GatheringErrorListener(); 2152 GatheringErrorListener listener = new GatheringErrorListener();
2158 Token token = scan(source, listener); 2153 Token token = scan(source, listener);
2159 listener.assertNoErrors(); 2154 listener.assertNoErrors();
2160 return token; 2155 return token;
2161 } 2156 }
2162 } 2157 }
2163
2164 /** 2158 /**
2165 * Instances of the class {@code ExpectedLocation} encode information about the expected location 2159 * Instances of the class {@code ExpectedLocation} encode information about the expected location
2166 * of a given offset in source code. 2160 * of a given offset in source code.
2167 */ 2161 */
2168 class AbstractScannerTest_ExpectedLocation { 2162 class AbstractScannerTest_ExpectedLocation {
2169 int _offset = 0; 2163 int _offset = 0;
2170 int _lineNumber = 0; 2164 int _lineNumber = 0;
2171 int _columnNumber = 0; 2165 int _columnNumber = 0;
2172 AbstractScannerTest_ExpectedLocation(int offset, int lineNumber, int columnNum ber) { 2166 AbstractScannerTest_ExpectedLocation(int offset, int lineNumber, int columnNum ber) {
2173 this._offset = offset; 2167 this._offset = offset;
2174 this._lineNumber = lineNumber; 2168 this._lineNumber = lineNumber;
2175 this._columnNumber = columnNumber; 2169 this._columnNumber = columnNumber;
2176 } 2170 }
2177 } 2171 }
2178 main() { 2172 main() {
2179 CharBufferScannerTest.dartSuite(); 2173 CharBufferScannerTest.dartSuite();
2180 KeywordStateTest.dartSuite(); 2174 KeywordStateTest.dartSuite();
2181 StringScannerTest.dartSuite(); 2175 StringScannerTest.dartSuite();
2182 TokenTypeTest.dartSuite(); 2176 TokenTypeTest.dartSuite();
2183 } 2177 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698