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

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

Issue 2832403002: merge PrecedenceInfo into TokenType and update all refs (Closed)
Patch Set: rebase 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
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, 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/fasta/scanner/precedence.dart';
6 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; 5 import 'package:front_end/src/fasta/scanner/string_scanner.dart';
7 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta;
8 import 'package:front_end/src/scanner/token.dart'; 7 import 'package:front_end/src/scanner/token.dart';
9 import 'package:test/test.dart'; 8 import 'package:test/test.dart';
10 import 'package:test_reflective_loader/test_reflective_loader.dart'; 9 import 'package:test_reflective_loader/test_reflective_loader.dart';
11 10
12 main() { 11 main() {
13 defineReflectiveSuite(() { 12 defineReflectiveSuite(() {
14 defineReflectiveTests(PrecedenceInfoTest); 13 defineReflectiveTests(PrecedenceInfoTest);
15 }); 14 });
16 } 15 }
17 16
18 /// Assert that fasta PrecedenceInfo implements analyzer TokenType. 17 /// Assert that fasta PrecedenceInfo implements analyzer TokenType.
19 @reflectiveTest 18 @reflectiveTest
20 class PrecedenceInfoTest { 19 class PrecedenceInfoTest {
21 var allTokenTypes = new Set<TokenType>.from(const [
22 TokenType.EOF,
23 TokenType.DOUBLE,
24 TokenType.HEXADECIMAL,
25 TokenType.IDENTIFIER,
26 TokenType.INT,
27 TokenType.KEYWORD,
28 TokenType.MULTI_LINE_COMMENT,
29 TokenType.SCRIPT_TAG,
30 TokenType.SINGLE_LINE_COMMENT,
31 TokenType.STRING,
32 TokenType.AMPERSAND,
33 TokenType.AMPERSAND_AMPERSAND,
34 TokenType.AMPERSAND_EQ,
35 TokenType.AT,
36 TokenType.BANG,
37 TokenType.BANG_EQ,
38 TokenType.BAR,
39 TokenType.BAR_BAR,
40 TokenType.BAR_EQ,
41 TokenType.COLON,
42 TokenType.COMMA,
43 TokenType.CARET,
44 TokenType.CARET_EQ,
45 TokenType.CLOSE_CURLY_BRACKET,
46 TokenType.CLOSE_PAREN,
47 TokenType.CLOSE_SQUARE_BRACKET,
48 TokenType.EQ,
49 TokenType.EQ_EQ,
50 TokenType.FUNCTION,
51 TokenType.GT,
52 TokenType.GT_EQ,
53 TokenType.GT_GT,
54 TokenType.GT_GT_EQ,
55 TokenType.HASH,
56 TokenType.INDEX,
57 TokenType.INDEX_EQ,
58 TokenType.LT,
59 TokenType.LT_EQ,
60 TokenType.LT_LT,
61 TokenType.LT_LT_EQ,
62 TokenType.MINUS,
63 TokenType.MINUS_EQ,
64 TokenType.MINUS_MINUS,
65 TokenType.OPEN_CURLY_BRACKET,
66 TokenType.OPEN_PAREN,
67 TokenType.OPEN_SQUARE_BRACKET,
68 TokenType.PERCENT,
69 TokenType.PERCENT_EQ,
70 TokenType.PERIOD,
71 TokenType.PERIOD_PERIOD,
72 TokenType.PLUS,
73 TokenType.PLUS_EQ,
74 TokenType.PLUS_PLUS,
75 TokenType.QUESTION,
76 TokenType.QUESTION_PERIOD,
77 TokenType.QUESTION_QUESTION,
78 TokenType.QUESTION_QUESTION_EQ,
79 TokenType.SEMICOLON,
80 TokenType.SLASH,
81 TokenType.SLASH_EQ,
82 TokenType.STAR,
83 TokenType.STAR_EQ,
84 TokenType.STRING_INTERPOLATION_EXPRESSION,
85 TokenType.STRING_INTERPOLATION_IDENTIFIER,
86 TokenType.TILDE,
87 TokenType.TILDE_SLASH,
88 TokenType.TILDE_SLASH_EQ,
89 TokenType.BACKPING,
90 TokenType.BACKSLASH,
91 TokenType.PERIOD_PERIOD_PERIOD,
92 TokenType.GENERIC_METHOD_TYPE_LIST,
93 TokenType.GENERIC_METHOD_TYPE_ASSIGN,
94
95 // These are not yet part of the language and not supported by fasta
96 //TokenType.AMPERSAND_AMPERSAND_EQ,
97 //TokenType.BAR_BAR_EQ,
98 ]);
99
100 void assertInfo(check(String source, fasta.Token token), 20 void assertInfo(check(String source, fasta.Token token),
101 {bool includeLazyAssignmentOperators: true}) { 21 {bool includeLazyAssignmentOperators: true}) {
102 void assertLexeme(String source) { 22 void assertLexeme(String source) {
103 if (source == null || source.isEmpty) return; 23 if (source == null || source.isEmpty) return;
104 var scanner = new StringScanner(source, includeComments: true); 24 var scanner = new StringScanner(source, includeComments: true);
105 var token = scanner.tokenize(); 25 var token = scanner.tokenize();
106 check(source, token); 26 check(source, token);
107 } 27 }
108 28
109 for (TokenType info in TokenType.all) { 29 for (TokenType info in TokenType.all) {
110 assertLexeme(info.value); 30 assertLexeme(info.value);
111 } 31 }
112 for (TokenType tt in allTokenTypes) {
113 assertLexeme(tt.lexeme);
114 }
115 assertLexeme('1.0'); // DOUBLE 32 assertLexeme('1.0'); // DOUBLE
116 assertLexeme('0xA'); // HEXADECIMAL 33 assertLexeme('0xA'); // HEXADECIMAL
117 assertLexeme('1'); // INT 34 assertLexeme('1'); // INT
118 assertLexeme('var'); // KEYWORD 35 assertLexeme('var'); // KEYWORD
119 assertLexeme('#!/'); // SCRIPT_TAG 36 assertLexeme('#!/'); // SCRIPT_TAG
120 assertLexeme('"foo"'); // STRING 37 assertLexeme('"foo"'); // STRING
121 assertLexeme('bar'); // IDENTIFIER 38 assertLexeme('bar'); // IDENTIFIER
122 if (includeLazyAssignmentOperators) { 39 if (includeLazyAssignmentOperators) {
123 assertLexeme('&&='); 40 assertLexeme('&&=');
124 assertLexeme('||='); 41 assertLexeme('||=');
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
455 }; 372 };
456 precedenceTable.forEach((precedence, lexemes) { 373 precedenceTable.forEach((precedence, lexemes) {
457 for (String source in lexemes) { 374 for (String source in lexemes) {
458 var scanner = new StringScanner(source, includeComments: true); 375 var scanner = new StringScanner(source, includeComments: true);
459 var token = scanner.tokenize(); 376 var token = scanner.tokenize();
460 expect(token.info.precedence, precedence, reason: source); 377 expect(token.info.precedence, precedence, reason: source);
461 } 378 }
462 }); 379 });
463 } 380 }
464 381
465 void test_identity() { 382 void test_type() {
466 var exceptions = <TokenType>[
467 // Null lexeme - no corresponding PrecedenceInfo
468 TokenType.MULTI_LINE_COMMENT,
469 TokenType.SINGLE_LINE_COMMENT,
470 TokenType.GENERIC_METHOD_TYPE_LIST,
471 TokenType.GENERIC_METHOD_TYPE_ASSIGN,
472
473 // Manually compared below
474 TokenType.DOUBLE,
475 TokenType.HEXADECIMAL,
476 TokenType.INT,
477 TokenType.KEYWORD,
478 TokenType.SCRIPT_TAG,
479 TokenType.STRING,
480 TokenType.STRING_INTERPOLATION_EXPRESSION,
481 TokenType.STRING_INTERPOLATION_IDENTIFIER,
482 ];
483
484 void assertLexeme(String source, TokenType tt) { 383 void assertLexeme(String source, TokenType tt) {
485 var scanner = new StringScanner(source, includeComments: true); 384 var scanner = new StringScanner(source, includeComments: true);
486 var token = scanner.tokenize(); 385 var token = scanner.tokenize();
487 expect(token.type, same(tt), reason: source); 386 expect(token.type, same(tt), reason: source);
488 } 387 }
489 388
490 for (TokenType tt in allTokenTypes) {
491 if (!exceptions.contains(tt)) {
492 assertLexeme(tt.lexeme, tt);
493 }
494 }
495 expect(DOUBLE_INFO, same(TokenType.DOUBLE));
496 expect(HEXADECIMAL_INFO, same(TokenType.HEXADECIMAL));
497 expect(INT_INFO, same(TokenType.INT));
498 expect(KEYWORD_INFO, same(TokenType.KEYWORD));
499 expect(SCRIPT_INFO, same(TokenType.SCRIPT_TAG));
500 expect(STRING_INFO, same(TokenType.STRING));
501
502 assertLexeme('1.0', TokenType.DOUBLE); 389 assertLexeme('1.0', TokenType.DOUBLE);
503 assertLexeme('0xA', TokenType.HEXADECIMAL); 390 assertLexeme('0xA', TokenType.HEXADECIMAL);
504 assertLexeme('1', TokenType.INT); 391 assertLexeme('1', TokenType.INT);
505 assertLexeme('var', TokenType.KEYWORD); 392 assertLexeme('var', TokenType.KEYWORD);
506 assertLexeme('#!/', TokenType.SCRIPT_TAG); 393 assertLexeme('#!/', TokenType.SCRIPT_TAG);
507 assertLexeme('"foo"', TokenType.STRING); 394 assertLexeme('"foo"', TokenType.STRING);
508
509 expect(STRING_INTERPOLATION_INFO,
510 same(TokenType.STRING_INTERPOLATION_EXPRESSION));
511 expect(STRING_INTERPOLATION_IDENTIFIER_INFO,
512 same(TokenType.STRING_INTERPOLATION_IDENTIFIER));
513 } 395 }
514 } 396 }
OLDNEW
« no previous file with comments | « pkg/front_end/test/fasta/parser/token_stream_rewriter_test.dart ('k') | pkg/front_end/test/scanner_replacement_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698