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

Side by Side Diff: pkg/front_end/test/scanner_test.dart

Issue 2842643004: flatten Keyword into TokenType (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « pkg/front_end/test/precedence_info_test.dart ('k') | pkg/front_end/test/token_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, 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 import 'package:front_end/src/base/errors.dart'; 5 import 'package:front_end/src/base/errors.dart';
6 import 'package:front_end/src/base/jenkins_smi_hash.dart'; 6 import 'package:front_end/src/base/jenkins_smi_hash.dart';
7 import 'package:front_end/src/scanner/errors.dart'; 7 import 'package:front_end/src/scanner/errors.dart';
8 import 'package:front_end/src/scanner/reader.dart'; 8 import 'package:front_end/src/scanner/reader.dart';
9 import 'package:front_end/src/scanner/scanner.dart'; 9 import 'package:front_end/src/scanner/scanner.dart';
10 import 'package:front_end/src/scanner/token.dart'; 10 import 'package:front_end/src/scanner/token.dart';
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 @reflectiveTest 83 @reflectiveTest
84 class KeywordStateTest { 84 class KeywordStateTest {
85 void test_KeywordState() { 85 void test_KeywordState() {
86 // 86 //
87 // Generate the test data to be scanned. 87 // Generate the test data to be scanned.
88 // 88 //
89 List<Keyword> keywords = Keyword.values; 89 List<Keyword> keywords = Keyword.values;
90 int keywordCount = keywords.length; 90 int keywordCount = keywords.length;
91 List<String> textToTest = new List<String>(keywordCount * 3); 91 List<String> textToTest = new List<String>(keywordCount * 3);
92 for (int i = 0; i < keywordCount; i++) { 92 for (int i = 0; i < keywordCount; i++) {
93 String syntax = keywords[i].syntax; 93 String syntax = keywords[i].lexeme;
94 textToTest[i] = syntax; 94 textToTest[i] = syntax;
95 textToTest[i + keywordCount] = "${syntax}x"; 95 textToTest[i + keywordCount] = "${syntax}x";
96 textToTest[i + keywordCount * 2] = syntax.substring(0, syntax.length - 1); 96 textToTest[i + keywordCount * 2] = syntax.substring(0, syntax.length - 1);
97 } 97 }
98 // 98 //
99 // Scan each of the identifiers. 99 // Scan each of the identifiers.
100 // 100 //
101 KeywordState firstState = KeywordState.KEYWORD_STATE; 101 KeywordState firstState = KeywordState.KEYWORD_STATE;
102 for (int i = 0; i < textToTest.length; i++) { 102 for (int i = 0; i < textToTest.length; i++) {
103 String text = textToTest[i]; 103 String text = textToTest[i];
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 // Analyzer's token streams don't consider "<" to be an opener 173 // Analyzer's token streams don't consider "<" to be an opener
174 // but fasta does. 174 // but fasta does.
175 if (lessThan is BeginToken) { 175 if (lessThan is BeginToken) {
176 expect(lessThan.endToken, greaterThan); 176 expect(lessThan.endToken, greaterThan);
177 } 177 }
178 expect(greaterThan, isNot(new isInstanceOf<BeginToken>())); 178 expect(greaterThan, isNot(new isInstanceOf<BeginToken>()));
179 } 179 }
180 180
181 void test_async_star() { 181 void test_async_star() {
182 Token token = _scan("async*"); 182 Token token = _scan("async*");
183 expect(token.type, TokenType.KEYWORD); 183 expect(token.type.isKeyword, true);
184 expect(token.lexeme, 'async'); 184 expect(token.lexeme, 'async');
185 expect(token.next.type, TokenType.STAR); 185 expect(token.next.type, TokenType.STAR);
186 expect(token.next.next.type, TokenType.EOF); 186 expect(token.next.next.type, TokenType.EOF);
187 } 187 }
188 188
189 void test_at() { 189 void test_at() {
190 _assertToken(TokenType.AT, "@"); 190 _assertToken(TokenType.AT, "@");
191 } 191 }
192 192
193 void test_backping() { 193 void test_backping() {
(...skipping 967 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [ 1161 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [
1162 new StringToken(TokenType.STRING, "'", 0), 1162 new StringToken(TokenType.STRING, "'", 0),
1163 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), 1163 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1),
1164 new StringToken(TokenType.IDENTIFIER, "name", 2), 1164 new StringToken(TokenType.IDENTIFIER, "name", 2),
1165 new StringToken(TokenType.STRING, "", 6) 1165 new StringToken(TokenType.STRING, "", 6)
1166 ]); 1166 ]);
1167 } 1167 }
1168 1168
1169 void test_sync_star() { 1169 void test_sync_star() {
1170 Token token = _scan("sync*"); 1170 Token token = _scan("sync*");
1171 expect(token.type, TokenType.KEYWORD); 1171 expect(token.type.isKeyword, true);
1172 expect(token.lexeme, 'sync'); 1172 expect(token.lexeme, 'sync');
1173 expect(token.next.type, TokenType.STAR); 1173 expect(token.next.type, TokenType.STAR);
1174 expect(token.next.next.type, TokenType.EOF); 1174 expect(token.next.next.type, TokenType.EOF);
1175 } 1175 }
1176 1176
1177 void test_tilde() { 1177 void test_tilde() {
1178 _assertToken(TokenType.TILDE, "~"); 1178 _assertToken(TokenType.TILDE, "~");
1179 } 1179 }
1180 1180
1181 void test_tilde_slash() { 1181 void test_tilde_slash() {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
1263 _checkTokens(token, expectedTokens); 1263 _checkTokens(token, expectedTokens);
1264 } 1264 }
1265 1265
1266 /** 1266 /**
1267 * Assert that when scanned the given [source] contains a single keyword token 1267 * Assert that when scanned the given [source] contains a single keyword token
1268 * with the same lexeme as the original source. 1268 * with the same lexeme as the original source.
1269 */ 1269 */
1270 void _assertKeywordToken(String source) { 1270 void _assertKeywordToken(String source) {
1271 Token token = _scan(source); 1271 Token token = _scan(source);
1272 expect(token, isNotNull); 1272 expect(token, isNotNull);
1273 expect(token.type, TokenType.KEYWORD); 1273 expect(token.type.isKeyword, true);
1274 expect(token.offset, 0); 1274 expect(token.offset, 0);
1275 expect(token.length, source.length); 1275 expect(token.length, source.length);
1276 expect(token.lexeme, source); 1276 expect(token.lexeme, source);
1277 Object value = token.value(); 1277 Object value = token.value();
1278 expect(value is Keyword, isTrue); 1278 expect(value is Keyword, isTrue);
1279 expect((value as Keyword).syntax, source); 1279 expect((value as Keyword).lexeme, source);
1280 token = _scan(" $source "); 1280 token = _scan(" $source ");
1281 expect(token, isNotNull); 1281 expect(token, isNotNull);
1282 expect(token.type, TokenType.KEYWORD); 1282 expect(token.type.isKeyword, true);
1283 expect(token.offset, 1); 1283 expect(token.offset, 1);
1284 expect(token.length, source.length); 1284 expect(token.length, source.length);
1285 expect(token.lexeme, source); 1285 expect(token.lexeme, source);
1286 value = token.value(); 1286 value = token.value();
1287 expect(value is Keyword, isTrue); 1287 expect(value is Keyword, isTrue);
1288 expect((value as Keyword).syntax, source); 1288 expect((value as Keyword).lexeme, source);
1289 expect(token.next.type, TokenType.EOF); 1289 expect(token.next.type, TokenType.EOF);
1290 } 1290 }
1291 1291
1292 /** 1292 /**
1293 * Assert that the token scanned from the given [source] has the 1293 * Assert that the token scanned from the given [source] has the
1294 * [expectedType]. 1294 * [expectedType].
1295 */ 1295 */
1296 Token _assertToken(TokenType expectedType, String source, 1296 Token _assertToken(TokenType expectedType, String source,
1297 {bool lazyAssignmentOperators: false}) { 1297 {bool lazyAssignmentOperators: false}) {
1298 Token originalToken = 1298 Token originalToken =
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1499 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader); 1499 _TestScanner(CharacterReader reader, [this.listener]) : super.create(reader);
1500 1500
1501 @override 1501 @override
1502 void reportError( 1502 void reportError(
1503 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1503 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1504 if (listener != null) { 1504 if (listener != null) {
1505 listener.errors.add(new TestError(offset, errorCode, arguments)); 1505 listener.errors.add(new TestError(offset, errorCode, arguments));
1506 } 1506 }
1507 } 1507 }
1508 } 1508 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/precedence_info_test.dart ('k') | pkg/front_end/test/token_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698