| 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/precedence.dart'; | 5 import 'package:front_end/src/fasta/scanner/precedence.dart'; |
| 6 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; | 6 import 'package:front_end/src/fasta/scanner/string_scanner.dart'; |
| 7 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; | 7 import 'package:front_end/src/fasta/scanner/token.dart' as fasta; |
| 8 import 'package:front_end/src/scanner/token.dart'; | 8 import 'package:front_end/src/scanner/token.dart'; |
| 9 import 'package:test/test.dart'; | 9 import 'package:test/test.dart'; |
| 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; | 10 import 'package:test_reflective_loader/test_reflective_loader.dart'; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 var token = scanner.tokenize(); | 105 var token = scanner.tokenize(); |
| 106 check(source, token); | 106 check(source, token); |
| 107 } | 107 } |
| 108 | 108 |
| 109 for (PrecedenceInfo info in PrecedenceInfo.all) { | 109 for (PrecedenceInfo info in PrecedenceInfo.all) { |
| 110 assertLexeme(info.value); | 110 assertLexeme(info.value); |
| 111 } | 111 } |
| 112 for (TokenType tt in allTokenTypes) { | 112 for (TokenType tt in allTokenTypes) { |
| 113 assertLexeme(tt.lexeme); | 113 assertLexeme(tt.lexeme); |
| 114 } | 114 } |
| 115 assertLexeme('1.0'); // DOUBLE |
| 116 assertLexeme('0xA'); // HEXADECIMAL |
| 117 assertLexeme('1'); // INT |
| 118 assertLexeme('var'); // KEYWORD |
| 119 assertLexeme('#!/'); // SCRIPT_TAG |
| 120 assertLexeme('"foo"'); // STRING |
| 115 if (includeLazyAssignmentOperators) { | 121 if (includeLazyAssignmentOperators) { |
| 116 assertLexeme('&&='); | 122 assertLexeme('&&='); |
| 117 assertLexeme('||='); | 123 assertLexeme('||='); |
| 118 } | 124 } |
| 119 } | 125 } |
| 120 | 126 |
| 121 void test_isOperator() { | 127 void test_isOperator() { |
| 122 var operatorLexemes = new Set<String>.from(const [ | 128 var operatorLexemes = new Set<String>.from(const [ |
| 123 '&', | 129 '&', |
| 124 '&&', | 130 '&&', |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 1: const <String>['=', '*=', '/=', '+=', '-=', '&=', '^='], | 454 1: const <String>['=', '*=', '/=', '+=', '-=', '&=', '^='], |
| 449 }; | 455 }; |
| 450 precedenceTable.forEach((precedence, lexemes) { | 456 precedenceTable.forEach((precedence, lexemes) { |
| 451 for (String source in lexemes) { | 457 for (String source in lexemes) { |
| 452 var scanner = new StringScanner(source, includeComments: true); | 458 var scanner = new StringScanner(source, includeComments: true); |
| 453 var token = scanner.tokenize(); | 459 var token = scanner.tokenize(); |
| 454 expect(token.type.precedence, precedence, reason: source); | 460 expect(token.type.precedence, precedence, reason: source); |
| 455 } | 461 } |
| 456 }); | 462 }); |
| 457 } | 463 } |
| 464 |
| 465 void test_identity() { |
| 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) { |
| 485 var scanner = new StringScanner(source, includeComments: true); |
| 486 var token = scanner.tokenize(); |
| 487 expect(token.type, same(tt), reason: source); |
| 488 } |
| 489 |
| 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); |
| 503 assertLexeme('0xA', TokenType.HEXADECIMAL); |
| 504 assertLexeme('1', TokenType.INT); |
| 505 assertLexeme('var', TokenType.KEYWORD); |
| 506 assertLexeme('#!/', TokenType.SCRIPT_TAG); |
| 507 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 } |
| 458 } | 514 } |
| OLD | NEW |