| 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('dart:uri'); | 5 #import('dart:uri'); |
| 6 #import('parser_helper.dart'); | 6 #import('parser_helper.dart'); |
| 7 #import("../../../lib/compiler/compiler.dart"); | 7 #import("../../../lib/compiler/compiler.dart"); |
| 8 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 8 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 9 | 9 |
| 10 testUnparse(String statement) { | 10 testUnparse(String statement) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 interface int extends num {} | 25 interface int extends num {} |
| 26 interface double extends num {} | 26 interface double extends num {} |
| 27 interface String {} | 27 interface String {} |
| 28 interface Function {} | 28 interface Function {} |
| 29 interface List {} | 29 interface List {} |
| 30 interface Closure {} | 30 interface Closure {} |
| 31 interface Dynamic {} | 31 interface Dynamic {} |
| 32 interface Null {} | 32 interface Null {} |
| 33 '''; | 33 '''; |
| 34 | 34 |
| 35 testDart2Dart(String src, void continuation(String s)) { | 35 testDart2Dart(String src, [void continuation(String s)]) { |
| 36 fileUri(path) => new Uri(scheme: 'file', path: path); | 36 fileUri(path) => new Uri(scheme: 'file', path: path); |
| 37 | 37 |
| 38 final scriptUri = fileUri('script.dart'); | 38 final scriptUri = fileUri('script.dart'); |
| 39 | 39 |
| 40 provider(uri) { | 40 provider(uri) { |
| 41 if (uri == scriptUri) return new Future.immediate(src); | 41 if (uri == scriptUri) return new Future.immediate(src); |
| 42 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 42 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 43 return new Future.immediate(''); | 43 return new Future.immediate(''); |
| 44 } | 44 } |
| 45 | 45 |
| 46 handler(uri, begin, end, message, kind) { | 46 handler(uri, begin, end, message, kind) { |
| 47 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 47 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 48 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 48 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 // If continuation is not provided, check that source string remains the same. |
| 53 if (continuation == null) { |
| 54 continuation = (s) => Expect.equals(src, s); |
| 55 } |
| 52 compile( | 56 compile( |
| 53 scriptUri, | 57 scriptUri, |
| 54 fileUri('libraryRoot'), | 58 fileUri('libraryRoot'), |
| 55 fileUri('packageRoot'), | 59 fileUri('packageRoot'), |
| 56 provider, | 60 provider, |
| 57 handler, | 61 handler, |
| 58 const ['--output-type=dart', '--unparse-validation']).then(continuation); | 62 const ['--output-type=dart', '--unparse-validation']).then(continuation); |
| 59 } | 63 } |
| 60 | 64 |
| 61 testGenericTypes() { | 65 testGenericTypes() { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 main() { | 116 main() { |
| 113 should_be_kept(); | 117 should_be_kept(); |
| 114 } | 118 } |
| 115 '''; | 119 '''; |
| 116 testDart2Dart(src, (String s) { | 120 testDart2Dart(src, (String s) { |
| 117 Expect.equals('should_be_kept(){}main(){should_be_kept();}', s); | 121 Expect.equals('should_be_kept(){}main(){should_be_kept();}', s); |
| 118 }); | 122 }); |
| 119 } | 123 } |
| 120 | 124 |
| 121 testTopLevelField() { | 125 testTopLevelField() { |
| 122 final src = 'final String x="asd";main(){x;}'; | 126 testDart2Dart('final String x="asd";main(){x;}'); |
| 123 testDart2Dart(src, (String s) => Expect.equals(src, s)); | |
| 124 } | 127 } |
| 125 | 128 |
| 126 testSimpleObjectInstantiation() { | 129 testSimpleObjectInstantiation() { |
| 127 testUnparse('main(){new Object();}'); | 130 testUnparse('main(){new Object();}'); |
| 128 } | 131 } |
| 129 | 132 |
| 130 testSimpleTopLevelClass() { | 133 testSimpleTopLevelClass() { |
| 131 final src = 'main(){new A();}class A{A(){}}'; | 134 testDart2Dart('main(){new A();}class A{A(){}}'); |
| 132 testDart2Dart(src, (String s) => Expect.equals(src, s)); | 135 } |
| 136 |
| 137 testClassWithSynthesizedConstructor() { |
| 138 testDart2Dart('main(){new A();}class A{}'); |
| 139 } |
| 140 |
| 141 testClassWithMethod() { |
| 142 testDart2Dart('main(){var a=new A(); a.foo();}class A{void foo(){}}'); |
| 133 } | 143 } |
| 134 | 144 |
| 135 main() { | 145 main() { |
| 136 testGenericTypes(); | 146 testGenericTypes(); |
| 137 testForLoop(); | 147 testForLoop(); |
| 138 testEmptyList(); | 148 testEmptyList(); |
| 139 testClosure(); | 149 testClosure(); |
| 140 testIndexedOperatorDecl(); | 150 testIndexedOperatorDecl(); |
| 141 testNativeMethods(); | 151 testNativeMethods(); |
| 142 testPrefixIncrements(); | 152 testPrefixIncrements(); |
| 143 testConstModifier(); | 153 testConstModifier(); |
| 144 testSimpleFileUnparse(); | 154 testSimpleFileUnparse(); |
| 145 testSimpleObjectInstantiation(); | 155 testSimpleObjectInstantiation(); |
| 146 testSimpleTopLevelClass(); | 156 testSimpleTopLevelClass(); |
| 157 testClassWithSynthesizedConstructor(); |
| 158 testClassWithMethod(); |
| 147 testTopLevelField(); | 159 testTopLevelField(); |
| 148 } | 160 } |
| OLD | NEW |