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

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

Issue 2647343003: Update dart2js unit tests to dart_parser and dart_scanner. (Closed)
Patch Set: Address review comments. Created 3 years, 10 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/scanner_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:dart_parser/dart_parser.dart";
9 import "package:compiler/src/scanner/string_scanner.dart"; 9 import "package:dart_scanner/dart_scanner.dart";
10 import "package:compiler/src/tokens/token.dart";
11 import "package:compiler/src/tree/tree.dart"; 10 import "package:compiler/src/tree/tree.dart";
12 11
13 import "package:compiler/src/diagnostics/diagnostic_listener.dart"; 12 import "package:compiler/src/diagnostics/diagnostic_listener.dart";
14 import "package:compiler/src/elements/elements.dart" 13 import "package:compiler/src/elements/elements.dart"
15 show CompilationUnitElement, LibraryElement; 14 show CompilationUnitElement, LibraryElement;
16 import "package:compiler/src/elements/modelx.dart" 15 import "package:compiler/src/elements/modelx.dart"
17 show CompilationUnitElementX, LibraryElementX; 16 show CompilationUnitElementX, LibraryElementX;
18 import "package:compiler/src/script.dart"; 17 import "package:compiler/src/script.dart";
19 18
20 import "options_helper.dart";
21
22 main() { 19 main() {
23 testClassDef(); 20 testClassDef();
24 testClass1Field(); 21 testClass1Field();
25 testClass2Fields(); 22 testClass2Fields();
26 testClass1Field1Method(); 23 testClass1Field1Method();
27 testClass1Field2Method(); 24 testClass1Field2Method();
28 testClassDefTypeParam(); 25 testClassDefTypeParam();
29 testEnumDef(); 26 testEnumDef();
30 testEnum1Value(); 27 testEnum1Value();
31 testEnum2Value(); 28 testEnum2Value();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 expectedResult = code; 79 expectedResult = code;
83 } 80 }
84 Expect.equals(expectedResult, doUnparse(code)); 81 Expect.equals(expectedResult, doUnparse(code));
85 } 82 }
86 83
87 String doUnparse(String source) { 84 String doUnparse(String source) {
88 MessageCollector diagnosticListener = new MessageCollector(); 85 MessageCollector diagnosticListener = new MessageCollector();
89 Script script = new Script(null, null, null); 86 Script script = new Script(null, null, null);
90 LibraryElement lib = new LibraryElementX(script); 87 LibraryElement lib = new LibraryElementX(script);
91 CompilationUnitElement element = new CompilationUnitElementX(script, lib); 88 CompilationUnitElement element = new CompilationUnitElementX(script, lib);
92 StringScanner scanner = new StringScanner.fromString(source); 89 StringScanner scanner = new StringScanner(source);
93 Token beginToken = scanner.tokenize(); 90 Token beginToken = scanner.tokenize();
94 NodeListener listener = 91 NodeListener listener =
95 new NodeListener(const ScannerOptions(), diagnosticListener, element); 92 new NodeListener(const ScannerOptions(), diagnosticListener, element);
96 Parser parser = new Parser(listener); 93 Parser parser = new Parser(listener);
97 parser.parseUnit(beginToken); 94 parser.parseUnit(beginToken);
98 Node node = listener.popNode(); 95 Node node = listener.popNode();
99 Expect.isTrue(listener.nodes.isEmpty); 96 Expect.isTrue(listener.nodes.isEmpty);
100 return unparse(node); 97 return unparse(node);
101 } 98 }
102 99
103 class MessageCollector extends DiagnosticReporter { 100 class MessageCollector extends DiagnosticReporter {
104 List<String> messages; 101 List<String> messages;
105 MessageCollector() { 102 MessageCollector() {
106 messages = []; 103 messages = [];
107 } 104 }
108 void internalError(node, String reason) { 105 void internalError(node, String reason) {
109 messages.add(reason); 106 messages.add(reason);
110 throw reason; 107 throw reason;
111 } 108 }
112 109
113 void log(message) { 110 void log(message) {
114 messages.add(message); 111 messages.add(message);
115 } 112 }
116 113
117 noSuchMethod(Invocation invocation) => throw 'unsupported operation'; 114 noSuchMethod(Invocation invocation) => throw 'unsupported operation';
118 } 115 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/scanner_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698