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

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

Issue 12543003: Use limited JavaStringBuilder implementation instead of Dart StringBuffer. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Tweak JavaStringBuilder. Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
1 // This code was auto-generated, is not intended to be edited, and is subject to 1 // This code was auto-generated, is not intended to be edited, and is subject to
2 // significant change. Please see the README file for more information. 2 // significant change. Please see the README file for more information.
3 3
4 library engine.scanner_test; 4 library engine.scanner_test;
5 5
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'package:analyzer-experimental/src/generated/java_core.dart'; 7 import 'package:analyzer-experimental/src/generated/java_core.dart';
8 import 'package:analyzer-experimental/src/generated/java_engine.dart'; 8 import 'package:analyzer-experimental/src/generated/java_engine.dart';
9 import 'package:analyzer-experimental/src/generated/java_junit.dart'; 9 import 'package:analyzer-experimental/src/generated/java_junit.dart';
10 import 'package:analyzer-experimental/src/generated/source.dart'; 10 import 'package:analyzer-experimental/src/generated/source.dart';
(...skipping 1409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1420 /** 1420 /**
1421 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction 1421 * Instances of the class {@code TokenStreamValidator} are used to validate the correct construction
1422 * of a stream of tokens. 1422 * of a stream of tokens.
1423 */ 1423 */
1424 class TokenStreamValidator { 1424 class TokenStreamValidator {
1425 /** 1425 /**
1426 * Validate that the stream of tokens that starts with the given token is corr ect. 1426 * Validate that the stream of tokens that starts with the given token is corr ect.
1427 * @param token the first token in the stream of tokens to be validated 1427 * @param token the first token in the stream of tokens to be validated
1428 */ 1428 */
1429 void validate(Token token) { 1429 void validate(Token token) {
1430 StringBuffer builder = new StringBuffer(); 1430 JavaStringBuilder builder = new JavaStringBuilder();
1431 validateStream(builder, token); 1431 validateStream(builder, token);
1432 if (builder.length > 0) { 1432 if (builder.length > 0) {
1433 JUnitTestCase.fail(builder.toString()); 1433 JUnitTestCase.fail(builder.toString());
1434 } 1434 }
1435 } 1435 }
1436 void validateStream(StringBuffer builder, Token token) { 1436 void validateStream(JavaStringBuilder builder, Token token) {
1437 if (token == null) { 1437 if (token == null) {
1438 return; 1438 return;
1439 } 1439 }
1440 Token previousToken = null; 1440 Token previousToken = null;
1441 int previousEnd = -1; 1441 int previousEnd = -1;
1442 Token currentToken = token; 1442 Token currentToken = token;
1443 while (currentToken != null && currentToken.type != TokenType.EOF) { 1443 while (currentToken != null && currentToken.type != TokenType.EOF) {
1444 validateStream(builder, currentToken.precedingComments); 1444 validateStream(builder, currentToken.precedingComments);
1445 TokenType type28 = currentToken.type; 1445 TokenType type28 = currentToken.type;
1446 if (identical(type28, TokenType.OPEN_CURLY_BRACKET) || identical(type28, T okenType.OPEN_PAREN) || identical(type28, TokenType.OPEN_SQUARE_BRACKET) || iden tical(type28, TokenType.STRING_INTERPOLATION_EXPRESSION)) { 1446 if (identical(type28, TokenType.OPEN_CURLY_BRACKET) || identical(type28, T okenType.OPEN_PAREN) || identical(type28, TokenType.OPEN_SQUARE_BRACKET) || iden tical(type28, TokenType.STRING_INTERPOLATION_EXPRESSION)) {
1447 if (currentToken is! BeginToken) { 1447 if (currentToken is! BeginToken) {
1448 builder.write("\r\nExpected BeginToken, found "); 1448 builder.append("\r\nExpected BeginToken, found ");
1449 builder.write(currentToken.runtimeType.toString()); 1449 builder.append(currentToken.runtimeType.toString());
1450 builder.write(" "); 1450 builder.append(" ");
1451 writeToken(builder, currentToken); 1451 writeToken(builder, currentToken);
1452 } 1452 }
1453 } 1453 }
1454 int currentStart = currentToken.offset; 1454 int currentStart = currentToken.offset;
1455 int currentLength = currentToken.length; 1455 int currentLength = currentToken.length;
1456 int currentEnd = currentStart + currentLength - 1; 1456 int currentEnd = currentStart + currentLength - 1;
1457 if (currentStart <= previousEnd) { 1457 if (currentStart <= previousEnd) {
1458 builder.write("\r\nInvalid token sequence: "); 1458 builder.append("\r\nInvalid token sequence: ");
1459 writeToken(builder, previousToken); 1459 writeToken(builder, previousToken);
1460 builder.write(" followed by "); 1460 builder.append(" followed by ");
1461 writeToken(builder, currentToken); 1461 writeToken(builder, currentToken);
1462 } 1462 }
1463 previousEnd = currentEnd; 1463 previousEnd = currentEnd;
1464 previousToken = currentToken; 1464 previousToken = currentToken;
1465 currentToken = currentToken.next; 1465 currentToken = currentToken.next;
1466 } 1466 }
1467 } 1467 }
1468 void writeToken(StringBuffer builder, Token token) { 1468 void writeToken(JavaStringBuilder builder, Token token) {
1469 builder.write("["); 1469 builder.append("[");
1470 builder.write(token.type); 1470 builder.append(token.type);
1471 builder.write(", '"); 1471 builder.append(", '");
1472 builder.write(token.lexeme); 1472 builder.append(token.lexeme);
1473 builder.write("', "); 1473 builder.append("', ");
1474 builder.write(token.offset); 1474 builder.append(token.offset);
1475 builder.write(", "); 1475 builder.append(", ");
1476 builder.write(token.length); 1476 builder.append(token.length);
1477 builder.write("]"); 1477 builder.append("]");
1478 } 1478 }
1479 } 1479 }
1480 abstract class AbstractScannerTest extends JUnitTestCase { 1480 abstract class AbstractScannerTest extends JUnitTestCase {
1481 void test_ampersand() { 1481 void test_ampersand() {
1482 assertToken(TokenType.AMPERSAND, "&"); 1482 assertToken(TokenType.AMPERSAND, "&");
1483 } 1483 }
1484 void test_ampersand_ampersand() { 1484 void test_ampersand_ampersand() {
1485 assertToken(TokenType.AMPERSAND_AMPERSAND, "&&"); 1485 assertToken(TokenType.AMPERSAND_AMPERSAND, "&&");
1486 } 1486 }
1487 void test_ampersand_eq() { 1487 void test_ampersand_eq() {
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
2054 listener.assertNoErrors(); 2054 listener.assertNoErrors();
2055 return token; 2055 return token;
2056 } 2056 }
2057 } 2057 }
2058 main() { 2058 main() {
2059 CharBufferScannerTest.dartSuite(); 2059 CharBufferScannerTest.dartSuite();
2060 KeywordStateTest.dartSuite(); 2060 KeywordStateTest.dartSuite();
2061 StringScannerTest.dartSuite(); 2061 StringScannerTest.dartSuite();
2062 TokenTypeTest.dartSuite(); 2062 TokenTypeTest.dartSuite();
2063 } 2063 }
OLDNEW
« no previous file with comments | « pkg/analyzer-experimental/test/generated/parser_test.dart ('k') | pkg/analyzer-experimental/test/generated/test_support.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698