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

Side by Side Diff: tests/compiler/dart2js/unparser2_test.dart

Issue 1864433004: Repeats and fixes the changes landed & reverted as CL 1789553003. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Updates to external dependents Created 4 years, 8 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
« no previous file with comments | « tests/compiler/dart2js/type_checker_test.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import "package:compiler/src/parser/element_listener.dart"; 6 import "package:compiler/src/parser/element_listener.dart";
7 import "package:compiler/src/parser/node_listener.dart"; 7 import "package:compiler/src/parser/node_listener.dart";
8 import "package:compiler/src/parser/parser.dart"; 8 import "package:compiler/src/parser/parser.dart";
9 import "package:compiler/src/scanner/string_scanner.dart"; 9 import "package:compiler/src/scanner/string_scanner.dart";
10 import "package:compiler/src/tokens/token.dart"; 10 import "package:compiler/src/tokens/token.dart";
11 import "package:compiler/src/tree/tree.dart"; 11 import "package:compiler/src/tree/tree.dart";
12 12
13 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; 13 import "package:compiler/src/diagnostics/diagnostic_listener.dart";
14 import "package:compiler/src/elements/elements.dart" 14 import "package:compiler/src/elements/elements.dart"
15 show CompilationUnitElement, 15 show CompilationUnitElement,
16 LibraryElement; 16 LibraryElement;
17 import "package:compiler/src/elements/modelx.dart" 17 import "package:compiler/src/elements/modelx.dart"
18 show CompilationUnitElementX, 18 show CompilationUnitElementX,
19 LibraryElementX; 19 LibraryElementX;
20 import "package:compiler/src/script.dart"; 20 import "package:compiler/src/script.dart";
21 21
22 import "options_helper.dart";
23
22 main() { 24 main() {
23 testClassDef(); 25 testClassDef();
24 testClass1Field(); 26 testClass1Field();
25 testClass2Fields(); 27 testClass2Fields();
26 testClass1Field1Method(); 28 testClass1Field1Method();
27 testClass1Field2Method(); 29 testClass1Field2Method();
28 testClassDefTypeParam(); 30 testClassDefTypeParam();
29 testEnumDef(); 31 testEnumDef();
30 testEnum1Value(); 32 testEnum1Value();
31 testEnum2Value(); 33 testEnum2Value();
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 compareCode('enum T {A,B,C,}', expectedResult: 'enum T {A,B,C}'); 79 compareCode('enum T {A,B,C,}', expectedResult: 'enum T {A,B,C}');
78 } 80 }
79 81
80 void compareCode(String code, {String expectedResult}) { 82 void compareCode(String code, {String expectedResult}) {
81 if (expectedResult == null) { 83 if (expectedResult == null) {
82 expectedResult = code; 84 expectedResult = code;
83 } 85 }
84 Expect.equals(expectedResult, doUnparse(code)); 86 Expect.equals(expectedResult, doUnparse(code));
85 } 87 }
86 88
87
88 String doUnparse(String source) { 89 String doUnparse(String source) {
89 MessageCollector diagnosticListener = new MessageCollector(); 90 MessageCollector diagnosticListener = new MessageCollector();
90 Script script = new Script(null, null, null); 91 Script script = new Script(null, null, null);
91 LibraryElement lib = new LibraryElementX(script); 92 LibraryElement lib = new LibraryElementX(script);
92 CompilationUnitElement element = new CompilationUnitElementX(script, lib); 93 CompilationUnitElement element = new CompilationUnitElementX(script, lib);
93 StringScanner scanner = new StringScanner.fromString(source); 94 StringScanner scanner = new StringScanner.fromString(source);
94 Token beginToken = scanner.tokenize(); 95 Token beginToken = scanner.tokenize();
95 NodeListener listener = new NodeListener( 96 NodeListener listener = new NodeListener(
96 const ScannerOptions(), diagnosticListener, element); 97 const ScannerOptions(), diagnosticListener, element);
97 Parser parser = new Parser(listener); 98 Parser parser = new Parser(listener, new MockParserOptions());
98 parser.parseUnit(beginToken); 99 parser.parseUnit(beginToken);
99 Node node = listener.popNode(); 100 Node node = listener.popNode();
100 Expect.isTrue(listener.nodes.isEmpty); 101 Expect.isTrue(listener.nodes.isEmpty);
101 return unparse(node); 102 return unparse(node);
102 } 103 }
103 104
104 class MessageCollector extends DiagnosticReporter { 105 class MessageCollector extends DiagnosticReporter {
105 List<String> messages; 106 List<String> messages;
106 MessageCollector() { 107 MessageCollector() {
107 messages = []; 108 messages = [];
108 } 109 }
109 void internalError(node, String reason) { 110 void internalError(node, String reason) {
110 messages.add(reason); 111 messages.add(reason);
111 throw reason; 112 throw reason;
112 } 113 }
113 114
114 void log(message) { 115 void log(message) {
115 messages.add(message); 116 messages.add(message);
116 } 117 }
117 118
118 noSuchMethod(Invocation invocation) => throw 'unsupported operation'; 119 noSuchMethod(Invocation invocation) => throw 'unsupported operation';
119 } 120 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/type_checker_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698