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('mock_compiler.dart'); | 7 #import('mock_compiler.dart'); |
8 #import("../../../lib/compiler/compiler.dart"); | 8 #import("../../../lib/compiler/compiler.dart"); |
9 #import("../../../lib/compiler/implementation/leg.dart", prefix:'leg'); | 9 #import("../../../lib/compiler/implementation/leg.dart", prefix:'leg'); |
10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); | 10 #import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart"); |
11 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 11 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
12 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 12 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
13 | 13 |
14 testUnparse(String statement) { | 14 testUnparse(String statement) { |
15 Node node = parseStatement(statement); | 15 Node node = parseStatement(statement); |
16 Expect.equals(statement, node.unparse()); | 16 Expect.equals(statement, node.unparse()); |
17 } | 17 } |
18 | 18 |
19 testUnparseMember(String member) { | 19 testUnparseMember(String member) { |
20 Node node = parseMember(member); | 20 Node node = parseMember(member); |
21 Expect.equals(member, node.unparse()); | 21 Expect.equals(member, node.unparse()); |
22 } | 22 } |
23 | 23 |
24 final coreLib = @''' | 24 const coreLib = @''' |
25 #library('corelib'); | 25 #library('corelib'); |
26 class Object {} | 26 class Object {} |
27 interface bool {} | 27 interface bool {} |
28 interface num {} | 28 interface num {} |
29 interface int extends num {} | 29 interface int extends num {} |
30 interface double extends num {} | 30 interface double extends num {} |
31 interface String {} | 31 interface String {} |
32 interface Function {} | 32 interface Function {} |
33 interface List {} | 33 interface List {} |
34 interface Closure {} | 34 interface Closure {} |
35 interface Dynamic {} | 35 interface Dynamic {} |
36 interface Null {} | 36 interface Null {} |
37 assert() {} | 37 assert() {} |
38 class Math { | 38 class Math { |
39 static double parseDouble(String s) => 1.0; | 39 static double parseDouble(String s) => 1.0; |
40 } | 40 } |
41 '''; | 41 '''; |
42 | 42 |
43 final ioLib = @''' | 43 const ioLib = @''' |
44 #library('io'); | 44 #library('io'); |
45 class Platform { | 45 class Platform { |
46 static int operatingSystem; | 46 static int operatingSystem; |
47 } | 47 } |
48 '''; | 48 '''; |
49 | 49 |
50 testDart2Dart(String src, [void continuation(String s), bool minify = false]) { | 50 testDart2Dart(String src, [void continuation(String s), bool minify = false]) { |
51 // If continuation is not provided, check that source string remains the same. | 51 // If continuation is not provided, check that source string remains the same. |
52 if (continuation === null) { | 52 if (continuation === null) { |
53 continuation = (s) { Expect.equals(src, s); }; | 53 continuation = (s) { Expect.equals(src, s); }; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 testExtendsImplements() { | 191 testExtendsImplements() { |
192 testDart2Dart('main(){new B<Object>();}' | 192 testDart2Dart('main(){new B<Object>();}' |
193 'class A<T>{}class B<T> extends A<T>{}'); | 193 'class A<T>{}class B<T> extends A<T>{}'); |
194 } | 194 } |
195 | 195 |
196 testVariableDefinitions() { | 196 testVariableDefinitions() { |
197 testDart2Dart('main(){final var x,y; final String s;}'); | 197 testDart2Dart('main(){final var x,y; final String s;}'); |
198 testDart2Dart('foo(f,g){}main(){foo(1,2);}'); | 198 testDart2Dart('foo(f,g){}main(){foo(1,2);}'); |
199 testDart2Dart('foo(f(arg)){}main(){foo(main);}'); | 199 testDart2Dart('foo(f(arg)){}main(){foo(main);}'); |
200 // A couple of static/finals inside a class. | 200 // A couple of static/finals inside a class. |
201 testDart2Dart('main(){A.a; A.b;}class A{static final String a="5";' | 201 testDart2Dart('main(){A.a; A.b;}class A{static const String a="5";' |
202 'static final String b="4";}'); | 202 'static const String b="4";}'); |
203 // Class member of typedef-ed function type. | 203 // Class member of typedef-ed function type. |
204 // Maybe typedef should be included in the result too, but it | 204 // Maybe typedef should be included in the result too, but it |
205 // works fine without it. | 205 // works fine without it. |
206 testDart2Dart( | 206 testDart2Dart( |
207 'typedef void foofunc(arg);main(){new A((arg){});}' | 207 'typedef void foofunc(arg);main(){new A((arg){});}' |
208 'class A{A(foofunc this.handler);final foofunc handler;}'); | 208 'class A{A(foofunc this.handler);final foofunc handler;}'); |
209 } | 209 } |
210 | 210 |
211 testGetSet() { | 211 testGetSet() { |
212 // Top-level get/set. | 212 // Top-level get/set. |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 | 244 |
245 globalfoo() {} | 245 globalfoo() {} |
246 var globalVar; | 246 var globalVar; |
247 var globalVarInitialized = 6, globalVarInitialized2 = 7; | 247 var globalVarInitialized = 6, globalVarInitialized2 = 7; |
248 | 248 |
249 class A { | 249 class A { |
250 A(){} | 250 A(){} |
251 A.fromFoo(){} | 251 A.fromFoo(){} |
252 static staticfoo(){} | 252 static staticfoo(){} |
253 foo(){} | 253 foo(){} |
254 static final field = 5; | 254 static const field = 5; |
255 } | 255 } |
256 '''; | 256 '''; |
257 var mainSrc = ''' | 257 var mainSrc = ''' |
258 #import("mylib.dart", prefix: "mylib"); | 258 #import("mylib.dart", prefix: "mylib"); |
259 | 259 |
260 globalfoo() {} | 260 globalfoo() {} |
261 var globalVar; | 261 var globalVar; |
262 var globalVarInitialized = 6, globalVarInitialized2 = 7; | 262 var globalVarInitialized = 6, globalVarInitialized2 = 7; |
263 | 263 |
264 class A { | 264 class A { |
265 A(){} | 265 A(){} |
266 A.fromFoo(){} | 266 A.fromFoo(){} |
267 static staticfoo(){} | 267 static staticfoo(){} |
268 foo(){} | 268 foo(){} |
269 static final field = 5; | 269 static const field = 5; |
270 } | 270 } |
271 | 271 |
272 main() { | 272 main() { |
273 globalVar; | 273 globalVar; |
274 globalVarInitialized; | 274 globalVarInitialized; |
275 globalVarInitialized2; | 275 globalVarInitialized2; |
276 globalfoo(); | 276 globalfoo(); |
277 A.field; | 277 A.field; |
278 A.staticfoo(); | 278 A.staticfoo(); |
279 new A(); | 279 new A(); |
280 new A.fromFoo(); | 280 new A.fromFoo(); |
281 new A().foo(); | 281 new A().foo(); |
282 | 282 |
283 mylib.globalVar; | 283 mylib.globalVar; |
284 mylib.globalVarInitialized; | 284 mylib.globalVarInitialized; |
285 mylib.globalVarInitialized2; | 285 mylib.globalVarInitialized2; |
286 mylib.globalfoo(); | 286 mylib.globalfoo(); |
287 mylib.A.field; | 287 mylib.A.field; |
288 mylib.A.staticfoo(); | 288 mylib.A.staticfoo(); |
289 new mylib.A(); | 289 new mylib.A(); |
290 new mylib.A.fromFoo(); | 290 new mylib.A.fromFoo(); |
291 new mylib.A().foo(); | 291 new mylib.A().foo(); |
292 } | 292 } |
293 '''; | 293 '''; |
294 var expectedResult = | 294 var expectedResult = |
295 'globalfoo(){}var globalVar;var globalVarInitialized=6,globalVarInitialize
d2=7;' | 295 'globalfoo(){}var globalVar;var globalVarInitialized=6,globalVarInitialize
d2=7;' |
296 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}static final field=5
;}' | 296 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}static const field=5
;}' |
297 'p_globalfoo(){}var p_globalVar;var p_globalVarInitialized=6,p_globalVarIn
itialized2=7;' | 297 'p_globalfoo(){}var p_globalVar;var p_globalVarInitialized=6,p_globalVarIn
itialized2=7;' |
298 'class p_A{p_A(){}p_A.fromFoo(){}static p_staticfoo(){}foo(){}static final
p_field=5;}' | 298 'class p_A{p_A(){}p_A.fromFoo(){}static p_staticfoo(){}foo(){}static const
p_field=5;}' |
299 'main(){p_globalVar; p_globalVarInitialized; p_globalVarInitialized2; p_gl
obalfoo();' | 299 'main(){p_globalVar; p_globalVarInitialized; p_globalVarInitialized2; p_gl
obalfoo();' |
300 ' p_A.p_field; p_A.p_staticfoo();' | 300 ' p_A.p_field; p_A.p_staticfoo();' |
301 ' new p_A(); new p_A.fromFoo(); new p_A().foo();' | 301 ' new p_A(); new p_A.fromFoo(); new p_A().foo();' |
302 ' globalVar; globalVarInitialized; globalVarInitialized2; globalfoo();' | 302 ' globalVar; globalVarInitialized; globalVarInitialized2; globalfoo();' |
303 ' A.field; A.staticfoo();' | 303 ' A.field; A.staticfoo();' |
304 ' new A(); new A.fromFoo(); new A().foo();}'; | 304 ' new A(); new A.fromFoo(); new A().foo();}'; |
305 testDart2DartWithLibrary(mainSrc, librarySrc, | 305 testDart2DartWithLibrary(mainSrc, librarySrc, |
306 (String result) { Expect.equals(expectedResult, result); }); | 306 (String result) { Expect.equals(expectedResult, result); }); |
307 } | 307 } |
308 | 308 |
309 testNoConflictSendsRename() { | 309 testNoConflictSendsRename() { |
310 // Various Send-s to current library and external library. Nothing should be | 310 // Various Send-s to current library and external library. Nothing should be |
311 // renamed here, only library prefixes must be cut. | 311 // renamed here, only library prefixes must be cut. |
312 var librarySrc = ''' | 312 var librarySrc = ''' |
313 #library("mylib.dart"); | 313 #library("mylib.dart"); |
314 | 314 |
315 globalfoo() {} | 315 globalfoo() {} |
316 | 316 |
317 class A { | 317 class A { |
318 A(){} | 318 A(){} |
319 A.fromFoo(){} | 319 A.fromFoo(){} |
320 static staticfoo(){} | 320 static staticfoo(){} |
321 foo(){} | 321 foo(){} |
322 static final field = 5; | 322 static const field = 5; |
323 } | 323 } |
324 '''; | 324 '''; |
325 var mainSrc = ''' | 325 var mainSrc = ''' |
326 #import("mylib.dart", prefix: "mylib"); | 326 #import("mylib.dart", prefix: "mylib"); |
327 | 327 |
328 myglobalfoo() {} | 328 myglobalfoo() {} |
329 | 329 |
330 class MyA { | 330 class MyA { |
331 MyA(){} | 331 MyA(){} |
332 MyA.myfromFoo(){} | 332 MyA.myfromFoo(){} |
333 static mystaticfoo(){} | 333 static mystaticfoo(){} |
334 myfoo(){} | 334 myfoo(){} |
335 static final myfield = 5; | 335 static const myfield = 5; |
336 } | 336 } |
337 | 337 |
338 main() { | 338 main() { |
339 myglobalfoo(); | 339 myglobalfoo(); |
340 MyA.myfield; | 340 MyA.myfield; |
341 MyA.mystaticfoo(); | 341 MyA.mystaticfoo(); |
342 new MyA(); | 342 new MyA(); |
343 new MyA.myfromFoo(); | 343 new MyA.myfromFoo(); |
344 new MyA().myfoo(); | 344 new MyA().myfoo(); |
345 | 345 |
346 mylib.globalfoo(); | 346 mylib.globalfoo(); |
347 mylib.A.field; | 347 mylib.A.field; |
348 mylib.A.staticfoo(); | 348 mylib.A.staticfoo(); |
349 new mylib.A(); | 349 new mylib.A(); |
350 new mylib.A.fromFoo(); | 350 new mylib.A.fromFoo(); |
351 new mylib.A().foo(); | 351 new mylib.A().foo(); |
352 } | 352 } |
353 '''; | 353 '''; |
354 var expectedResult = | 354 var expectedResult = |
355 'globalfoo(){}' | 355 'globalfoo(){}' |
356 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}static final field=5
;}' | 356 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}static const field=5
;}' |
357 'myglobalfoo(){}' | 357 'myglobalfoo(){}' |
358 'class MyA{MyA(){}MyA.myfromFoo(){}static mystaticfoo(){}myfoo(){}static f
inal myfield=5;}' | 358 'class MyA{MyA(){}MyA.myfromFoo(){}static mystaticfoo(){}myfoo(){}static c
onst myfield=5;}' |
359 'main(){myglobalfoo(); MyA.myfield; MyA.mystaticfoo(); new MyA();' | 359 'main(){myglobalfoo(); MyA.myfield; MyA.mystaticfoo(); new MyA();' |
360 ' new MyA.myfromFoo(); new MyA().myfoo(); globalfoo(); A.field;' | 360 ' new MyA.myfromFoo(); new MyA().myfoo(); globalfoo(); A.field;' |
361 ' A.staticfoo(); new A(); new A.fromFoo(); new A().foo();}'; | 361 ' A.staticfoo(); new A(); new A.fromFoo(); new A().foo();}'; |
362 testDart2DartWithLibrary(mainSrc, librarySrc, | 362 testDart2DartWithLibrary(mainSrc, librarySrc, |
363 (String result) { Expect.equals(expectedResult, result); }); | 363 (String result) { Expect.equals(expectedResult, result); }); |
364 } | 364 } |
365 | 365 |
366 testConflictLibraryClassRename() { | 366 testConflictLibraryClassRename() { |
367 var librarySrc = ''' | 367 var librarySrc = ''' |
368 #library('mylib'); | 368 #library('mylib'); |
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 testTypeVariablesAreRenamed(); | 782 testTypeVariablesAreRenamed(); |
783 testClassTypeArgumentBound(); | 783 testClassTypeArgumentBound(); |
784 testDoubleMains(); | 784 testDoubleMains(); |
785 testInterfaceDefaultAnotherLib(); | 785 testInterfaceDefaultAnotherLib(); |
786 testStaticAccessIoLib(); | 786 testStaticAccessIoLib(); |
787 testLocalFunctionPlaceholder(); | 787 testLocalFunctionPlaceholder(); |
788 testMinification(); | 788 testMinification(); |
789 testClosureLocalsMinified(); | 789 testClosureLocalsMinified(); |
790 testParametersMinified(); | 790 testParametersMinified(); |
791 } | 791 } |
OLD | NEW |