| OLD | NEW |
| 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/string_scanner.dart'; | 5 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 6 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 7 import 'package:front_end/src/scanner/token.dart'; | 7 import 'package:front_end/src/scanner/token.dart'; |
| 8 import 'package:test/test.dart'; | 8 import 'package:test/test.dart'; |
| 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 9 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| 10 | 10 |
| 11 main() { | 11 main() { |
| 12 defineReflectiveSuite(() { | 12 defineReflectiveSuite(() { |
| 13 defineReflectiveTests(PrecedenceInfoTest); | 13 defineReflectiveTests(PrecedenceInfoTest); |
| 14 }); | 14 }); |
| 15 } | 15 } |
| 16 | 16 |
| 17 /// Assert that fasta PrecedenceInfo implements analyzer TokenType. | 17 /// Assert that fasta PrecedenceInfo implements analyzer TokenType. |
| 18 @reflectiveTest | 18 @reflectiveTest |
| 19 class PrecedenceInfoTest { | 19 class PrecedenceInfoTest { |
| 20 void assertInfo(check(String source, fasta.Token token), | 20 void assertInfo(check(String source, fasta.Token token), |
| 21 {bool includeLazyAssignmentOperators: true}) { | 21 {bool includeLazyAssignmentOperators: true}) { |
| 22 void assertLexeme(String source) { | 22 void assertLexeme(String source) { |
| 23 if (source == null || source.isEmpty) return; | 23 if (source == null || source.isEmpty) return; |
| 24 var scanner = new StringScanner(source, includeComments: true); | 24 var scanner = new StringScanner(source, includeComments: true); |
| 25 var token = scanner.tokenize(); | 25 var token = scanner.tokenize(); |
| 26 check(source, token); | 26 check(source, token); |
| 27 } | 27 } |
| 28 | 28 |
| 29 for (TokenType info in TokenType.all) { | 29 for (TokenType type in TokenType.all) { |
| 30 assertLexeme(info.value); | 30 assertLexeme(type.value); |
| 31 } | 31 } |
| 32 assertLexeme('1.0'); // DOUBLE | 32 assertLexeme('1.0'); // DOUBLE |
| 33 assertLexeme('0xA'); // HEXADECIMAL | 33 assertLexeme('0xA'); // HEXADECIMAL |
| 34 assertLexeme('1'); // INT | 34 assertLexeme('1'); // INT |
| 35 assertLexeme('var'); // KEYWORD | 35 assertLexeme('var'); // KEYWORD |
| 36 assertLexeme('#!/'); // SCRIPT_TAG | 36 assertLexeme('#!/'); // SCRIPT_TAG |
| 37 assertLexeme('"foo"'); // STRING | 37 assertLexeme('"foo"'); // STRING |
| 38 assertLexeme('bar'); // IDENTIFIER | 38 assertLexeme('bar'); // IDENTIFIER |
| 39 if (includeLazyAssignmentOperators) { | 39 if (includeLazyAssignmentOperators) { |
| 40 assertLexeme('&&='); | 40 assertLexeme('&&='); |
| (...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 5: const <String>['||'], | 367 5: const <String>['||'], |
| 368 4: const <String>['??'], | 368 4: const <String>['??'], |
| 369 3: const <String>['? :'], | 369 3: const <String>['? :'], |
| 370 2: const <String>['..'], | 370 2: const <String>['..'], |
| 371 1: const <String>['=', '*=', '/=', '+=', '-=', '&=', '^='], | 371 1: const <String>['=', '*=', '/=', '+=', '-=', '&=', '^='], |
| 372 }; | 372 }; |
| 373 precedenceTable.forEach((precedence, lexemes) { | 373 precedenceTable.forEach((precedence, lexemes) { |
| 374 for (String source in lexemes) { | 374 for (String source in lexemes) { |
| 375 var scanner = new StringScanner(source, includeComments: true); | 375 var scanner = new StringScanner(source, includeComments: true); |
| 376 var token = scanner.tokenize(); | 376 var token = scanner.tokenize(); |
| 377 expect(token.info.precedence, precedence, reason: source); | 377 expect(token.type.precedence, precedence, reason: source); |
| 378 } | 378 } |
| 379 }); | 379 }); |
| 380 } | 380 } |
| 381 | 381 |
| 382 void test_type() { | 382 void test_type() { |
| 383 void assertLexeme(String source, TokenType tt) { | 383 void assertLexeme(String source, TokenType tt) { |
| 384 var scanner = new StringScanner(source, includeComments: true); | 384 var scanner = new StringScanner(source, includeComments: true); |
| 385 var token = scanner.tokenize(); | 385 var token = scanner.tokenize(); |
| 386 expect(token.type, same(tt), reason: source); | 386 expect(token.type, same(tt), reason: source); |
| 387 } | 387 } |
| 388 | 388 |
| 389 assertLexeme('1.0', TokenType.DOUBLE); | 389 assertLexeme('1.0', TokenType.DOUBLE); |
| 390 assertLexeme('0xA', TokenType.HEXADECIMAL); | 390 assertLexeme('0xA', TokenType.HEXADECIMAL); |
| 391 assertLexeme('1', TokenType.INT); | 391 assertLexeme('1', TokenType.INT); |
| 392 assertLexeme('var', Keyword.VAR); | 392 assertLexeme('var', Keyword.VAR); |
| 393 assertLexeme('#!/', TokenType.SCRIPT_TAG); | 393 assertLexeme('#!/', TokenType.SCRIPT_TAG); |
| 394 assertLexeme('foo', TokenType.IDENTIFIER); | 394 assertLexeme('foo', TokenType.IDENTIFIER); |
| 395 assertLexeme('"foo"', TokenType.STRING); | 395 assertLexeme('"foo"', TokenType.STRING); |
| 396 } | 396 } |
| 397 } | 397 } |
| OLD | NEW |