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