Chromium Code Reviews| 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 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 295 | 295 |
| 296 void test_comment_nested() { | 296 void test_comment_nested() { |
| 297 _assertComment( | 297 _assertComment( |
| 298 TokenType.MULTI_LINE_COMMENT, "/* comment /* within a */ comment */"); | 298 TokenType.MULTI_LINE_COMMENT, "/* comment /* within a */ comment */"); |
| 299 } | 299 } |
| 300 | 300 |
| 301 void test_comment_single() { | 301 void test_comment_single() { |
| 302 _assertComment(TokenType.SINGLE_LINE_COMMENT, "// comment"); | 302 _assertComment(TokenType.SINGLE_LINE_COMMENT, "// comment"); |
| 303 } | 303 } |
| 304 | 304 |
| 305 void test_comment_generic_method_type_list() { | |
| 306 _assertComment(TokenType.MULTI_LINE_COMMENT, "/*<comment>*/"); | |
| 307 _assertComment(TokenType.GENERIC_METHOD_TYPE_LIST, "/*<comment>*/", | |
| 308 genericMethodComments: true); | |
| 309 } | |
| 310 | |
| 311 void test_comment_generic_method_type_assign() { | |
| 312 _assertComment(TokenType.MULTI_LINE_COMMENT, "/*=comment*/"); | |
| 313 _assertComment(TokenType.GENERIC_METHOD_TYPE_ASSIGN, "/*=comment*/", | |
| 314 genericMethodComments: true); | |
| 315 } | |
| 316 | |
| 305 void test_double_both_E() { | 317 void test_double_both_E() { |
| 306 _assertToken(TokenType.DOUBLE, "0.123E4"); | 318 _assertToken(TokenType.DOUBLE, "0.123E4"); |
| 307 } | 319 } |
| 308 | 320 |
| 309 void test_double_both_e() { | 321 void test_double_both_e() { |
| 310 _assertToken(TokenType.DOUBLE, "0.123e4"); | 322 _assertToken(TokenType.DOUBLE, "0.123e4"); |
| 311 } | 323 } |
| 312 | 324 |
| 313 void test_double_fraction() { | 325 void test_double_fraction() { |
| 314 _assertToken(TokenType.DOUBLE, ".123"); | 326 _assertToken(TokenType.DOUBLE, ".123"); |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1041 | 1053 |
| 1042 void test_tilde_slash_eq() { | 1054 void test_tilde_slash_eq() { |
| 1043 _assertToken(TokenType.TILDE_SLASH_EQ, "~/="); | 1055 _assertToken(TokenType.TILDE_SLASH_EQ, "~/="); |
| 1044 } | 1056 } |
| 1045 | 1057 |
| 1046 void test_unclosedPairInInterpolation() { | 1058 void test_unclosedPairInInterpolation() { |
| 1047 GatheringErrorListener listener = new GatheringErrorListener(); | 1059 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1048 _scanWithListener("'\${(}'", listener); | 1060 _scanWithListener("'\${(}'", listener); |
| 1049 } | 1061 } |
| 1050 | 1062 |
| 1051 void _assertComment(TokenType commentType, String source) { | 1063 void _assertComment(TokenType commentType, String source, {bool genericMethodC omments: false}) { |
|
Jennifer Messerly
2015/11/11 18:28:06
Just reran formatter & sort members on this file,
| |
| 1052 // | 1064 // |
| 1053 // Test without a trailing end-of-line marker | 1065 // Test without a trailing end-of-line marker |
| 1054 // | 1066 // |
| 1055 Token token = _scan(source); | 1067 Token token = _scan(source, genericMethodComments: genericMethodComments); |
| 1056 expect(token, isNotNull); | 1068 expect(token, isNotNull); |
| 1057 expect(token.type, TokenType.EOF); | 1069 expect(token.type, TokenType.EOF); |
| 1058 Token comment = token.precedingComments; | 1070 Token comment = token.precedingComments; |
| 1059 expect(comment, isNotNull); | 1071 expect(comment, isNotNull); |
| 1060 expect(comment.type, commentType); | 1072 expect(comment.type, commentType); |
| 1061 expect(comment.offset, 0); | 1073 expect(comment.offset, 0); |
| 1062 expect(comment.length, source.length); | 1074 expect(comment.length, source.length); |
| 1063 expect(comment.lexeme, source); | 1075 expect(comment.lexeme, source); |
| 1064 // | 1076 // |
| 1065 // Test with a trailing end-of-line marker | 1077 // Test with a trailing end-of-line marker |
| 1066 // | 1078 // |
| 1067 token = _scan("$source\n"); | 1079 token = _scan("$source\n", genericMethodComments: genericMethodComments); |
| 1068 expect(token, isNotNull); | 1080 expect(token, isNotNull); |
| 1069 expect(token.type, TokenType.EOF); | 1081 expect(token.type, TokenType.EOF); |
| 1070 comment = token.precedingComments; | 1082 comment = token.precedingComments; |
| 1071 expect(comment, isNotNull); | 1083 expect(comment, isNotNull); |
| 1072 expect(comment.type, commentType); | 1084 expect(comment.type, commentType); |
| 1073 expect(comment.offset, 0); | 1085 expect(comment.offset, 0); |
| 1074 expect(comment.length, source.length); | 1086 expect(comment.length, source.length); |
| 1075 expect(comment.lexeme, source); | 1087 expect(comment.lexeme, source); |
| 1076 } | 1088 } |
| 1077 | 1089 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1226 expect(token.length, expectedToken.length, | 1238 expect(token.length, expectedToken.length, |
| 1227 reason: "Wrong length for token $i"); | 1239 reason: "Wrong length for token $i"); |
| 1228 expect(token.lexeme, expectedToken.lexeme, | 1240 expect(token.lexeme, expectedToken.lexeme, |
| 1229 reason: "Wrong lexeme for token $i"); | 1241 reason: "Wrong lexeme for token $i"); |
| 1230 token = token.next; | 1242 token = token.next; |
| 1231 expect(token, isNotNull); | 1243 expect(token, isNotNull); |
| 1232 } | 1244 } |
| 1233 expect(token.type, TokenType.EOF); | 1245 expect(token.type, TokenType.EOF); |
| 1234 } | 1246 } |
| 1235 | 1247 |
| 1236 Token _scan(String source) { | 1248 Token _scan(String source, {bool genericMethodComments: false}) { |
| 1237 GatheringErrorListener listener = new GatheringErrorListener(); | 1249 GatheringErrorListener listener = new GatheringErrorListener(); |
| 1238 Token token = _scanWithListener(source, listener); | 1250 Token token = _scanWithListener(source, listener, |
| 1251 genericMethodComments: genericMethodComments); | |
| 1239 listener.assertNoErrors(); | 1252 listener.assertNoErrors(); |
| 1240 return token; | 1253 return token; |
| 1241 } | 1254 } |
| 1242 | 1255 |
| 1243 Token _scanWithListener(String source, GatheringErrorListener listener) { | 1256 Token _scanWithListener(String source, GatheringErrorListener listener, |
| 1257 {bool genericMethodComments: false}) { | |
| 1244 Scanner scanner = | 1258 Scanner scanner = |
| 1245 new Scanner(null, new CharSequenceReader(source), listener); | 1259 new Scanner(null, new CharSequenceReader(source), listener); |
| 1260 if (genericMethodComments) { | |
| 1261 scanner.parseGenericMethodComments = true; | |
| 1262 } | |
| 1246 Token result = scanner.tokenize(); | 1263 Token result = scanner.tokenize(); |
| 1247 listener.setLineInfo(new TestSource(), scanner.lineStarts); | 1264 listener.setLineInfo(new TestSource(), scanner.lineStarts); |
| 1248 return result; | 1265 return result; |
| 1249 } | 1266 } |
| 1250 } | 1267 } |
| 1251 | 1268 |
| 1252 /** | 1269 /** |
| 1253 * An `ExpectedLocation` encodes information about the expected location of a | 1270 * An `ExpectedLocation` encodes information about the expected location of a |
| 1254 * given offset in source code. | 1271 * given offset in source code. |
| 1255 */ | 1272 */ |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1390 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); | 1407 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); |
| 1391 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); | 1408 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); |
| 1392 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); | 1409 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); |
| 1393 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); | 1410 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); |
| 1394 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); | 1411 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); |
| 1395 expect(TokenType.STAR.isUserDefinableOperator, isTrue); | 1412 expect(TokenType.STAR.isUserDefinableOperator, isTrue); |
| 1396 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); | 1413 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); |
| 1397 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); | 1414 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); |
| 1398 } | 1415 } |
| 1399 } | 1416 } |
| OLD | NEW |