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

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

Issue 2682423003: Unify fasta->analyzer token translation logic. (Closed)
Patch Set: Created 3 years, 10 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
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 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 158
159 void test_ampersand_ampersand_eq() { 159 void test_ampersand_ampersand_eq() {
160 _assertToken(TokenType.AMPERSAND_AMPERSAND_EQ, "&&=", 160 _assertToken(TokenType.AMPERSAND_AMPERSAND_EQ, "&&=",
161 lazyAssignmentOperators: true); 161 lazyAssignmentOperators: true);
162 } 162 }
163 163
164 void test_ampersand_eq() { 164 void test_ampersand_eq() {
165 _assertToken(TokenType.AMPERSAND_EQ, "&="); 165 _assertToken(TokenType.AMPERSAND_EQ, "&=");
166 } 166 }
167 167
168 void test_async_star() {
169 Token token = _scan("async*");
170 expect(token.type, TokenType.IDENTIFIER);
171 expect(token.lexeme, 'async');
172 expect(token.next.type, TokenType.STAR);
173 expect(token.next.next.type, TokenType.EOF);
174 }
175
168 void test_at() { 176 void test_at() {
169 _assertToken(TokenType.AT, "@"); 177 _assertToken(TokenType.AT, "@");
170 } 178 }
171 179
172 void test_backping() { 180 void test_backping() {
173 _assertToken(TokenType.BACKPING, "`"); 181 _assertToken(TokenType.BACKPING, "`");
174 } 182 }
175 183
176 void test_backslash() { 184 void test_backslash() {
177 _assertToken(TokenType.BACKSLASH, "\\"); 185 _assertToken(TokenType.BACKSLASH, "\\");
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 } 446 }
439 447
440 void test_keyword_as() { 448 void test_keyword_as() {
441 _assertKeywordToken("as"); 449 _assertKeywordToken("as");
442 } 450 }
443 451
444 void test_keyword_assert() { 452 void test_keyword_assert() {
445 _assertKeywordToken("assert"); 453 _assertKeywordToken("assert");
446 } 454 }
447 455
456 void test_keyword_async() {
457 _assertIdentifierToken("async");
458 }
459
460 void test_keyword_await() {
461 _assertIdentifierToken("await");
462 }
463
448 void test_keyword_break() { 464 void test_keyword_break() {
449 _assertKeywordToken("break"); 465 _assertKeywordToken("break");
450 } 466 }
451 467
452 void test_keyword_case() { 468 void test_keyword_case() {
453 _assertKeywordToken("case"); 469 _assertKeywordToken("case");
454 } 470 }
455 471
456 void test_keyword_catch() { 472 void test_keyword_catch() {
457 _assertKeywordToken("catch"); 473 _assertKeywordToken("catch");
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
582 } 598 }
583 599
584 void test_keyword_super() { 600 void test_keyword_super() {
585 _assertKeywordToken("super"); 601 _assertKeywordToken("super");
586 } 602 }
587 603
588 void test_keyword_switch() { 604 void test_keyword_switch() {
589 _assertKeywordToken("switch"); 605 _assertKeywordToken("switch");
590 } 606 }
591 607
608 void test_keyword_sync() {
609 _assertIdentifierToken("sync");
610 }
611
592 void test_keyword_this() { 612 void test_keyword_this() {
593 _assertKeywordToken("this"); 613 _assertKeywordToken("this");
594 } 614 }
595 615
596 void test_keyword_throw() { 616 void test_keyword_throw() {
597 _assertKeywordToken("throw"); 617 _assertKeywordToken("throw");
598 } 618 }
599 619
600 void test_keyword_true() { 620 void test_keyword_true() {
601 _assertKeywordToken("true"); 621 _assertKeywordToken("true");
(...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after
1006 void test_string_simple_unterminated_interpolation_identifier() { 1026 void test_string_simple_unterminated_interpolation_identifier() {
1007 _assertErrorAndTokens( 1027 _assertErrorAndTokens(
1008 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [ 1028 ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 5, "'\$name", [
1009 new StringToken(TokenType.STRING, "'", 0), 1029 new StringToken(TokenType.STRING, "'", 0),
1010 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1), 1030 new StringToken(TokenType.STRING_INTERPOLATION_IDENTIFIER, "\$", 1),
1011 new StringToken(TokenType.IDENTIFIER, "name", 2), 1031 new StringToken(TokenType.IDENTIFIER, "name", 2),
1012 new StringToken(TokenType.STRING, "", 6) 1032 new StringToken(TokenType.STRING, "", 6)
1013 ]); 1033 ]);
1014 } 1034 }
1015 1035
1036 void test_sync_star() {
1037 Token token = _scan("sync*");
1038 expect(token.type, TokenType.IDENTIFIER);
1039 expect(token.lexeme, 'sync');
1040 expect(token.next.type, TokenType.STAR);
1041 expect(token.next.next.type, TokenType.EOF);
1042 }
1043
1016 void test_tilde() { 1044 void test_tilde() {
1017 _assertToken(TokenType.TILDE, "~"); 1045 _assertToken(TokenType.TILDE, "~");
1018 } 1046 }
1019 1047
1020 void test_tilde_slash() { 1048 void test_tilde_slash() {
1021 _assertToken(TokenType.TILDE_SLASH, "~/"); 1049 _assertToken(TokenType.TILDE_SLASH, "~/");
1022 } 1050 }
1023 1051
1024 void test_tilde_slash_eq() { 1052 void test_tilde_slash_eq() {
1025 _assertToken(TokenType.TILDE_SLASH_EQ, "~/="); 1053 _assertToken(TokenType.TILDE_SLASH_EQ, "~/=");
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset, 1115 void _assertErrorAndTokens(ScannerErrorCode expectedError, int expectedOffset,
1088 String source, List<Token> expectedTokens) { 1116 String source, List<Token> expectedTokens) {
1089 ErrorListener listener = new ErrorListener(); 1117 ErrorListener listener = new ErrorListener();
1090 Token token = scanWithListener(source, listener); 1118 Token token = scanWithListener(source, listener);
1091 listener 1119 listener
1092 .assertErrors([new TestError(expectedOffset, 1, expectedError, null)]); 1120 .assertErrors([new TestError(expectedOffset, 1, expectedError, null)]);
1093 _checkTokens(token, expectedTokens); 1121 _checkTokens(token, expectedTokens);
1094 } 1122 }
1095 1123
1096 /** 1124 /**
1125 * Assert that when scanned the given [source] contains a single identifier
1126 * token with the same lexeme as the original source.
1127 */
1128 void _assertIdentifierToken(String source) {
1129 void check(String s, int expectedOffset) {
1130 Token token = _scan(s);
1131 expect(token, isNotNull);
1132 expect(token.type, TokenType.IDENTIFIER);
1133 expect(token.offset, expectedOffset);
1134 expect(token.length, source.length);
1135 expect(token.lexeme, source);
1136 expect(token.value(), source);
1137 expect(token.next.type, TokenType.EOF);
1138 }
1139
1140 check(source, 0);
1141 check(' $source ', 1);
1142 }
1143
1144 /**
1097 * Assert that when scanned the given [source] contains a single keyword token 1145 * Assert that when scanned the given [source] contains a single keyword token
1098 * with the same lexeme as the original source. 1146 * with the same lexeme as the original source.
1099 */ 1147 */
1100 void _assertKeywordToken(String source) { 1148 void _assertKeywordToken(String source) {
1101 Token token = _scan(source); 1149 Token token = _scan(source);
1102 expect(token, isNotNull); 1150 expect(token, isNotNull);
1103 expect(token.type, TokenType.KEYWORD); 1151 expect(token.type, TokenType.KEYWORD);
1104 expect(token.offset, 0); 1152 expect(token.offset, 0);
1105 expect(token.length, source.length); 1153 expect(token.length, source.length);
1106 expect(token.lexeme, source); 1154 expect(token.lexeme, source);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 _TestScanner(CharacterReader reader, [this.listener]) : super(reader); 1379 _TestScanner(CharacterReader reader, [this.listener]) : super(reader);
1332 1380
1333 @override 1381 @override
1334 void reportError( 1382 void reportError(
1335 ScannerErrorCode errorCode, int offset, List<Object> arguments) { 1383 ScannerErrorCode errorCode, int offset, List<Object> arguments) {
1336 if (listener != null) { 1384 if (listener != null) {
1337 listener.errors.add(new TestError(offset, 1, errorCode, arguments)); 1385 listener.errors.add(new TestError(offset, 1, errorCode, arguments));
1338 } 1386 }
1339 } 1387 }
1340 } 1388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698