| OLD | NEW |
| 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("../../../lib/compiler/implementation/scanner/scannerlib.dart"); | 5 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); |
| 6 #import("../../../lib/compiler/implementation/elements/elements.dart"); // only
need CompilationUnitElement | 6 #import("../../../lib/compiler/implementation/elements/elements.dart"); // only
need CompilationUnitElement |
| 7 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 7 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 8 #import("../../../lib/compiler/implementation/leg.dart"); // only need Diagnosti
cListener & Script | 8 #import("../../../lib/compiler/implementation/leg.dart"); // only need Diagnosti
cListener & Script |
| 9 | 9 |
| 10 // This is the number of spaces to trim from the test code. | |
| 11 // New tests should be indented this amount. | |
| 12 const int BUILT_IN_TEST_INDENTATION = 6; | |
| 13 | |
| 14 main() { | 10 main() { |
| 15 testClassDef(); | 11 testClassDef(); |
| 16 testClass1Field(); | 12 testClass1Field(); |
| 17 testClass2Fields(); | 13 testClass2Fields(); |
| 18 testClass1Field1Method(); | 14 testClass1Field1Method(); |
| 19 testClass1Field2Method(); | 15 testClass1Field2Method(); |
| 20 testClassDefTypeParam(); | 16 testClassDefTypeParam(); |
| 21 } | 17 } |
| 22 | 18 |
| 23 testClassDef() { | 19 testClassDef() { |
| 24 compareCode(''' | 20 compareCode('class T{}'); |
| 25 class T{} | |
| 26 ''', ''' | |
| 27 class T{ | |
| 28 } | |
| 29 '''); | |
| 30 } | 21 } |
| 31 | 22 |
| 32 testClass1Field() { | 23 testClass1Field() { |
| 33 compareCode(''' | 24 compareCode('class T{var x;}'); |
| 34 class T{var x;} | |
| 35 ''', ''' | |
| 36 class T{ | |
| 37 var x; | |
| 38 } | |
| 39 '''); | |
| 40 } | 25 } |
| 41 | 26 |
| 42 testClass2Fields() { | 27 testClass2Fields() { |
| 43 compareCode(''' | 28 compareCode('class T{var x;var y;}'); |
| 44 class T{var x; var y;} | |
| 45 ''', ''' | |
| 46 class T{ | |
| 47 var x; | |
| 48 var y; | |
| 49 } | |
| 50 '''); | |
| 51 } | 29 } |
| 52 | 30 |
| 53 testClass1Field1Method() { | 31 testClass1Field1Method() { |
| 54 compareCode(''' | 32 compareCode('class T{var x;m(){}}'); |
| 55 class T{var x;m(){}} | |
| 56 ''', ''' | |
| 57 class T{ | |
| 58 var x; | |
| 59 m(){} | |
| 60 } | |
| 61 '''); | |
| 62 } | 33 } |
| 63 | 34 |
| 64 testClass1Field2Method() { | 35 testClass1Field2Method() { |
| 65 compareCode(''' | 36 compareCode('class T{a(){}b(){}}'); |
| 66 class T{a(){}b(){}} | |
| 67 ''', ''' | |
| 68 class T{ | |
| 69 a(){} | |
| 70 b(){} | |
| 71 } | |
| 72 '''); | |
| 73 } | 37 } |
| 74 | 38 |
| 75 testClassDefTypeParam() { | 39 testClassDefTypeParam() { |
| 76 compareCode(''' | 40 compareCode('class T<X>{}'); |
| 77 class T<X>{} | |
| 78 ''', ''' | |
| 79 class T<X>{ | |
| 80 } | |
| 81 '''); | |
| 82 } | 41 } |
| 83 | 42 |
| 84 void compareCode(String original, String expected) { | 43 void compareCode(String code) { |
| 85 String unparsed = doUnparse(cleanUpLiteral(original)); | 44 Expect.equals(code, doUnparse(code)); |
| 86 Expect.equals(cleanUpLiteral(expected), unparsed); | |
| 87 } | |
| 88 | |
| 89 String cleanUpLiteral(String text) { | |
| 90 var lines = text.split('\n'); | |
| 91 for (var j = 0; j < lines.length; j++) { | |
| 92 if (lines[j].length > BUILT_IN_TEST_INDENTATION) { | |
| 93 lines[j] = lines[j].substring(BUILT_IN_TEST_INDENTATION, lines[j].length); | |
| 94 } else { | |
| 95 lines[j] = ''; | |
| 96 } | |
| 97 } | |
| 98 return Strings.join(lines, '\n'); | |
| 99 } | 45 } |
| 100 | 46 |
| 101 String doUnparse(String source) { | 47 String doUnparse(String source) { |
| 102 MessageCollector diagnosticListener = new MessageCollector(); | 48 MessageCollector diagnosticListener = new MessageCollector(); |
| 103 Script script = new Script(null, null); | 49 Script script = new Script(null, null); |
| 104 LibraryElement lib = new LibraryElement(script); | 50 LibraryElement lib = new LibraryElement(script); |
| 105 CompilationUnitElement element = new CompilationUnitElement(script, lib); | 51 CompilationUnitElement element = new CompilationUnitElement(script, lib); |
| 106 StringScanner scanner = new StringScanner(source); | 52 StringScanner scanner = new StringScanner(source); |
| 107 Token beginToken = scanner.tokenize(); | 53 Token beginToken = scanner.tokenize(); |
| 108 NodeListener listener = new NodeListener(diagnosticListener, element); | 54 NodeListener listener = new NodeListener(diagnosticListener, element); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 127 } | 73 } |
| 128 void internalErrorOnElement(Element element, String message) { | 74 void internalErrorOnElement(Element element, String message) { |
| 129 throw message; | 75 throw message; |
| 130 } | 76 } |
| 131 void internalError(String message, | 77 void internalError(String message, |
| 132 [Node node, Token token, Dynamic instruction, | 78 [Node node, Token token, Dynamic instruction, |
| 133 Element element]) { | 79 Element element]) { |
| 134 throw message; | 80 throw message; |
| 135 } | 81 } |
| 136 } | 82 } |
| OLD | NEW |