| 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 16 matching lines...) Expand all Loading... |
| 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 assert() {} | 33 assert() {} |
| 34 '''; | 34 '''; |
| 35 | 35 |
| 36 testDart2Dart(String src, [void continuation(String s)]) { | 36 testDart2Dart(String src, [void continuation(String s)]) { |
| 37 // If continuation is not provided, check that source string remains the same. |
| 38 if (continuation === null) { |
| 39 continuation = (s) { Expect.equals(src, s); }; |
| 40 } |
| 41 testDart2DartWithLibrary(src, '', continuation); |
| 42 } |
| 43 |
| 44 /** |
| 45 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 46 */ |
| 47 testDart2DartWithLibrary(String srcMain, String srcLibrary, [void continuation(S
tring s)]) { |
| 37 fileUri(path) => new Uri(scheme: 'file', path: path); | 48 fileUri(path) => new Uri(scheme: 'file', path: path); |
| 38 | 49 |
| 39 final scriptUri = fileUri('script.dart'); | 50 final scriptUri = fileUri('script.dart'); |
| 51 final libUri = fileUri('mylib.dart'); |
| 40 | 52 |
| 41 provider(uri) { | 53 provider(uri) { |
| 42 if (uri == scriptUri) return new Future.immediate(src); | 54 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 55 if (uri.toString() == libUri.toString()) return new Future.immediate(srcLibr
ary); |
| 43 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 56 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 44 return new Future.immediate(''); | 57 return new Future.immediate(''); |
| 45 } | 58 } |
| 46 | 59 |
| 47 handler(uri, begin, end, message, kind) { | 60 handler(uri, begin, end, message, kind) { |
| 48 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 61 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 49 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 62 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 50 } | 63 } |
| 51 } | 64 } |
| 52 | 65 |
| 53 // If continuation is not provided, check that source string remains the same. | |
| 54 if (continuation == null) { | |
| 55 continuation = (s) => Expect.equals(src, s); | |
| 56 } | |
| 57 compile( | 66 compile( |
| 58 scriptUri, | 67 scriptUri, |
| 59 fileUri('libraryRoot'), | 68 fileUri('libraryRoot'), |
| 60 fileUri('packageRoot'), | 69 fileUri('packageRoot'), |
| 61 provider, | 70 provider, |
| 62 handler, | 71 handler, |
| 63 const ['--output-type=dart', '--unparse-validation']).then(continuation); | 72 const ['--output-type=dart', '--unparse-validation']).then(continuation); |
| 64 } | 73 } |
| 65 | 74 |
| 66 testGenericTypes() { | 75 testGenericTypes() { |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 testDart2Dart('main(){new A.fromFoo(5);}' | 196 testDart2Dart('main(){new A.fromFoo(5);}' |
| 188 'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}'); | 197 'class A{A(this.f);A.fromFoo(foo):this("f");final String f;}'); |
| 189 // Now even more complicated, with interface and default factory. | 198 // Now even more complicated, with interface and default factory. |
| 190 testDart2Dart('main(){new A.fromFoo(5); new I.fromFoo();}' | 199 testDart2Dart('main(){new A.fromFoo(5); new I.fromFoo();}' |
| 191 'class IFactory{factory I.fromFoo()=> new A(5);}' | 200 'class IFactory{factory I.fromFoo()=> new A(5);}' |
| 192 'interface I default IFactory{I.fromFoo();}' | 201 'interface I default IFactory{I.fromFoo();}' |
| 193 'class A implements I{A(this.f);A.fromFoo(foo):this("f");' | 202 'class A implements I{A(this.f);A.fromFoo(foo):this("f");' |
| 194 'final String f;}'); | 203 'final String f;}'); |
| 195 } | 204 } |
| 196 | 205 |
| 206 testConflictLibraryClassRename() { |
| 207 var librarySrc = ''' |
| 208 #library('mylib'); |
| 209 |
| 210 topfoo() {} |
| 211 |
| 212 class A { |
| 213 foo(){} |
| 214 } |
| 215 '''; |
| 216 var mainSrc = ''' |
| 217 #import('mylib.dart', prefix: 'mylib'); |
| 218 |
| 219 |
| 220 topfoo() {var x = 5;} |
| 221 |
| 222 class A{ |
| 223 num foo() {} |
| 224 A.fromFoo() {} |
| 225 mylib.A myliba; |
| 226 List<A> mylist; |
| 227 } |
| 228 |
| 229 mylib.A getA() => null; |
| 230 |
| 231 main() { |
| 232 var a = new mylib.A(); |
| 233 a.foo(); |
| 234 var b = new A.fromFoo(); |
| 235 b.foo(); |
| 236 var GREATVAR = b.myliba; |
| 237 b.mylist; |
| 238 a = getA(); |
| 239 topfoo(); |
| 240 mylib.topfoo(); |
| 241 } |
| 242 '''; |
| 243 var expectedResult = 'topfoo(){}_topfoo(){var x=5;}A getA()=> null;' |
| 244 'main(){var a=new A(); a.foo(); var b=new _A.fromFoo(); b.foo(); ' |
| 245 'var GREATVAR=b.myliba; b.mylist; a=getA(); _topfoo(); topfoo();}' |
| 246 'class _A{_A.fromFoo(){}List<List> mylist;num foo(){}A myliba;}' |
| 247 'class A{foo(){}}'; |
| 248 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 249 (String result) { Expect.equals(expectedResult, result); }); |
| 250 } |
| 251 |
| 197 main() { | 252 main() { |
| 198 testGenericTypes(); | 253 testGenericTypes(); |
| 199 testForLoop(); | 254 testForLoop(); |
| 200 testEmptyList(); | 255 testEmptyList(); |
| 201 testClosure(); | 256 testClosure(); |
| 202 testIndexedOperatorDecl(); | 257 testIndexedOperatorDecl(); |
| 203 testNativeMethods(); | 258 testNativeMethods(); |
| 204 testPrefixIncrements(); | 259 testPrefixIncrements(); |
| 205 testConstModifier(); | 260 testConstModifier(); |
| 206 testSimpleFileUnparse(); | 261 testSimpleFileUnparse(); |
| 207 testSimpleObjectInstantiation(); | 262 testSimpleObjectInstantiation(); |
| 208 testSimpleTopLevelClass(); | 263 testSimpleTopLevelClass(); |
| 209 testClassWithSynthesizedConstructor(); | 264 testClassWithSynthesizedConstructor(); |
| 210 testClassWithMethod(); | 265 testClassWithMethod(); |
| 211 testVariableDefinitions(); | 266 testVariableDefinitions(); |
| 212 testGetSet(); | 267 testGetSet(); |
| 213 testFactoryConstructor(); | 268 testFactoryConstructor(); |
| 214 testTopLevelField(); | 269 testTopLevelField(); |
| 270 testConflictLibraryClassRename(); |
| 215 } | 271 } |
| OLD | NEW |