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

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

Issue 2199323002: Initial implementation for lazy compound assignment operators (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 4 years, 4 months 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
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 analyzer.test.generated.scanner_test; 5 library analyzer.test.generated.scanner_test;
6 6
7 import 'package:analyzer/dart/ast/token.dart'; 7 import 'package:analyzer/dart/ast/token.dart';
8 import 'package:analyzer/src/dart/ast/token.dart'; 8 import 'package:analyzer/src/dart/ast/token.dart';
9 import 'package:analyzer/src/dart/scanner/reader.dart'; 9 import 'package:analyzer/src/dart/scanner/reader.dart';
10 import 'package:analyzer/src/dart/scanner/scanner.dart'; 10 import 'package:analyzer/src/dart/scanner/scanner.dart';
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 } 185 }
186 186
187 void test_ampersand() { 187 void test_ampersand() {
188 _assertToken(TokenType.AMPERSAND, "&"); 188 _assertToken(TokenType.AMPERSAND, "&");
189 } 189 }
190 190
191 void test_ampersand_ampersand() { 191 void test_ampersand_ampersand() {
192 _assertToken(TokenType.AMPERSAND_AMPERSAND, "&&"); 192 _assertToken(TokenType.AMPERSAND_AMPERSAND, "&&");
193 } 193 }
194 194
195 void test_ampersand_ampersand_eq() {
196 _assertToken(TokenType.AMPERSAND_AMPERSAND_EQ, "&&=",
197 lazyAssignmentOperators: true);
198 }
199
195 void test_ampersand_eq() { 200 void test_ampersand_eq() {
196 _assertToken(TokenType.AMPERSAND_EQ, "&="); 201 _assertToken(TokenType.AMPERSAND_EQ, "&=");
197 } 202 }
198 203
199 void test_at() { 204 void test_at() {
200 _assertToken(TokenType.AT, "@"); 205 _assertToken(TokenType.AT, "@");
201 } 206 }
202 207
203 void test_backping() { 208 void test_backping() {
204 _assertToken(TokenType.BACKPING, "`"); 209 _assertToken(TokenType.BACKPING, "`");
(...skipping 12 matching lines...) Expand all
217 } 222 }
218 223
219 void test_bar() { 224 void test_bar() {
220 _assertToken(TokenType.BAR, "|"); 225 _assertToken(TokenType.BAR, "|");
221 } 226 }
222 227
223 void test_bar_bar() { 228 void test_bar_bar() {
224 _assertToken(TokenType.BAR_BAR, "||"); 229 _assertToken(TokenType.BAR_BAR, "||");
225 } 230 }
226 231
232 void test_bar_bar_eq() {
233 _assertToken(TokenType.BAR_BAR_EQ, "||=", lazyAssignmentOperators: true);
234 }
235
227 void test_bar_eq() { 236 void test_bar_eq() {
228 _assertToken(TokenType.BAR_EQ, "|="); 237 _assertToken(TokenType.BAR_EQ, "|=");
229 } 238 }
230 239
231 void test_caret() { 240 void test_caret() {
232 _assertToken(TokenType.CARET, "^"); 241 _assertToken(TokenType.CARET, "^");
233 } 242 }
234 243
235 void test_caret_eq() { 244 void test_caret_eq() {
236 _assertToken(TokenType.CARET_EQ, "^="); 245 _assertToken(TokenType.CARET_EQ, "^=");
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 reason: 'Line number in location $i'); 1179 reason: 'Line number in location $i');
1171 expect(location.columnNumber, expectedLocation._columnNumber, 1180 expect(location.columnNumber, expectedLocation._columnNumber,
1172 reason: 'Column number in location $i'); 1181 reason: 'Column number in location $i');
1173 } 1182 }
1174 } 1183 }
1175 1184
1176 /** 1185 /**
1177 * Assert that the token scanned from the given [source] has the 1186 * Assert that the token scanned from the given [source] has the
1178 * [expectedType]. 1187 * [expectedType].
1179 */ 1188 */
1180 Token _assertToken(TokenType expectedType, String source) { 1189 Token _assertToken(TokenType expectedType, String source,
1181 Token originalToken = _scan(source); 1190 {bool lazyAssignmentOperators: false}) {
1191 Token originalToken =
1192 _scan(source, lazyAssignmentOperators: lazyAssignmentOperators);
1182 expect(originalToken, isNotNull); 1193 expect(originalToken, isNotNull);
1183 expect(originalToken.type, expectedType); 1194 expect(originalToken.type, expectedType);
1184 expect(originalToken.offset, 0); 1195 expect(originalToken.offset, 0);
1185 expect(originalToken.length, source.length); 1196 expect(originalToken.length, source.length);
1186 expect(originalToken.lexeme, source); 1197 expect(originalToken.lexeme, source);
1187 if (expectedType == TokenType.SCRIPT_TAG) { 1198 if (expectedType == TokenType.SCRIPT_TAG) {
1188 // Adding space before the script tag is not allowed, and adding text at 1199 // Adding space before the script tag is not allowed, and adding text at
1189 // the end changes nothing. 1200 // the end changes nothing.
1190 return originalToken; 1201 return originalToken;
1191 } else if (expectedType == TokenType.SINGLE_LINE_COMMENT) { 1202 } else if (expectedType == TokenType.SINGLE_LINE_COMMENT) {
1192 // Adding space to an end-of-line comment changes the comment. 1203 // Adding space to an end-of-line comment changes the comment.
1193 Token tokenWithSpaces = _scan(" $source"); 1204 Token tokenWithSpaces =
1205 _scan(" $source", lazyAssignmentOperators: lazyAssignmentOperators);
1194 expect(tokenWithSpaces, isNotNull); 1206 expect(tokenWithSpaces, isNotNull);
1195 expect(tokenWithSpaces.type, expectedType); 1207 expect(tokenWithSpaces.type, expectedType);
1196 expect(tokenWithSpaces.offset, 1); 1208 expect(tokenWithSpaces.offset, 1);
1197 expect(tokenWithSpaces.length, source.length); 1209 expect(tokenWithSpaces.length, source.length);
1198 expect(tokenWithSpaces.lexeme, source); 1210 expect(tokenWithSpaces.lexeme, source);
1199 return originalToken; 1211 return originalToken;
1200 } else if (expectedType == TokenType.INT || 1212 } else if (expectedType == TokenType.INT ||
1201 expectedType == TokenType.DOUBLE) { 1213 expectedType == TokenType.DOUBLE) {
1202 Token tokenWithLowerD = _scan("${source}d"); 1214 Token tokenWithLowerD =
1215 _scan("${source}d", lazyAssignmentOperators: lazyAssignmentOperators);
1203 expect(tokenWithLowerD, isNotNull); 1216 expect(tokenWithLowerD, isNotNull);
1204 expect(tokenWithLowerD.type, expectedType); 1217 expect(tokenWithLowerD.type, expectedType);
1205 expect(tokenWithLowerD.offset, 0); 1218 expect(tokenWithLowerD.offset, 0);
1206 expect(tokenWithLowerD.length, source.length); 1219 expect(tokenWithLowerD.length, source.length);
1207 expect(tokenWithLowerD.lexeme, source); 1220 expect(tokenWithLowerD.lexeme, source);
1208 Token tokenWithUpperD = _scan("${source}D"); 1221 Token tokenWithUpperD =
1222 _scan("${source}D", lazyAssignmentOperators: lazyAssignmentOperators);
1209 expect(tokenWithUpperD, isNotNull); 1223 expect(tokenWithUpperD, isNotNull);
1210 expect(tokenWithUpperD.type, expectedType); 1224 expect(tokenWithUpperD.type, expectedType);
1211 expect(tokenWithUpperD.offset, 0); 1225 expect(tokenWithUpperD.offset, 0);
1212 expect(tokenWithUpperD.length, source.length); 1226 expect(tokenWithUpperD.length, source.length);
1213 expect(tokenWithUpperD.lexeme, source); 1227 expect(tokenWithUpperD.lexeme, source);
1214 } 1228 }
1215 Token tokenWithSpaces = _scan(" $source "); 1229 Token tokenWithSpaces =
1230 _scan(" $source ", lazyAssignmentOperators: lazyAssignmentOperators);
1216 expect(tokenWithSpaces, isNotNull); 1231 expect(tokenWithSpaces, isNotNull);
1217 expect(tokenWithSpaces.type, expectedType); 1232 expect(tokenWithSpaces.type, expectedType);
1218 expect(tokenWithSpaces.offset, 1); 1233 expect(tokenWithSpaces.offset, 1);
1219 expect(tokenWithSpaces.length, source.length); 1234 expect(tokenWithSpaces.length, source.length);
1220 expect(tokenWithSpaces.lexeme, source); 1235 expect(tokenWithSpaces.lexeme, source);
1221 expect(originalToken.next.type, TokenType.EOF); 1236 expect(originalToken.next.type, TokenType.EOF);
1222 return originalToken; 1237 return originalToken;
1223 } 1238 }
1224 1239
1225 /** 1240 /**
(...skipping 16 matching lines...) Expand all
1242 expect(token.length, expectedToken.length, 1257 expect(token.length, expectedToken.length,
1243 reason: "Wrong length for token $i"); 1258 reason: "Wrong length for token $i");
1244 expect(token.lexeme, expectedToken.lexeme, 1259 expect(token.lexeme, expectedToken.lexeme,
1245 reason: "Wrong lexeme for token $i"); 1260 reason: "Wrong lexeme for token $i");
1246 token = token.next; 1261 token = token.next;
1247 expect(token, isNotNull); 1262 expect(token, isNotNull);
1248 } 1263 }
1249 expect(token.type, TokenType.EOF); 1264 expect(token.type, TokenType.EOF);
1250 } 1265 }
1251 1266
1252 Token _scan(String source, {bool genericMethodComments: false}) { 1267 Token _scan(String source,
1268 {bool genericMethodComments: false,
1269 bool lazyAssignmentOperators: false}) {
1253 GatheringErrorListener listener = new GatheringErrorListener(); 1270 GatheringErrorListener listener = new GatheringErrorListener();
1254 Token token = _scanWithListener(source, listener, 1271 Token token = _scanWithListener(source, listener,
1255 genericMethodComments: genericMethodComments); 1272 genericMethodComments: genericMethodComments,
1273 lazyAssignmentOperators: lazyAssignmentOperators);
1256 listener.assertNoErrors(); 1274 listener.assertNoErrors();
1257 return token; 1275 return token;
1258 } 1276 }
1259 1277
1260 Token _scanWithListener(String source, GatheringErrorListener listener, 1278 Token _scanWithListener(String source, GatheringErrorListener listener,
1261 {bool genericMethodComments: false}) { 1279 {bool genericMethodComments: false,
1280 bool lazyAssignmentOperators: false}) {
1262 Scanner scanner = 1281 Scanner scanner =
1263 new Scanner(null, new CharSequenceReader(source), listener); 1282 new Scanner(null, new CharSequenceReader(source), listener);
1264 if (genericMethodComments) { 1283 scanner.scanGenericMethodComments = genericMethodComments;
1265 scanner.scanGenericMethodComments = true; 1284 scanner.scanLazyAssignmentOperators = lazyAssignmentOperators;
1266 }
1267 Token result = scanner.tokenize(); 1285 Token result = scanner.tokenize();
1268 listener.setLineInfo(new TestSource(), scanner.lineStarts); 1286 listener.setLineInfo(new TestSource(), scanner.lineStarts);
1269 return result; 1287 return result;
1270 } 1288 }
1271 } 1289 }
1272 1290
1273 /** 1291 /**
1274 * An `ExpectedLocation` encodes information about the expected location of a 1292 * An `ExpectedLocation` encodes information about the expected location of a
1275 * given offset in source code. 1293 * given offset in source code.
1276 */ 1294 */
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue); 1429 expect(TokenType.LT_LT.isUserDefinableOperator, isTrue);
1412 expect(TokenType.MINUS.isUserDefinableOperator, isTrue); 1430 expect(TokenType.MINUS.isUserDefinableOperator, isTrue);
1413 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue); 1431 expect(TokenType.PERCENT.isUserDefinableOperator, isTrue);
1414 expect(TokenType.PLUS.isUserDefinableOperator, isTrue); 1432 expect(TokenType.PLUS.isUserDefinableOperator, isTrue);
1415 expect(TokenType.SLASH.isUserDefinableOperator, isTrue); 1433 expect(TokenType.SLASH.isUserDefinableOperator, isTrue);
1416 expect(TokenType.STAR.isUserDefinableOperator, isTrue); 1434 expect(TokenType.STAR.isUserDefinableOperator, isTrue);
1417 expect(TokenType.TILDE.isUserDefinableOperator, isTrue); 1435 expect(TokenType.TILDE.isUserDefinableOperator, isTrue);
1418 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue); 1436 expect(TokenType.TILDE_SLASH.isUserDefinableOperator, isTrue);
1419 } 1437 }
1420 } 1438 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698