| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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 library engine.scanner_test; | 5 library engine.scanner_test; |
| 6 | 6 |
| 7 import 'package:analyzer/src/generated/error.dart'; | 7 import 'package:analyzer/src/generated/error.dart'; |
| 8 import 'package:analyzer/src/generated/scanner.dart'; | 8 import 'package:analyzer/src/generated/scanner.dart'; |
| 9 import 'package:analyzer/src/generated/source.dart'; | 9 import 'package:analyzer/src/generated/source.dart'; |
| 10 import 'package:unittest/unittest.dart'; | 10 import 'package:unittest/unittest.dart'; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 163 } else { | 163 } else { |
| 164 // keyword.substring(0, keyword.length() - 1) | 164 // keyword.substring(0, keyword.length() - 1) |
| 165 expect(state, isNotNull); | 165 expect(state, isNotNull); |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 } | 168 } |
| 169 } | 169 } |
| 170 | 170 |
| 171 @reflectiveTest | 171 @reflectiveTest |
| 172 class ScannerTest { | 172 class ScannerTest { |
| 173 /** | |
| 174 * If non-null, this value is used to override the default value of | |
| 175 * [Scanner.enableNullAwareOperators] before scanning. | |
| 176 */ | |
| 177 bool _enableNullAwareOperators; | |
| 178 | |
| 179 void fail_incomplete_string_interpolation() { | 173 void fail_incomplete_string_interpolation() { |
| 180 // https://code.google.com/p/dart/issues/detail?id=18073 | 174 // https://code.google.com/p/dart/issues/detail?id=18073 |
| 181 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, | 175 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 9, |
| 182 "\"foo \${bar", [ | 176 "\"foo \${bar", [ |
| 183 new StringToken(TokenType.STRING, "\"foo ", 0), | 177 new StringToken(TokenType.STRING, "\"foo ", 0), |
| 184 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5), | 178 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 5), |
| 185 new StringToken(TokenType.IDENTIFIER, "bar", 7) | 179 new StringToken(TokenType.IDENTIFIER, "bar", 7) |
| 186 ]); | 180 ]); |
| 187 } | 181 } |
| 188 | 182 |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 720 | 714 |
| 721 void test_plus_plus() { | 715 void test_plus_plus() { |
| 722 _assertToken(TokenType.PLUS_PLUS, "++"); | 716 _assertToken(TokenType.PLUS_PLUS, "++"); |
| 723 } | 717 } |
| 724 | 718 |
| 725 void test_question() { | 719 void test_question() { |
| 726 _assertToken(TokenType.QUESTION, "?"); | 720 _assertToken(TokenType.QUESTION, "?"); |
| 727 } | 721 } |
| 728 | 722 |
| 729 void test_question_dot() { | 723 void test_question_dot() { |
| 730 _enableNullAwareOperators = true; | |
| 731 _assertToken(TokenType.QUESTION_PERIOD, "?."); | 724 _assertToken(TokenType.QUESTION_PERIOD, "?."); |
| 732 } | 725 } |
| 733 | 726 |
| 734 void test_question_question() { | 727 void test_question_question() { |
| 735 _enableNullAwareOperators = true; | |
| 736 _assertToken(TokenType.QUESTION_QUESTION, "??"); | 728 _assertToken(TokenType.QUESTION_QUESTION, "??"); |
| 737 } | 729 } |
| 738 | 730 |
| 739 void test_question_question_eq() { | 731 void test_question_question_eq() { |
| 740 _enableNullAwareOperators = true; | |
| 741 _assertToken(TokenType.QUESTION_QUESTION_EQ, "??="); | 732 _assertToken(TokenType.QUESTION_QUESTION_EQ, "??="); |
| 742 } | 733 } |
| 743 | 734 |
| 744 void test_scriptTag_withArgs() { | 735 void test_scriptTag_withArgs() { |
| 745 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); | 736 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart -debug"); |
| 746 } | 737 } |
| 747 | 738 |
| 748 void test_scriptTag_withoutSpace() { | 739 void test_scriptTag_withoutSpace() { |
| 749 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); | 740 _assertToken(TokenType.SCRIPT_TAG, "#!/bin/dart"); |
| 750 } | 741 } |
| (...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1222 Token _scan(String source) { | 1213 Token _scan(String source) { |
| 1223 GatheringErrorListener listener = new GatheringErrorListener(); | 1214 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1224 Token token = _scanWithListener(source, listener); | 1215 Token token = _scanWithListener(source, listener); |
| 1225 listener.assertNoErrors(); | 1216 listener.assertNoErrors(); |
| 1226 return token; | 1217 return token; |
| 1227 } | 1218 } |
| 1228 | 1219 |
| 1229 Token _scanWithListener(String source, GatheringErrorListener listener) { | 1220 Token _scanWithListener(String source, GatheringErrorListener listener) { |
| 1230 Scanner scanner = | 1221 Scanner scanner = |
| 1231 new Scanner(null, new CharSequenceReader(source), listener); | 1222 new Scanner(null, new CharSequenceReader(source), listener); |
| 1232 if (_enableNullAwareOperators != null) { | |
| 1233 scanner.enableNullAwareOperators = _enableNullAwareOperators; | |
| 1234 } | |
| 1235 Token result = scanner.tokenize(); | 1223 Token result = scanner.tokenize(); |
| 1236 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 1224 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 1237 return result; | 1225 return result; |
| 1238 } | 1226 } |
| 1239 } | 1227 } |
| 1240 | 1228 |
| 1241 /** | 1229 /** |
| 1242 * An `ExpectedLocation` encodes information about the expected location of a | 1230 * An `ExpectedLocation` encodes information about the expected location of a |
| 1243 * given offset in source code. | 1231 * given offset in source code. |
| 1244 */ | 1232 */ |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1379 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); | 1367 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); |
| 1380 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); | 1368 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); |
| 1381 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); | 1369 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); |
| 1382 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); | 1370 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); |
| 1383 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); | 1371 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); |
| 1384 expect(TokenType.STAR.isUserDefinableOperator, isTrue); | 1372 expect(TokenType.STAR.isUserDefinableOperator, isTrue); |
| 1385 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); | 1373 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); |
| 1386 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); | 1374 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); |
| 1387 } | 1375 } |
| 1388 } | 1376 } |
| OLD | NEW |