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

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

Issue 679873002: Clone tokens when cloning ASTs for constants (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.utilities_test; 8 library engine.utilities_test;
9 9
10 import 'dart:collection'; 10 import 'dart:collection';
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 void test_visitAssignmentExpression() { 77 void test_visitAssignmentExpression() {
78 _assertClone( 78 _assertClone(
79 AstFactory.assignmentExpression( 79 AstFactory.assignmentExpression(
80 AstFactory.identifier3("a"), 80 AstFactory.identifier3("a"),
81 TokenType.EQ, 81 TokenType.EQ,
82 AstFactory.identifier3("b"))); 82 AstFactory.identifier3("b")));
83 } 83 }
84 84
85 void test_visitAwaitExpression() {
86 _assertClone(AstFactory.awaitExpression(AstFactory.identifier3("a")));
87 }
88
85 void test_visitBinaryExpression() { 89 void test_visitBinaryExpression() {
86 _assertClone( 90 _assertClone(
87 AstFactory.binaryExpression( 91 AstFactory.binaryExpression(
88 AstFactory.identifier3("a"), 92 AstFactory.identifier3("a"),
89 TokenType.PLUS, 93 TokenType.PLUS,
90 AstFactory.identifier3("b"))); 94 AstFactory.identifier3("b")));
91 } 95 }
92 96
93 void test_visitBlockFunctionBody() { 97 void test_visitBlockFunctionBody() {
94 _assertClone(AstFactory.blockFunctionBody2([])); 98 _assertClone(AstFactory.blockFunctionBody2([]));
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 [ 2028 [
2025 AstFactory.typeName4("A", []), 2029 AstFactory.typeName4("A", []),
2026 AstFactory.typeName4("B", []), 2030 AstFactory.typeName4("B", []),
2027 AstFactory.typeName4("C", [])])); 2031 AstFactory.typeName4("C", [])]));
2028 } 2032 }
2029 2033
2030 void test_visitWithClause_single() { 2034 void test_visitWithClause_single() {
2031 _assertClone(AstFactory.withClause([AstFactory.typeName4("A", [])])); 2035 _assertClone(AstFactory.withClause([AstFactory.typeName4("A", [])]));
2032 } 2036 }
2033 2037
2038 void test_visitYieldStatement() {
2039 _assertClone(AstFactory.yieldStatement(AstFactory.identifier3("A")));
2040 }
2041
2034 /** 2042 /**
2035 * Assert that an `AstCloner` will produce the expected ASt structure when vis iting the 2043 * Assert that an `AstCloner` will produce the expected AST structure when
2036 * given node. 2044 * visiting the given [node].
2037 * 2045 *
2038 * @param node the AST node being visited to produce the cloned structure 2046 * @param node the AST node being visited to produce the cloned structure
2039 * @throws AFE if the visitor does not produce the expected source for the giv en node 2047 * @throws AFE if the visitor does not produce the expected source for the giv en node
2040 */ 2048 */
2041 void _assertClone(AstNode node) { 2049 void _assertClone(AstNode node) {
2042 AstNode clone = node.accept(new AstCloner()); 2050 AstNode clone = node.accept(new AstCloner());
2043 if (!AstComparator.equalNodes(node, clone)) { 2051 AstCloneComparator comparitor = new AstCloneComparator(false);
2052 if (!comparitor.isEqualNodes(node, clone)) {
2053 JUnitTestCase.fail("Failed to clone ${node.runtimeType.toString()}");
2054 }
2055
2056 clone = node.accept(new AstCloner(true));
2057 comparitor = new AstCloneComparator(true);
2058 if (!comparitor.isEqualNodes(node, clone)) {
2044 JUnitTestCase.fail("Failed to clone ${node.runtimeType.toString()}"); 2059 JUnitTestCase.fail("Failed to clone ${node.runtimeType.toString()}");
2045 } 2060 }
2046 } 2061 }
2047 } 2062 }
2048 2063
2064 class AstCloneComparator extends AstComparator {
2065 final bool expectTokensCopied;
2066
2067 AstCloneComparator(this.expectTokensCopied);
2068
2069 @override
2070 bool isEqualNodes(AstNode first, AstNode second) {
2071 if (first != null && identical(first, second)) {
2072 JUnitTestCase.fail('Failed to copy node: $first (${first.offset})');
2073 return false;
2074 }
2075 return super.isEqualNodes(first, second);
2076 }
2077
2078 @override
2079 bool isEqualTokens(Token first, Token second) {
2080 if (expectTokensCopied && first != null && identical(first, second)) {
2081 JUnitTestCase.fail('Failed to copy token: ${first.lexeme} (${first.offset} )');
2082 return false;
2083 }
2084 return super.isEqualTokens(first, second);
2085 }
2086 }
2087
2049 class BooleanArrayTest extends JUnitTestCase { 2088 class BooleanArrayTest extends JUnitTestCase {
2050 void test_get_negative() { 2089 void test_get_negative() {
2051 try { 2090 try {
2052 BooleanArray.get(0, -1); 2091 BooleanArray.get(0, -1);
2053 JUnitTestCase.fail("Expected "); 2092 JUnitTestCase.fail("Expected ");
2054 } on RangeError catch (exception) { 2093 } on RangeError catch (exception) {
2055 // Expected 2094 // Expected
2056 } 2095 }
2057 } 2096 }
2058 2097
(...skipping 3306 matching lines...) Expand 10 before | Expand all | Expand 10 after
5365 } 5404 }
5366 5405
5367 void test_get_added() { 5406 void test_get_added() {
5368 TokenMap tokenMap = new TokenMap(); 5407 TokenMap tokenMap = new TokenMap();
5369 Token key = TokenFactory.tokenFromType(TokenType.AT); 5408 Token key = TokenFactory.tokenFromType(TokenType.AT);
5370 Token value = TokenFactory.tokenFromType(TokenType.AT); 5409 Token value = TokenFactory.tokenFromType(TokenType.AT);
5371 tokenMap.put(key, value); 5410 tokenMap.put(key, value);
5372 JUnitTestCase.assertSame(value, tokenMap.get(key)); 5411 JUnitTestCase.assertSame(value, tokenMap.get(key));
5373 } 5412 }
5374 } 5413 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698