Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2035)

Side by Side Diff: pkg/analyzer/test/generated/scanner_test.dart

Issue 1434863003: initial generic method comment parsing (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: re-sort members Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 Scanner scanner = new Scanner( 257 Scanner scanner = new Scanner(
258 null, 258 null,
259 new CharSequenceReader("/* comment */ "), 259 new CharSequenceReader("/* comment */ "),
260 AnalysisErrorListener.NULL_LISTENER); 260 AnalysisErrorListener.NULL_LISTENER);
261 scanner.preserveComments = false; 261 scanner.preserveComments = false;
262 Token token = scanner.tokenize(); 262 Token token = scanner.tokenize();
263 expect(token, isNotNull); 263 expect(token, isNotNull);
264 expect(token.precedingComments, isNull); 264 expect(token.precedingComments, isNull);
265 } 265 }
266 266
267 void test_comment_generic_method_type_assign() {
268 _assertComment(TokenType.MULTI_LINE_COMMENT, "/*=comment*/");
269 _assertComment(TokenType.GENERIC_METHOD_TYPE_ASSIGN, "/*=comment*/",
270 genericMethodComments: true);
271 }
272
273 void test_comment_generic_method_type_list() {
274 _assertComment(TokenType.MULTI_LINE_COMMENT, "/*<comment>*/");
275 _assertComment(TokenType.GENERIC_METHOD_TYPE_LIST, "/*<comment>*/",
276 genericMethodComments: true);
277 }
278
267 void test_comment_multi() { 279 void test_comment_multi() {
268 _assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment */"); 280 _assertComment(TokenType.MULTI_LINE_COMMENT, "/* comment */");
269 } 281 }
270 282
271 void test_comment_multi_lineEnds() { 283 void test_comment_multi_lineEnds() {
272 String code = r''' 284 String code = r'''
273 /** 285 /**
274 * aa 286 * aa
275 * bbb 287 * bbb
276 * c 288 * c
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
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,
1064 {bool genericMethodComments: false}) {
1052 // 1065 //
1053 // Test without a trailing end-of-line marker 1066 // Test without a trailing end-of-line marker
1054 // 1067 //
1055 Token token = _scan(source); 1068 Token token = _scan(source, genericMethodComments: genericMethodComments);
1056 expect(token, isNotNull); 1069 expect(token, isNotNull);
1057 expect(token.type, TokenType.EOF); 1070 expect(token.type, TokenType.EOF);
1058 Token comment = token.precedingComments; 1071 Token comment = token.precedingComments;
1059 expect(comment, isNotNull); 1072 expect(comment, isNotNull);
1060 expect(comment.type, commentType); 1073 expect(comment.type, commentType);
1061 expect(comment.offset, 0); 1074 expect(comment.offset, 0);
1062 expect(comment.length, source.length); 1075 expect(comment.length, source.length);
1063 expect(comment.lexeme, source); 1076 expect(comment.lexeme, source);
1064 // 1077 //
1065 // Test with a trailing end-of-line marker 1078 // Test with a trailing end-of-line marker
1066 // 1079 //
1067 token = _scan("$source\n"); 1080 token = _scan("$source\n", genericMethodComments: genericMethodComments);
1068 expect(token, isNotNull); 1081 expect(token, isNotNull);
1069 expect(token.type, TokenType.EOF); 1082 expect(token.type, TokenType.EOF);
1070 comment = token.precedingComments; 1083 comment = token.precedingComments;
1071 expect(comment, isNotNull); 1084 expect(comment, isNotNull);
1072 expect(comment.type, commentType); 1085 expect(comment.type, commentType);
1073 expect(comment.offset, 0); 1086 expect(comment.offset, 0);
1074 expect(comment.length, source.length); 1087 expect(comment.length, source.length);
1075 expect(comment.lexeme, source); 1088 expect(comment.lexeme, source);
1076 } 1089 }
1077 1090
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 expect(token.length, expectedToken.length, 1239 expect(token.length, expectedToken.length,
1227 reason: "Wrong length for token $i"); 1240 reason: "Wrong length for token $i");
1228 expect(token.lexeme, expectedToken.lexeme, 1241 expect(token.lexeme, expectedToken.lexeme,
1229 reason: "Wrong lexeme for token $i"); 1242 reason: "Wrong lexeme for token $i");
1230 token = token.next; 1243 token = token.next;
1231 expect(token, isNotNull); 1244 expect(token, isNotNull);
1232 } 1245 }
1233 expect(token.type, TokenType.EOF); 1246 expect(token.type, TokenType.EOF);
1234 } 1247 }
1235 1248
1236 Token _scan(String source) { 1249 Token _scan(String source, {bool genericMethodComments: false}) {
1237 GatheringErrorListener listener = new GatheringErrorListener(); 1250 GatheringErrorListener listener = new GatheringErrorListener();
1238 Token token = _scanWithListener(source, listener); 1251 Token token = _scanWithListener(source, listener,
1252 genericMethodComments: genericMethodComments);
1239 listener.assertNoErrors(); 1253 listener.assertNoErrors();
1240 return token; 1254 return token;
1241 } 1255 }
1242 1256
1243 Token _scanWithListener(String source, GatheringErrorListener listener) { 1257 Token _scanWithListener(String source, GatheringErrorListener listener,
1258 {bool genericMethodComments: false}) {
1244 Scanner scanner = 1259 Scanner scanner =
1245 new Scanner(null, new CharSequenceReader(source), listener); 1260 new Scanner(null, new CharSequenceReader(source), listener);
1261 if (genericMethodComments) {
1262 scanner.scanGenericMethodComments = true;
1263 }
1246 Token result = scanner.tokenize(); 1264 Token result = scanner.tokenize();
1247 listener.setLineInfo(new TestSource(), scanner.lineStarts); 1265 listener.setLineInfo(new TestSource(), scanner.lineStarts);
1248 return result; 1266 return result;
1249 } 1267 }
1250 } 1268 }
1251 1269
1252 /** 1270 /**
1253 * An `ExpectedLocation` encodes information about the expected location of a 1271 * An `ExpectedLocation` encodes information about the expected location of a
1254 * given offset in source code. 1272 * given offset in source code.
1255 */ 1273 */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1390 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); 1408 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue);
1391 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); 1409 expect(TokenType.MINUS.isUserDefinableOperator, isTrue);
1392 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); 1410 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue);
1393 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); 1411 expect(TokenType.PLUS.isUserDefinableOperator, isTrue);
1394 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); 1412 expect(TokenType.SLASH.isUserDefinableOperator, isTrue);
1395 expect(TokenType.STAR.isUserDefinableOperator, isTrue); 1413 expect(TokenType.STAR.isUserDefinableOperator, isTrue);
1396 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); 1414 expect(TokenType.TILDE.isUserDefinableOperator, isTrue);
1397 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); 1415 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue);
1398 } 1416 }
1399 } 1417 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/parser_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698