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

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

Issue 680863002: Remove JavaStringBuilder (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 1495 matching lines...) Expand 10 before | Expand all | Expand 10 after
1506 * Instances of the class `TokenStreamValidator` are used to validate the correc t construction 1506 * Instances of the class `TokenStreamValidator` are used to validate the correc t construction
1507 * of a stream of tokens. 1507 * of a stream of tokens.
1508 */ 1508 */
1509 class TokenStreamValidator { 1509 class TokenStreamValidator {
1510 /** 1510 /**
1511 * Validate that the stream of tokens that starts with the given token is corr ect. 1511 * Validate that the stream of tokens that starts with the given token is corr ect.
1512 * 1512 *
1513 * @param token the first token in the stream of tokens to be validated 1513 * @param token the first token in the stream of tokens to be validated
1514 */ 1514 */
1515 void validate(Token token) { 1515 void validate(Token token) {
1516 JavaStringBuilder builder = new JavaStringBuilder(); 1516 StringBuffer buffer = new StringBuffer();
1517 _validateStream(builder, token); 1517 _validateStream(buffer, token);
1518 if (builder.length > 0) { 1518 if (buffer.length > 0) {
1519 JUnitTestCase.fail(builder.toString()); 1519 JUnitTestCase.fail(buffer.toString());
1520 } 1520 }
1521 } 1521 }
1522 1522
1523 void _validateStream(JavaStringBuilder builder, Token token) { 1523 void _validateStream(StringBuffer buffer, Token token) {
1524 if (token == null) { 1524 if (token == null) {
1525 return; 1525 return;
1526 } 1526 }
1527 Token previousToken = null; 1527 Token previousToken = null;
1528 int previousEnd = -1; 1528 int previousEnd = -1;
1529 Token currentToken = token; 1529 Token currentToken = token;
1530 while (currentToken != null && currentToken.type != TokenType.EOF) { 1530 while (currentToken != null && currentToken.type != TokenType.EOF) {
1531 _validateStream(builder, currentToken.precedingComments); 1531 _validateStream(buffer, currentToken.precedingComments);
1532 TokenType type = currentToken.type; 1532 TokenType type = currentToken.type;
1533 if (type == TokenType.OPEN_CURLY_BRACKET || type == TokenType.OPEN_PAREN | | type == TokenType.OPEN_SQUARE_BRACKET || type == TokenType.STRING_INTERPOLATIO N_EXPRESSION) { 1533 if (type == TokenType.OPEN_CURLY_BRACKET || type == TokenType.OPEN_PAREN | | type == TokenType.OPEN_SQUARE_BRACKET || type == TokenType.STRING_INTERPOLATIO N_EXPRESSION) {
1534 if (currentToken is! BeginToken) { 1534 if (currentToken is! BeginToken) {
1535 builder.append("\r\nExpected BeginToken, found "); 1535 buffer.write("\r\nExpected BeginToken, found ");
1536 builder.append(currentToken.runtimeType.toString()); 1536 buffer.write(currentToken.runtimeType.toString());
1537 builder.append(" "); 1537 buffer.write(" ");
1538 _writeToken(builder, currentToken); 1538 _writeToken(buffer, currentToken);
1539 } 1539 }
1540 } 1540 }
1541 int currentStart = currentToken.offset; 1541 int currentStart = currentToken.offset;
1542 int currentLength = currentToken.length; 1542 int currentLength = currentToken.length;
1543 int currentEnd = currentStart + currentLength - 1; 1543 int currentEnd = currentStart + currentLength - 1;
1544 if (currentStart <= previousEnd) { 1544 if (currentStart <= previousEnd) {
1545 builder.append("\r\nInvalid token sequence: "); 1545 buffer.write("\r\nInvalid token sequence: ");
1546 _writeToken(builder, previousToken); 1546 _writeToken(buffer, previousToken);
1547 builder.append(" followed by "); 1547 buffer.write(" followed by ");
1548 _writeToken(builder, currentToken); 1548 _writeToken(buffer, currentToken);
1549 } 1549 }
1550 previousEnd = currentEnd; 1550 previousEnd = currentEnd;
1551 previousToken = currentToken; 1551 previousToken = currentToken;
1552 currentToken = currentToken.next; 1552 currentToken = currentToken.next;
1553 } 1553 }
1554 } 1554 }
1555 1555
1556 void _writeToken(JavaStringBuilder builder, Token token) { 1556 void _writeToken(StringBuffer buffer, Token token) {
1557 builder.append("["); 1557 buffer.write("[");
1558 builder.append(token.type); 1558 buffer.write(token.type);
1559 builder.append(", '"); 1559 buffer.write(", '");
1560 builder.append(token.lexeme); 1560 buffer.write(token.lexeme);
1561 builder.append("', "); 1561 buffer.write("', ");
1562 builder.append(token.offset); 1562 buffer.write(token.offset);
1563 builder.append(", "); 1563 buffer.write(", ");
1564 builder.append(token.length); 1564 buffer.write(token.length);
1565 builder.append("]"); 1565 buffer.write("]");
1566 } 1566 }
1567 } 1567 }
1568 1568
1569 class TokenTypeTest extends EngineTestCase { 1569 class TokenTypeTest extends EngineTestCase {
1570 void test_isOperator() { 1570 void test_isOperator() {
1571 JUnitTestCase.assertTrue(TokenType.AMPERSAND.isOperator); 1571 JUnitTestCase.assertTrue(TokenType.AMPERSAND.isOperator);
1572 JUnitTestCase.assertTrue(TokenType.AMPERSAND_AMPERSAND.isOperator); 1572 JUnitTestCase.assertTrue(TokenType.AMPERSAND_AMPERSAND.isOperator);
1573 JUnitTestCase.assertTrue(TokenType.AMPERSAND_EQ.isOperator); 1573 JUnitTestCase.assertTrue(TokenType.AMPERSAND_EQ.isOperator);
1574 JUnitTestCase.assertTrue(TokenType.BANG.isOperator); 1574 JUnitTestCase.assertTrue(TokenType.BANG.isOperator);
1575 JUnitTestCase.assertTrue(TokenType.BANG_EQ.isOperator); 1575 JUnitTestCase.assertTrue(TokenType.BANG_EQ.isOperator);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 } 1634 }
1635 1635
1636 main() { 1636 main() {
1637 _ut.groupSep = ' | '; 1637 _ut.groupSep = ' | ';
1638 runReflectiveTests(CharSequenceReaderTest); 1638 runReflectiveTests(CharSequenceReaderTest);
1639 runReflectiveTests(IncrementalScannerTest); 1639 runReflectiveTests(IncrementalScannerTest);
1640 runReflectiveTests(KeywordStateTest); 1640 runReflectiveTests(KeywordStateTest);
1641 runReflectiveTests(ScannerTest); 1641 runReflectiveTests(ScannerTest);
1642 runReflectiveTests(TokenTypeTest); 1642 runReflectiveTests(TokenTypeTest);
1643 } 1643 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698