| 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 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 | 115 assertLexeme('1.0'); // DOUBLE |
| 116 assertLexeme('0xA'); // HEXADECIMAL | 116 assertLexeme('0xA'); // HEXADECIMAL |
| 117 assertLexeme('1'); // INT | 117 assertLexeme('1'); // INT |
| 118 assertLexeme('var'); // KEYWORD | 118 assertLexeme('var'); // KEYWORD |
| 119 assertLexeme('#!/'); // SCRIPT_TAG | 119 assertLexeme('#!/'); // SCRIPT_TAG |
| 120 assertLexeme('"foo"'); // STRING | 120 assertLexeme('"foo"'); // STRING |
| 121 assertLexeme('bar'); // IDENTIFIER |
| 121 if (includeLazyAssignmentOperators) { | 122 if (includeLazyAssignmentOperators) { |
| 122 assertLexeme('&&='); | 123 assertLexeme('&&='); |
| 123 assertLexeme('||='); | 124 assertLexeme('||='); |
| 124 } | 125 } |
| 125 } | 126 } |
| 126 | 127 |
| 127 void test_isOperator() { | 128 void test_isOperator() { |
| 128 var operatorLexemes = new Set<String>.from(const [ | 129 var operatorLexemes = new Set<String>.from(const [ |
| 129 '&', | 130 '&', |
| 130 '&&', | 131 '&&', |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 '<<', | 339 '<<', |
| 339 '-', | 340 '-', |
| 340 '%', | 341 '%', |
| 341 '+', | 342 '+', |
| 342 '/', | 343 '/', |
| 343 '*', | 344 '*', |
| 344 '~', | 345 '~', |
| 345 '~/', | 346 '~/', |
| 346 ]; | 347 ]; |
| 347 assertInfo((String source, fasta.Token token) { | 348 assertInfo((String source, fasta.Token token) { |
| 348 expect(token.type.isUserDefinableOperator, | 349 var userDefinable = userDefinableOperatorLexemes.contains(source); |
| 349 userDefinableOperatorLexemes.contains(source), | 350 expect(token.type.isUserDefinableOperator, userDefinable, reason: source); |
| 350 reason: source); | 351 expect(token.isUserDefinableOperator, userDefinable, reason: source); |
| 351 expect(token.isUserDefinableOperator, | 352 expect(fasta.isUserDefinableOperator(token.lexeme), userDefinable, |
| 352 userDefinableOperatorLexemes.contains(source), | |
| 353 reason: source); | 353 reason: source); |
| 354 }); | 354 }); |
| 355 } | 355 } |
| 356 | 356 |
| 357 void test_name() { | 357 void test_name() { |
| 358 void assertName(String source, String name, {int offset: 0}) { | 358 void assertName(String source, String name, {int offset: 0}) { |
| 359 if (source == null || source.isEmpty) return; | 359 if (source == null || source.isEmpty) return; |
| 360 var scanner = new StringScanner(source, includeComments: true); | 360 var scanner = new StringScanner(source, includeComments: true); |
| 361 var token = scanner.tokenize(); | 361 var token = scanner.tokenize(); |
| 362 while (token.offset < offset) { | 362 while (token.offset < offset) { |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 expect(INT_INFO, same(TokenType.INT)); | 497 expect(INT_INFO, same(TokenType.INT)); |
| 498 expect(KEYWORD_INFO, same(TokenType.KEYWORD)); | 498 expect(KEYWORD_INFO, same(TokenType.KEYWORD)); |
| 499 expect(SCRIPT_INFO, same(TokenType.SCRIPT_TAG)); | 499 expect(SCRIPT_INFO, same(TokenType.SCRIPT_TAG)); |
| 500 expect(STRING_INFO, same(TokenType.STRING)); | 500 expect(STRING_INFO, same(TokenType.STRING)); |
| 501 | 501 |
| 502 assertLexeme('1.0', TokenType.DOUBLE); | 502 assertLexeme('1.0', TokenType.DOUBLE); |
| 503 assertLexeme('0xA', TokenType.HEXADECIMAL); | 503 assertLexeme('0xA', TokenType.HEXADECIMAL); |
| 504 assertLexeme('1', TokenType.INT); | 504 assertLexeme('1', TokenType.INT); |
| 505 assertLexeme('var', TokenType.KEYWORD); | 505 assertLexeme('var', TokenType.KEYWORD); |
| 506 assertLexeme('#!/', TokenType.SCRIPT_TAG); | 506 assertLexeme('#!/', TokenType.SCRIPT_TAG); |
| 507 assertLexeme('"foo"',TokenType.STRING); | 507 assertLexeme('"foo"', TokenType.STRING); |
| 508 | 508 |
| 509 expect(STRING_INTERPOLATION_INFO, | 509 expect(STRING_INTERPOLATION_INFO, |
| 510 same(TokenType.STRING_INTERPOLATION_EXPRESSION)); | 510 same(TokenType.STRING_INTERPOLATION_EXPRESSION)); |
| 511 expect(STRING_INTERPOLATION_IDENTIFIER_INFO, | 511 expect(STRING_INTERPOLATION_IDENTIFIER_INFO, |
| 512 same(TokenType.STRING_INTERPOLATION_IDENTIFIER)); | 512 same(TokenType.STRING_INTERPOLATION_IDENTIFIER)); |
| 513 } | 513 } |
| 514 } | 514 } |
| OLD | NEW |