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

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

Issue 698563005: Support parsing of enums in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add unparser test. 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) 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/implementation/scanner/scannerlib.dart"; 6 import "package:compiler/implementation/scanner/scannerlib.dart";
7 import "package:compiler/implementation/tree/tree.dart"; 7 import "package:compiler/implementation/tree/tree.dart";
8 8
9 import "package:compiler/implementation/dart2jslib.dart" 9 import "package:compiler/implementation/dart2jslib.dart"
10 show DiagnosticListener, 10 show DiagnosticListener,
11 Script; 11 Script;
12 12
13 import "package:compiler/implementation/elements/elements.dart" 13 import "package:compiler/implementation/elements/elements.dart"
14 show CompilationUnitElement, 14 show CompilationUnitElement,
15 LibraryElement; 15 LibraryElement;
16 16
17 import "package:compiler/implementation/elements/modelx.dart" 17 import "package:compiler/implementation/elements/modelx.dart"
18 show CompilationUnitElementX, 18 show CompilationUnitElementX,
19 LibraryElementX; 19 LibraryElementX;
20 20
21 main() { 21 main() {
22 testClassDef(); 22 testClassDef();
23 testClass1Field(); 23 testClass1Field();
24 testClass2Fields(); 24 testClass2Fields();
25 testClass1Field1Method(); 25 testClass1Field1Method();
26 testClass1Field2Method(); 26 testClass1Field2Method();
27 testClassDefTypeParam(); 27 testClassDefTypeParam();
28 testEnumDef();
29 testEnum1Value();
30 testEnum2Value();
31 testEnum3Value();
32 testEnum3CommaValue();
28 } 33 }
29 34
30 testClassDef() { 35 testClassDef() {
31 compareCode('class T{}'); 36 compareCode('class T{}');
32 } 37 }
33 38
34 testClass1Field() { 39 testClass1Field() {
35 compareCode('class T{var x;}'); 40 compareCode('class T{var x;}');
36 } 41 }
37 42
38 testClass2Fields() { 43 testClass2Fields() {
39 compareCode('class T{var x;var y;}'); 44 compareCode('class T{var x;var y;}');
40 } 45 }
41 46
42 testClass1Field1Method() { 47 testClass1Field1Method() {
43 compareCode('class T{var x;m(){}}'); 48 compareCode('class T{var x;m(){}}');
44 } 49 }
45 50
46 testClass1Field2Method() { 51 testClass1Field2Method() {
47 compareCode('class T{a(){}b(){}}'); 52 compareCode('class T{a(){}b(){}}');
48 } 53 }
49 54
50 testClassDefTypeParam() { 55 testClassDefTypeParam() {
51 compareCode('class T<X>{}'); 56 compareCode('class T<X>{}');
52 } 57 }
53 58
54 void compareCode(String code) { 59 testEnumDef() {
55 Expect.equals(code, doUnparse(code)); 60 compareCode('enum T {}');
56 } 61 }
57 62
63 testEnum1Value() {
64 compareCode('enum T {A}');
65 }
66
67 testEnum2Value() {
68 compareCode('enum T {A,B}');
69 }
70
71 testEnum3Value() {
72 compareCode('enum T {A,B,C}');
73 }
74
75 testEnum3CommaValue() {
76 compareCode('enum T {A,B,C,}', expectedResult: 'enum T {A,B,C}');
77 }
78
79 void compareCode(String code, {String expectedResult}) {
80 if (expectedResult == null) {
81 expectedResult = code;
82 }
83 Expect.equals(expectedResult, doUnparse(code));
84 }
85
86
58 String doUnparse(String source) { 87 String doUnparse(String source) {
59 MessageCollector diagnosticListener = new MessageCollector(); 88 MessageCollector diagnosticListener = new MessageCollector();
60 Script script = new Script(null, null, null); 89 Script script = new Script(null, null, null);
61 LibraryElement lib = new LibraryElementX(script); 90 LibraryElement lib = new LibraryElementX(script);
62 CompilationUnitElement element = new CompilationUnitElementX(script, lib); 91 CompilationUnitElement element = new CompilationUnitElementX(script, lib);
63 StringScanner scanner = new StringScanner.fromString(source); 92 StringScanner scanner = new StringScanner.fromString(source);
64 Token beginToken = scanner.tokenize(); 93 Token beginToken = scanner.tokenize();
65 NodeListener listener = new NodeListener(diagnosticListener, element); 94 NodeListener listener = new NodeListener(diagnosticListener, element);
66 Parser parser = new Parser(listener); 95 Parser parser = new Parser(listener);
67 parser.parseUnit(beginToken); 96 parser.parseUnit(beginToken);
(...skipping 11 matching lines...) Expand all
79 messages.add(reason); 108 messages.add(reason);
80 throw reason; 109 throw reason;
81 } 110 }
82 111
83 void log(message) { 112 void log(message) {
84 messages.add(message); 113 messages.add(message);
85 } 114 }
86 115
87 noSuchMethod(Invocation invocation) => throw 'unsupported operation'; 116 noSuchMethod(Invocation invocation) => throw 'unsupported operation';
88 } 117 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698