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

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

Issue 681003002: Replace ${name} with $name where possible. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up also implementation Created 6 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 | Annotate | Revision Log
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 // This code was auto-generated, is not intended to be edited, and is subject to 5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information. 6 // significant change. Please see the README file for more information.
7 7
8 library engine.scanner_test; 8 library engine.scanner_test;
9 9
10 import 'package:analyzer/src/generated/java_core.dart'; 10 import 'package:analyzer/src/generated/java_core.dart';
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 * 410 *
411 * @param prefix the unchanged text before the edit region 411 * @param prefix the unchanged text before the edit region
412 * @param removed the text that was removed from the original contents 412 * @param removed the text that was removed from the original contents
413 * @param added the text that was added to the modified contents 413 * @param added the text that was added to the modified contents
414 * @param suffix the unchanged text after the edit region 414 * @param suffix the unchanged text after the edit region
415 */ 415 */
416 void _scan(String prefix, String removed, String added, String suffix) { 416 void _scan(String prefix, String removed, String added, String suffix) {
417 // 417 //
418 // Compute the information needed to perform the test. 418 // Compute the information needed to perform the test.
419 // 419 //
420 String originalContents = "${prefix}${removed}${suffix}"; 420 String originalContents = "$prefix$removed$suffix";
421 String modifiedContents = "${prefix}${added}${suffix}"; 421 String modifiedContents = "$prefix$added$suffix";
422 int replaceStart = prefix.length; 422 int replaceStart = prefix.length;
423 Source source = new TestSource(); 423 Source source = new TestSource();
424 // 424 //
425 // Scan the original contents. 425 // Scan the original contents.
426 // 426 //
427 GatheringErrorListener originalListener = new GatheringErrorListener(); 427 GatheringErrorListener originalListener = new GatheringErrorListener();
428 Scanner originalScanner = new Scanner(source, new CharSequenceReader(origina lContents), originalListener); 428 Scanner originalScanner = new Scanner(source, new CharSequenceReader(origina lContents), originalListener);
429 _originalTokens = originalScanner.tokenize(); 429 _originalTokens = originalScanner.tokenize();
430 JUnitTestCase.assertNotNull(_originalTokens); 430 JUnitTestCase.assertNotNull(_originalTokens);
431 // 431 //
(...skipping 734 matching lines...) Expand 10 before | Expand all | Expand 10 after
1166 _assertToken(TokenType.STRING, "r'string'"); 1166 _assertToken(TokenType.STRING, "r'string'");
1167 } 1167 }
1168 1168
1169 void test_string_raw_simple_unterminated_eof() { 1169 void test_string_raw_simple_unterminated_eof() {
1170 String source = "r'string"; 1170 String source = "r'string";
1171 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, sourc e, [new StringToken(TokenType.STRING, source, 0)]); 1171 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, sourc e, [new StringToken(TokenType.STRING, source, 0)]);
1172 } 1172 }
1173 1173
1174 void test_string_raw_simple_unterminated_eol() { 1174 void test_string_raw_simple_unterminated_eol() {
1175 String source = "r'string"; 1175 String source = "r'string";
1176 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "${so urce}\n", [new StringToken(TokenType.STRING, source, 0)]); 1176 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 8, "$sou rce\n", [new StringToken(TokenType.STRING, source, 0)]);
1177 } 1177 }
1178 1178
1179 void test_string_simple_double() { 1179 void test_string_simple_double() {
1180 _assertToken(TokenType.STRING, "\"string\""); 1180 _assertToken(TokenType.STRING, "\"string\"");
1181 } 1181 }
1182 1182
1183 void test_string_simple_escapedDollar() { 1183 void test_string_simple_escapedDollar() {
1184 _assertToken(TokenType.STRING, "'a\\\$b'"); 1184 _assertToken(TokenType.STRING, "'a\\\$b'");
1185 } 1185 }
1186 1186
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 _assertToken(TokenType.STRING, "'string'"); 1260 _assertToken(TokenType.STRING, "'string'");
1261 } 1261 }
1262 1262
1263 void test_string_simple_unterminated_eof() { 1263 void test_string_simple_unterminated_eof() {
1264 String source = "'string"; 1264 String source = "'string";
1265 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, sourc e, [new StringToken(TokenType.STRING, source, 0)]); 1265 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, sourc e, [new StringToken(TokenType.STRING, source, 0)]);
1266 } 1266 }
1267 1267
1268 void test_string_simple_unterminated_eol() { 1268 void test_string_simple_unterminated_eol() {
1269 String source = "'string"; 1269 String source = "'string";
1270 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "${so urce}\r", [new StringToken(TokenType.STRING, source, 0)]); 1270 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 7, "$sou rce\r", [new StringToken(TokenType.STRING, source, 0)]);
1271 } 1271 }
1272 1272
1273 void test_string_simple_unterminated_interpolation_block() { 1273 void test_string_simple_unterminated_interpolation_block() {
1274 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${ name", [ 1274 _assertErrorAndTokens(ScannerErrorCode.UNTERMINATED_STRING_LITERAL, 6, "'\${ name", [
1275 new StringToken(TokenType.STRING, "'", 0), 1275 new StringToken(TokenType.STRING, "'", 0),
1276 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1), 1276 new StringToken(TokenType.STRING_INTERPOLATION_EXPRESSION, "\${", 1),
1277 new StringToken(TokenType.IDENTIFIER, "name", 3), 1277 new StringToken(TokenType.IDENTIFIER, "name", 3),
1278 new StringToken(TokenType.STRING, "", 7)]); 1278 new StringToken(TokenType.STRING, "", 7)]);
1279 } 1279 }
1280 1280
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1312 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 1312 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
1313 Token comment = token.precedingComments; 1313 Token comment = token.precedingComments;
1314 JUnitTestCase.assertNotNull(comment); 1314 JUnitTestCase.assertNotNull(comment);
1315 JUnitTestCase.assertEquals(commentType, comment.type); 1315 JUnitTestCase.assertEquals(commentType, comment.type);
1316 JUnitTestCase.assertEquals(0, comment.offset); 1316 JUnitTestCase.assertEquals(0, comment.offset);
1317 JUnitTestCase.assertEquals(source.length, comment.length); 1317 JUnitTestCase.assertEquals(source.length, comment.length);
1318 JUnitTestCase.assertEquals(source, comment.lexeme); 1318 JUnitTestCase.assertEquals(source, comment.lexeme);
1319 // 1319 //
1320 // Test with a trailing end-of-line marker 1320 // Test with a trailing end-of-line marker
1321 // 1321 //
1322 token = _scan("${source}\n"); 1322 token = _scan("$source\n");
1323 JUnitTestCase.assertNotNull(token); 1323 JUnitTestCase.assertNotNull(token);
1324 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 1324 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
1325 comment = token.precedingComments; 1325 comment = token.precedingComments;
1326 JUnitTestCase.assertNotNull(comment); 1326 JUnitTestCase.assertNotNull(comment);
1327 JUnitTestCase.assertEquals(commentType, comment.type); 1327 JUnitTestCase.assertEquals(commentType, comment.type);
1328 JUnitTestCase.assertEquals(0, comment.offset); 1328 JUnitTestCase.assertEquals(0, comment.offset);
1329 JUnitTestCase.assertEquals(source.length, comment.length); 1329 JUnitTestCase.assertEquals(source.length, comment.length);
1330 JUnitTestCase.assertEquals(source, comment.lexeme); 1330 JUnitTestCase.assertEquals(source, comment.lexeme);
1331 } 1331 }
1332 1332
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 void _assertKeywordToken(String source) { 1368 void _assertKeywordToken(String source) {
1369 Token token = _scan(source); 1369 Token token = _scan(source);
1370 JUnitTestCase.assertNotNull(token); 1370 JUnitTestCase.assertNotNull(token);
1371 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); 1371 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type);
1372 JUnitTestCase.assertEquals(0, token.offset); 1372 JUnitTestCase.assertEquals(0, token.offset);
1373 JUnitTestCase.assertEquals(source.length, token.length); 1373 JUnitTestCase.assertEquals(source.length, token.length);
1374 JUnitTestCase.assertEquals(source, token.lexeme); 1374 JUnitTestCase.assertEquals(source, token.lexeme);
1375 Object value = token.value(); 1375 Object value = token.value();
1376 JUnitTestCase.assertTrue(value is Keyword); 1376 JUnitTestCase.assertTrue(value is Keyword);
1377 JUnitTestCase.assertEquals(source, (value as Keyword).syntax); 1377 JUnitTestCase.assertEquals(source, (value as Keyword).syntax);
1378 token = _scan(" ${source} "); 1378 token = _scan(" $source ");
1379 JUnitTestCase.assertNotNull(token); 1379 JUnitTestCase.assertNotNull(token);
1380 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type); 1380 JUnitTestCase.assertEquals(TokenType.KEYWORD, token.type);
1381 JUnitTestCase.assertEquals(1, token.offset); 1381 JUnitTestCase.assertEquals(1, token.offset);
1382 JUnitTestCase.assertEquals(source.length, token.length); 1382 JUnitTestCase.assertEquals(source.length, token.length);
1383 JUnitTestCase.assertEquals(source, token.lexeme); 1383 JUnitTestCase.assertEquals(source, token.lexeme);
1384 value = token.value(); 1384 value = token.value();
1385 JUnitTestCase.assertTrue(value is Keyword); 1385 JUnitTestCase.assertTrue(value is Keyword);
1386 JUnitTestCase.assertEquals(source, (value as Keyword).syntax); 1386 JUnitTestCase.assertEquals(source, (value as Keyword).syntax);
1387 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type); 1387 JUnitTestCase.assertEquals(TokenType.EOF, token.next.type);
1388 } 1388 }
(...skipping 22 matching lines...) Expand all
1411 JUnitTestCase.assertNotNull(originalToken); 1411 JUnitTestCase.assertNotNull(originalToken);
1412 JUnitTestCase.assertEquals(expectedType, originalToken.type); 1412 JUnitTestCase.assertEquals(expectedType, originalToken.type);
1413 JUnitTestCase.assertEquals(0, originalToken.offset); 1413 JUnitTestCase.assertEquals(0, originalToken.offset);
1414 JUnitTestCase.assertEquals(source.length, originalToken.length); 1414 JUnitTestCase.assertEquals(source.length, originalToken.length);
1415 JUnitTestCase.assertEquals(source, originalToken.lexeme); 1415 JUnitTestCase.assertEquals(source, originalToken.lexeme);
1416 if (expectedType == TokenType.SCRIPT_TAG) { 1416 if (expectedType == TokenType.SCRIPT_TAG) {
1417 // Adding space before the script tag is not allowed, and adding text at t he end changes nothing. 1417 // Adding space before the script tag is not allowed, and adding text at t he end changes nothing.
1418 return originalToken; 1418 return originalToken;
1419 } else if (expectedType == TokenType.SINGLE_LINE_COMMENT) { 1419 } else if (expectedType == TokenType.SINGLE_LINE_COMMENT) {
1420 // Adding space to an end-of-line comment changes the comment. 1420 // Adding space to an end-of-line comment changes the comment.
1421 Token tokenWithSpaces = _scan(" ${source}"); 1421 Token tokenWithSpaces = _scan(" $source");
1422 JUnitTestCase.assertNotNull(tokenWithSpaces); 1422 JUnitTestCase.assertNotNull(tokenWithSpaces);
1423 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); 1423 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type);
1424 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); 1424 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset);
1425 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); 1425 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length);
1426 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); 1426 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme);
1427 return originalToken; 1427 return originalToken;
1428 } else if (expectedType == TokenType.INT || expectedType == TokenType.DOUBLE ) { 1428 } else if (expectedType == TokenType.INT || expectedType == TokenType.DOUBLE ) {
1429 Token tokenWithLowerD = _scan("${source}d"); 1429 Token tokenWithLowerD = _scan("${source}d");
1430 JUnitTestCase.assertNotNull(tokenWithLowerD); 1430 JUnitTestCase.assertNotNull(tokenWithLowerD);
1431 JUnitTestCase.assertEquals(expectedType, tokenWithLowerD.type); 1431 JUnitTestCase.assertEquals(expectedType, tokenWithLowerD.type);
1432 JUnitTestCase.assertEquals(0, tokenWithLowerD.offset); 1432 JUnitTestCase.assertEquals(0, tokenWithLowerD.offset);
1433 JUnitTestCase.assertEquals(source.length, tokenWithLowerD.length); 1433 JUnitTestCase.assertEquals(source.length, tokenWithLowerD.length);
1434 JUnitTestCase.assertEquals(source, tokenWithLowerD.lexeme); 1434 JUnitTestCase.assertEquals(source, tokenWithLowerD.lexeme);
1435 Token tokenWithUpperD = _scan("${source}D"); 1435 Token tokenWithUpperD = _scan("${source}D");
1436 JUnitTestCase.assertNotNull(tokenWithUpperD); 1436 JUnitTestCase.assertNotNull(tokenWithUpperD);
1437 JUnitTestCase.assertEquals(expectedType, tokenWithUpperD.type); 1437 JUnitTestCase.assertEquals(expectedType, tokenWithUpperD.type);
1438 JUnitTestCase.assertEquals(0, tokenWithUpperD.offset); 1438 JUnitTestCase.assertEquals(0, tokenWithUpperD.offset);
1439 JUnitTestCase.assertEquals(source.length, tokenWithUpperD.length); 1439 JUnitTestCase.assertEquals(source.length, tokenWithUpperD.length);
1440 JUnitTestCase.assertEquals(source, tokenWithUpperD.lexeme); 1440 JUnitTestCase.assertEquals(source, tokenWithUpperD.lexeme);
1441 } 1441 }
1442 Token tokenWithSpaces = _scan(" ${source} "); 1442 Token tokenWithSpaces = _scan(" $source ");
1443 JUnitTestCase.assertNotNull(tokenWithSpaces); 1443 JUnitTestCase.assertNotNull(tokenWithSpaces);
1444 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type); 1444 JUnitTestCase.assertEquals(expectedType, tokenWithSpaces.type);
1445 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset); 1445 JUnitTestCase.assertEquals(1, tokenWithSpaces.offset);
1446 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length); 1446 JUnitTestCase.assertEquals(source.length, tokenWithSpaces.length);
1447 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme); 1447 JUnitTestCase.assertEquals(source, tokenWithSpaces.lexeme);
1448 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type); 1448 JUnitTestCase.assertEquals(TokenType.EOF, originalToken.next.type);
1449 return originalToken; 1449 return originalToken;
1450 } 1450 }
1451 1451
1452 /** 1452 /**
1453 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given 1453 * Assert that when scanned the given source contains a sequence of tokens ide ntical to the given
1454 * tokens. 1454 * tokens.
1455 * 1455 *
1456 * @param source the source to be scanned 1456 * @param source the source to be scanned
1457 * @param expectedTokens the tokens that are expected to be in the source 1457 * @param expectedTokens the tokens that are expected to be in the source
1458 */ 1458 */
1459 void _assertTokens(String source, List<Token> expectedTokens) { 1459 void _assertTokens(String source, List<Token> expectedTokens) {
1460 Token token = _scan(source); 1460 Token token = _scan(source);
1461 _checkTokens(token, expectedTokens); 1461 _checkTokens(token, expectedTokens);
1462 } 1462 }
1463 1463
1464 void _checkTokens(Token firstToken, List<Token> expectedTokens) { 1464 void _checkTokens(Token firstToken, List<Token> expectedTokens) {
1465 JUnitTestCase.assertNotNull(firstToken); 1465 JUnitTestCase.assertNotNull(firstToken);
1466 Token token = firstToken; 1466 Token token = firstToken;
1467 for (int i = 0; i < expectedTokens.length; i++) { 1467 for (int i = 0; i < expectedTokens.length; i++) {
1468 Token expectedToken = expectedTokens[i]; 1468 Token expectedToken = expectedTokens[i];
1469 JUnitTestCase.assertEqualsMsg("Wrong type for token ${i}", expectedToken.t ype, token.type); 1469 JUnitTestCase.assertEqualsMsg("Wrong type for token $i", expectedToken.typ e, token.type);
1470 JUnitTestCase.assertEqualsMsg("Wrong offset for token ${i}", expectedToken .offset, token.offset); 1470 JUnitTestCase.assertEqualsMsg("Wrong offset for token $i", expectedToken.o ffset, token.offset);
1471 JUnitTestCase.assertEqualsMsg("Wrong length for token ${i}", expectedToken .length, token.length); 1471 JUnitTestCase.assertEqualsMsg("Wrong length for token $i", expectedToken.l ength, token.length);
1472 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token ${i}", expectedToken .lexeme, token.lexeme); 1472 JUnitTestCase.assertEqualsMsg("Wrong lexeme for token $i", expectedToken.l exeme, token.lexeme);
1473 token = token.next; 1473 token = token.next;
1474 JUnitTestCase.assertNotNull(token); 1474 JUnitTestCase.assertNotNull(token);
1475 } 1475 }
1476 JUnitTestCase.assertEquals(TokenType.EOF, token.type); 1476 JUnitTestCase.assertEquals(TokenType.EOF, token.type);
1477 } 1477 }
1478 1478
1479 Token _scan(String source) { 1479 Token _scan(String source) {
1480 GatheringErrorListener listener = new GatheringErrorListener(); 1480 GatheringErrorListener listener = new GatheringErrorListener();
1481 Token token = _scanWithListener(source, listener); 1481 Token token = _scanWithListener(source, listener);
1482 listener.assertNoErrors(); 1482 listener.assertNoErrors();
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 } 1637 }
1638 1638
1639 main() { 1639 main() {
1640 _ut.groupSep = ' | '; 1640 _ut.groupSep = ' | ';
1641 runReflectiveTests(CharSequenceReaderTest); 1641 runReflectiveTests(CharSequenceReaderTest);
1642 runReflectiveTests(IncrementalScannerTest); 1642 runReflectiveTests(IncrementalScannerTest);
1643 runReflectiveTests(KeywordStateTest); 1643 runReflectiveTests(KeywordStateTest);
1644 runReflectiveTests(ScannerTest); 1644 runReflectiveTests(ScannerTest);
1645 runReflectiveTests(TokenTypeTest); 1645 runReflectiveTests(TokenTypeTest);
1646 } 1646 }
OLDNEW
« no previous file with comments | « pkg/analyzer/test/generated/resolver_test.dart ('k') | pkg/analyzer/test/generated/test_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698