Chromium Code Reviews| 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"); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 47 } | 47 } |
| 48 abstract class Navigator { | 48 abstract class Navigator { |
| 49 abstract String get userAgent; | 49 abstract String get userAgent; |
| 50 } | 50 } |
| 51 '''; | 51 '''; |
| 52 | 52 |
| 53 const helperLib = r''' | 53 const helperLib = r''' |
| 54 #library('js_helper'); | 54 #library('js_helper'); |
| 55 '''; | 55 '''; |
| 56 | 56 |
| 57 testDart2Dart(String src, [void continuation(String s), bool minify = false, | 57 testDart2Dart(String src, {void continuation(String s), bool minify: false, |
| 58 bool stripTypes = false]) { | 58 bool stripTypes: false}) { |
| 59 // If continuation is not provided, check that source string remains the same. | 59 // If continuation is not provided, check that source string remains the same. |
| 60 if (continuation === null) { | 60 if (continuation === null) { |
| 61 continuation = (s) { Expect.equals(src, s); }; | 61 continuation = (s) { Expect.equals(src, s); }; |
| 62 } | 62 } |
| 63 testDart2DartWithLibrary(src, '', continuation, minify, stripTypes); | 63 testDart2DartWithLibrary(src, '', continuation: continuation, minify: minify, |
| 64 stripTypes: stripTypes); | |
|
Lasse Reichstein Nielsen
2012/10/17 14:56:10
This is one of the cases where we would really wan
regis
2012/10/17 19:58:16
Agreed.
| |
| 64 } | 65 } |
| 65 | 66 |
| 66 /** | 67 /** |
| 67 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 68 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 68 */ | 69 */ |
| 69 testDart2DartWithLibrary( | 70 testDart2DartWithLibrary( |
| 70 String srcMain, String srcLibrary, | 71 String srcMain, String srcLibrary, |
| 71 [void continuation(String s), bool minify = false, | 72 {void continuation(String s), bool minify: false, |
| 72 bool stripTypes = false]) { | 73 bool stripTypes: false}) { |
| 73 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); | 74 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); |
| 74 | 75 |
| 75 final scriptUri = fileUri('script.dart'); | 76 final scriptUri = fileUri('script.dart'); |
| 76 final libUri = fileUri('mylib.dart'); | 77 final libUri = fileUri('mylib.dart'); |
| 77 | 78 |
| 78 provider(uri) { | 79 provider(uri) { |
| 79 if (uri == scriptUri) return new Future.immediate(srcMain); | 80 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 80 if (uri.toString() == libUri.toString()) { | 81 if (uri.toString() == libUri.toString()) { |
| 81 return new Future.immediate(srcLibrary); | 82 return new Future.immediate(srcLibrary); |
| 82 } | 83 } |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 112 should_be_dropped() { | 113 should_be_dropped() { |
| 113 } | 114 } |
| 114 | 115 |
| 115 should_be_kept() { | 116 should_be_kept() { |
| 116 } | 117 } |
| 117 | 118 |
| 118 main() { | 119 main() { |
| 119 should_be_kept(); | 120 should_be_kept(); |
| 120 } | 121 } |
| 121 '''; | 122 '''; |
| 122 testDart2Dart(src, (String s) { | 123 testDart2Dart(src, continuation: (String s) { |
| 123 Expect.equals('should_be_kept(){}main(){should_be_kept();}', s); | 124 Expect.equals('should_be_kept(){}main(){should_be_kept();}', s); |
| 124 }); | 125 }); |
| 125 } | 126 } |
| 126 | 127 |
| 127 testTopLevelField() { | 128 testTopLevelField() { |
| 128 testDart2Dart('final String x="asd";main(){x;}'); | 129 testDart2Dart('final String x="asd";main(){x;}'); |
| 129 } | 130 } |
| 130 | 131 |
| 131 testSimpleTopLevelClass() { | 132 testSimpleTopLevelClass() { |
| 132 testDart2Dart('main(){new A();}class A{A(){}}'); | 133 testDart2Dart('main(){new A();}class A{A(){}}'); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 253 'class p_A{p_A(){}p_A.fromFoo(){}static p_staticfoo(){}foo(){}' | 254 'class p_A{p_A(){}p_A.fromFoo(){}static p_staticfoo(){}foo(){}' |
| 254 'static const p_field=5;}' | 255 'static const p_field=5;}' |
| 255 'main(){p_globalVar;p_globalVarInitialized;' | 256 'main(){p_globalVar;p_globalVarInitialized;' |
| 256 'p_globalVarInitialized2;p_globalfoo();' | 257 'p_globalVarInitialized2;p_globalfoo();' |
| 257 'p_A.p_field;p_A.p_staticfoo();' | 258 'p_A.p_field;p_A.p_staticfoo();' |
| 258 'new p_A();new p_A.fromFoo();new p_A().foo();' | 259 'new p_A();new p_A.fromFoo();new p_A().foo();' |
| 259 'globalVar;globalVarInitialized;globalVarInitialized2;globalfoo();' | 260 'globalVar;globalVarInitialized;globalVarInitialized2;globalfoo();' |
| 260 'A.field;A.staticfoo();' | 261 'A.field;A.staticfoo();' |
| 261 'new A();new A.fromFoo();new A().foo();}'; | 262 'new A();new A.fromFoo();new A().foo();}'; |
| 262 testDart2DartWithLibrary(mainSrc, librarySrc, | 263 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 263 (String result) { Expect.equals(expectedResult, result); }); | 264 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 264 } | 265 } |
| 265 | 266 |
| 266 testNoConflictSendsRename() { | 267 testNoConflictSendsRename() { |
| 267 // Various Send-s to current library and external library. Nothing should be | 268 // Various Send-s to current library and external library. Nothing should be |
| 268 // renamed here, only library prefixes must be cut. | 269 // renamed here, only library prefixes must be cut. |
| 269 var librarySrc = ''' | 270 var librarySrc = ''' |
| 270 #library("mylib.dart"); | 271 #library("mylib.dart"); |
| 271 | 272 |
| 272 globalfoo() {} | 273 globalfoo() {} |
| 273 | 274 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 312 'globalfoo(){}' | 313 'globalfoo(){}' |
| 313 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}' | 314 'class A{A(){}A.fromFoo(){}static staticfoo(){}foo(){}' |
| 314 'static const field=5;}' | 315 'static const field=5;}' |
| 315 'myglobalfoo(){}' | 316 'myglobalfoo(){}' |
| 316 'class MyA{MyA(){}MyA.myfromFoo(){}static mystaticfoo(){}myfoo(){}' | 317 'class MyA{MyA(){}MyA.myfromFoo(){}static mystaticfoo(){}myfoo(){}' |
| 317 'static const myfield=5;}' | 318 'static const myfield=5;}' |
| 318 'main(){myglobalfoo();MyA.myfield;MyA.mystaticfoo();new MyA();' | 319 'main(){myglobalfoo();MyA.myfield;MyA.mystaticfoo();new MyA();' |
| 319 'new MyA.myfromFoo();new MyA().myfoo();globalfoo();A.field;' | 320 'new MyA.myfromFoo();new MyA().myfoo();globalfoo();A.field;' |
| 320 'A.staticfoo();new A();new A.fromFoo();new A().foo();}'; | 321 'A.staticfoo();new A();new A.fromFoo();new A().foo();}'; |
| 321 testDart2DartWithLibrary(mainSrc, librarySrc, | 322 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 322 (String result) { Expect.equals(expectedResult, result); }); | 323 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 323 } | 324 } |
| 324 | 325 |
| 325 testConflictLibraryClassRename() { | 326 testConflictLibraryClassRename() { |
| 326 var librarySrc = ''' | 327 var librarySrc = ''' |
| 327 #library('mylib'); | 328 #library('mylib'); |
| 328 | 329 |
| 329 topfoo() {} | 330 topfoo() {} |
| 330 | 331 |
| 331 class A { | 332 class A { |
| 332 foo(){} | 333 foo(){} |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 361 '''; | 362 '''; |
| 362 var expectedResult = | 363 var expectedResult = |
| 363 'topfoo(){}' | 364 'topfoo(){}' |
| 364 'class A{foo(){}}' | 365 'class A{foo(){}}' |
| 365 'p_topfoo(){var x=5;}' | 366 'p_topfoo(){var x=5;}' |
| 366 'class p_A{num foo(){}p_A.fromFoo(){}A myliba;List<p_A> mylist;}' | 367 'class p_A{num foo(){}p_A.fromFoo(){}A myliba;List<p_A> mylist;}' |
| 367 'A getA()=>null;' | 368 'A getA()=>null;' |
| 368 'main(){var a=new A();a.foo();var b=new p_A.fromFoo();b.foo();' | 369 'main(){var a=new A();a.foo();var b=new p_A.fromFoo();b.foo();' |
| 369 'var GREATVAR=b.myliba;b.mylist;a=getA();p_topfoo();topfoo();}'; | 370 'var GREATVAR=b.myliba;b.mylist;a=getA();p_topfoo();topfoo();}'; |
| 370 testDart2DartWithLibrary(mainSrc, librarySrc, | 371 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 371 (String result) { Expect.equals(expectedResult, result); }); | 372 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 372 } | 373 } |
| 373 | 374 |
| 374 testDefaultClassWithArgs() { | 375 testDefaultClassWithArgs() { |
| 375 testDart2Dart('main(){var result=new IA<String>();}' | 376 testDart2Dart('main(){var result=new IA<String>();}' |
| 376 'interface IA<T> default A<T extends Object>{IA();}' | 377 'interface IA<T> default A<T extends Object>{IA();}' |
| 377 'class A<T extends Object> implements IA<T>{factory A(){}}'); | 378 'class A<T extends Object> implements IA<T>{factory A(){}}'); |
| 378 } | 379 } |
| 379 | 380 |
| 380 testClassExtendsWithArgs() { | 381 testClassExtendsWithArgs() { |
| 381 testDart2Dart('main(){new B<Object>();}' | 382 testDart2Dart('main(){new B<Object>();}' |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 408 mylib.topgetset = 5; | 409 mylib.topgetset = 5; |
| 409 } | 410 } |
| 410 '''; | 411 '''; |
| 411 var expectedResult = | 412 var expectedResult = |
| 412 'get topgetset=>5;' | 413 'get topgetset=>5;' |
| 413 'set topgetset(arg){}' | 414 'set topgetset(arg){}' |
| 414 'get p_topgetset=>6;' | 415 'get p_topgetset=>6;' |
| 415 'set p_topgetset(arg){}' | 416 'set p_topgetset(arg){}' |
| 416 'main(){p_topgetset;p_topgetset=6;topgetset;topgetset=5;}'; | 417 'main(){p_topgetset;p_topgetset=6;topgetset;topgetset=5;}'; |
| 417 testDart2DartWithLibrary(mainSrc, librarySrc, | 418 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 418 (String result) { Expect.equals(expectedResult, result); }); | 419 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 419 } | 420 } |
| 420 | 421 |
| 421 testFieldTypeOutput() { | 422 testFieldTypeOutput() { |
| 422 testDart2Dart('main(){new A().field;}class B{}class A{B field;}'); | 423 testDart2Dart('main(){new A().field;}class B{}class A{B field;}'); |
| 423 } | 424 } |
| 424 | 425 |
| 425 class DynoMap implements Map<Element, ElementAst> { | 426 class DynoMap implements Map<Element, ElementAst> { |
| 426 final compiler; | 427 final compiler; |
| 427 DynoMap(this.compiler); | 428 DynoMap(this.compiler); |
| 428 | 429 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 507 '''; | 508 '''; |
| 508 var expectedResult = | 509 var expectedResult = |
| 509 'interface I default B{I();}' | 510 'interface I default B{I();}' |
| 510 'class A implements I{A(){}}' | 511 'class A implements I{A(){}}' |
| 511 'class B{factory I(){}}' | 512 'class B{factory I(){}}' |
| 512 'interface p_I default p_B{p_I();}' | 513 'interface p_I default p_B{p_I();}' |
| 513 'class p_A implements p_I{p_A(){}}' | 514 'class p_A implements p_I{p_A(){}}' |
| 514 'class p_B{factory p_I(){}}' | 515 'class p_B{factory p_I(){}}' |
| 515 'main(){new p_I();new p_A();new I();new A();}'; | 516 'main(){new p_I();new p_A();new I();new A();}'; |
| 516 testDart2DartWithLibrary(mainSrc, librarySrc, | 517 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 517 (String result) { Expect.equals(expectedResult, result); }); | 518 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 518 } | 519 } |
| 519 | 520 |
| 520 testTypeVariablesAreRenamed() { | 521 testTypeVariablesAreRenamed() { |
| 521 // Somewhat a hack: we require all the references of the identifier | 522 // Somewhat a hack: we require all the references of the identifier |
| 522 // to be renamed in the same way for the whole library. Hence | 523 // to be renamed in the same way for the whole library. Hence |
| 523 // if we have a class and type variable with the same name, they | 524 // if we have a class and type variable with the same name, they |
| 524 // both should be renamed. | 525 // both should be renamed. |
| 525 var librarySrc = ''' | 526 var librarySrc = ''' |
| 526 #library('mylib'); | 527 #library('mylib'); |
| 527 typedef void MyFunction<T extends num>(T arg); | 528 typedef void MyFunction<T extends num>(T arg); |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 551 'class T{}' | 552 'class T{}' |
| 552 'class B<T>{}' | 553 'class B<T>{}' |
| 553 'class A<T> extends B<T>{T f;}' | 554 'class A<T> extends B<T>{T f;}' |
| 554 'typedef void p_MyFunction<p_T extends num>(p_T arg);' | 555 'typedef void p_MyFunction<p_T extends num>(p_T arg);' |
| 555 'class p_T{}' | 556 'class p_T{}' |
| 556 'class p_B<p_T>{}' | 557 'class p_B<p_T>{}' |
| 557 'class p_A<p_T> extends p_B<p_T>{p_T f;}' | 558 'class p_A<p_T> extends p_B<p_T>{p_T f;}' |
| 558 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;' | 559 'main(){p_MyFunction myf1;MyFunction myf2;new p_A<int>().f;' |
| 559 'new p_T();new A<int>().f;new T();}'; | 560 'new p_T();new A<int>().f;new T();}'; |
| 560 testDart2DartWithLibrary(mainSrc, librarySrc, | 561 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 561 (String result) { Expect.equals(expectedResult, result); }); | 562 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 562 } | 563 } |
| 563 | 564 |
| 564 testClassTypeArgumentBound() { | 565 testClassTypeArgumentBound() { |
| 565 var librarySrc = ''' | 566 var librarySrc = ''' |
| 566 #library('mylib'); | 567 #library('mylib'); |
| 567 | 568 |
| 568 interface I {} | 569 interface I {} |
| 569 class A<T extends I> {} | 570 class A<T extends I> {} |
| 570 | 571 |
| 571 '''; | 572 '''; |
| 572 var mainSrc = ''' | 573 var mainSrc = ''' |
| 573 #import('mylib.dart', prefix: 'mylib'); | 574 #import('mylib.dart', prefix: 'mylib'); |
| 574 | 575 |
| 575 interface I {} | 576 interface I {} |
| 576 class A<T extends I> {} | 577 class A<T extends I> {} |
| 577 | 578 |
| 578 main() { | 579 main() { |
| 579 new A(); | 580 new A(); |
| 580 new mylib.A(); | 581 new mylib.A(); |
| 581 } | 582 } |
| 582 '''; | 583 '''; |
| 583 var expectedResult = | 584 var expectedResult = |
| 584 'interface I{}' | 585 'interface I{}' |
| 585 'class A<T extends I>{}' | 586 'class A<T extends I>{}' |
| 586 'interface p_I{}' | 587 'interface p_I{}' |
| 587 'class p_A<p_T extends p_I>{}' | 588 'class p_A<p_T extends p_I>{}' |
| 588 'main(){new p_A();new A();}'; | 589 'main(){new p_A();new A();}'; |
| 589 testDart2DartWithLibrary(mainSrc, librarySrc, | 590 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 590 (String result) { Expect.equals(expectedResult, result); }); | 591 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 591 } | 592 } |
| 592 | 593 |
| 593 testDoubleMains() { | 594 testDoubleMains() { |
| 594 var librarySrc = ''' | 595 var librarySrc = ''' |
| 595 #library('mylib'); | 596 #library('mylib'); |
| 596 main() {} | 597 main() {} |
| 597 '''; | 598 '''; |
| 598 var mainSrc = ''' | 599 var mainSrc = ''' |
| 599 #import('mylib.dart', prefix: 'mylib'); | 600 #import('mylib.dart', prefix: 'mylib'); |
| 600 main() { | 601 main() { |
| 601 mylib.main(); | 602 mylib.main(); |
| 602 } | 603 } |
| 603 '''; | 604 '''; |
| 604 var expectedResult = | 605 var expectedResult = |
| 605 'p_main(){}' | 606 'p_main(){}' |
| 606 'main(){p_main();}'; | 607 'main(){p_main();}'; |
| 607 testDart2DartWithLibrary(mainSrc, librarySrc, | 608 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 608 (String result) { Expect.equals(expectedResult, result); }); | 609 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 609 } | 610 } |
| 610 | 611 |
| 611 testInterfaceDefaultAnotherLib() { | 612 testInterfaceDefaultAnotherLib() { |
| 612 var librarySrc = ''' | 613 var librarySrc = ''' |
| 613 #library('mylib'); | 614 #library('mylib'); |
| 614 class C<T> { | 615 class C<T> { |
| 615 factory I() {} | 616 factory I() {} |
| 616 } | 617 } |
| 617 '''; | 618 '''; |
| 618 var mainSrc = ''' | 619 var mainSrc = ''' |
| 619 #import('mylib.dart', prefix: 'mylib'); | 620 #import('mylib.dart', prefix: 'mylib'); |
| 620 | 621 |
| 621 interface I<T> default mylib.C<T> { | 622 interface I<T> default mylib.C<T> { |
| 622 I(); | 623 I(); |
| 623 } | 624 } |
| 624 | 625 |
| 625 main() { | 626 main() { |
| 626 new I(); | 627 new I(); |
| 627 } | 628 } |
| 628 '''; | 629 '''; |
| 629 var expectedResult = | 630 var expectedResult = |
| 630 'class C<T>{factory I(){}}' | 631 'class C<T>{factory I(){}}' |
| 631 'interface I<T> default C<T>{I();}' | 632 'interface I<T> default C<T>{I();}' |
| 632 'main(){new I();}'; | 633 'main(){new I();}'; |
| 633 testDart2DartWithLibrary(mainSrc, librarySrc, | 634 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 634 (String result) { Expect.equals(expectedResult, result); }); | 635 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 635 } | 636 } |
| 636 | 637 |
| 637 testStaticAccessIoLib() { | 638 testStaticAccessIoLib() { |
| 638 var src = ''' | 639 var src = ''' |
| 639 #import('dart:io'); | 640 #import('dart:io'); |
| 640 | 641 |
| 641 main() { | 642 main() { |
| 642 Platform.operatingSystem; | 643 Platform.operatingSystem; |
| 643 } | 644 } |
| 644 '''; | 645 '''; |
| 645 var expectedResult = 'import "dart:io" as p;' | 646 var expectedResult = 'import "dart:io" as p;' |
| 646 'main(){p.Platform.operatingSystem;}'; | 647 'main(){p.Platform.operatingSystem;}'; |
| 647 testDart2Dart(src, | 648 testDart2Dart(src, |
| 648 (String result) { Expect.equals(expectedResult, result); }); | 649 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 649 } | 650 } |
| 650 | 651 |
| 651 testMinification() { | 652 testMinification() { |
| 652 var src = ''' | 653 var src = ''' |
| 653 class ClassWithVeryVeryLongName {} | 654 class ClassWithVeryVeryLongName {} |
| 654 main() { | 655 main() { |
| 655 new ClassWithVeryVeryLongName(); | 656 new ClassWithVeryVeryLongName(); |
| 656 } | 657 } |
| 657 '''; | 658 '''; |
| 658 var expectedResult = | 659 var expectedResult = |
| 659 'class A{}' | 660 'class A{}' |
| 660 'main(){new A();}'; | 661 'main(){new A();}'; |
| 661 testDart2Dart(src, | 662 testDart2Dart(src, continuation: |
| 662 (String result) { Expect.equals(expectedResult, result); }, minify: true); | 663 (String result) { Expect.equals(expectedResult, result); }, minify: true); |
| 663 } | 664 } |
| 664 | 665 |
| 665 testClosureLocalsMinified() { | 666 testClosureLocalsMinified() { |
| 666 var src = ''' | 667 var src = ''' |
| 667 main() { | 668 main() { |
| 668 var a = 7; | 669 var a = 7; |
| 669 void foo1(a,b) { | 670 void foo1(a,b) { |
| 670 void foo2(c,d) { | 671 void foo2(c,d) { |
| 671 var E = a; | 672 var E = a; |
| 672 } | 673 } |
| 673 foo2(b, a); | 674 foo2(b, a); |
| 674 } | 675 } |
| 675 foo1(a, 8); | 676 foo1(a, 8); |
| 676 } | 677 } |
| 677 '''; | 678 '''; |
| 678 var expectedResult = | 679 var expectedResult = |
| 679 'main(){var A=7; B(A,C){ D(E,F){var G=A;}D(C,A);}B(A,8);}'; | 680 'main(){var A=7; B(A,C){ D(E,F){var G=A;}D(C,A);}B(A,8);}'; |
| 680 testDart2Dart(src, | 681 testDart2Dart(src, continuation: |
| 681 (String result) { Expect.equals(expectedResult, result); }, minify: true); | 682 (String result) { Expect.equals(expectedResult, result); }, minify: true); |
| 682 } | 683 } |
| 683 | 684 |
| 684 testParametersMinified() { | 685 testParametersMinified() { |
| 685 var src = ''' | 686 var src = ''' |
| 686 class A { | 687 class A { |
| 687 var a; | 688 var a; |
| 688 static foo(arg1) { | 689 static foo(arg1) { |
| 689 // Should not rename arg1 to a. | 690 // Should not rename arg1 to a. |
| 690 arg1 = 5; | 691 arg1 = 5; |
| 691 } | 692 } |
| 692 } | 693 } |
| 693 | 694 |
| 694 fooglobal(arg,[optionalarg = 7]) { | 695 fooglobal(arg,[optionalarg = 7]) { |
| 695 arg = 6; | 696 arg = 6; |
| 696 } | 697 } |
| 697 | 698 |
| 698 main() { | 699 main() { |
| 699 new A().a; | 700 new A().a; |
| 700 A.foo(8); | 701 A.foo(8); |
| 701 fooglobal(8); | 702 fooglobal(8); |
| 702 } | 703 } |
| 703 '''; | 704 '''; |
| 704 var expectedResult = | 705 var expectedResult = |
| 705 'class B{var E;static C(A){A=5;}}D(A,[optionalarg=7]){A=6;}' | 706 'class B{var E;static C(A){A=5;}}D(A,[optionalarg=7]){A=6;}' |
| 706 'main(){new B().E;B.C(8);D(8);}'; | 707 'main(){new B().E;B.C(8);D(8);}'; |
| 707 testDart2Dart(src, | 708 testDart2Dart(src, continuation: |
| 708 (String result) { Expect.equals(expectedResult, result); }, minify: true); | 709 (String result) { Expect.equals(expectedResult, result); }, minify: true); |
| 709 } | 710 } |
| 710 | 711 |
| 711 testTypeVariablesInDifferentLibraries() { | 712 testTypeVariablesInDifferentLibraries() { |
| 712 // This is a simplified version of what we have in | 713 // This is a simplified version of what we have in |
| 713 // lib/compiler/implementation/util. | 714 // lib/compiler/implementation/util. |
| 714 var librarySrc = ''' | 715 var librarySrc = ''' |
| 715 #library('mylib'); | 716 #library('mylib'); |
| 716 #import('script.dart'); | 717 #import('script.dart'); |
| 717 interface Iterable<K> {} | 718 interface Iterable<K> {} |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 731 main() { | 732 main() { |
| 732 new Link<int>(); | 733 new Link<int>(); |
| 733 } | 734 } |
| 734 '''; | 735 '''; |
| 735 var expectedResult = | 736 var expectedResult = |
| 736 'interface Iterable<K>{}' | 737 'interface Iterable<K>{}' |
| 737 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}' | 738 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}' |
| 738 'class LinkFactory<T>{factory Link(){}}' | 739 'class LinkFactory<T>{factory Link(){}}' |
| 739 'main(){new Link<int>();}'; | 740 'main(){new Link<int>();}'; |
| 740 testDart2DartWithLibrary(mainSrc, librarySrc, | 741 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 741 (String result) { Expect.equals(expectedResult, result); }); | 742 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 742 } | 743 } |
| 743 | 744 |
| 744 testDeclarationTypePlaceholders() { | 745 testDeclarationTypePlaceholders() { |
| 745 var src = ''' | 746 var src = ''' |
| 746 String globalfield; | 747 String globalfield; |
| 747 const String globalconstfield; | 748 const String globalconstfield; |
| 748 | 749 |
| 749 void foo(String arg) {} | 750 void foo(String arg) {} |
| 750 | 751 |
| 751 main() { | 752 main() { |
| 752 String localvar; | 753 String localvar; |
| 753 foo("5"); | 754 foo("5"); |
| 754 } | 755 } |
| 755 '''; | 756 '''; |
| 756 var expectedResult = | 757 var expectedResult = |
| 757 ' foo( arg){}main(){var localvar;foo("5");}'; | 758 ' foo( arg){}main(){var localvar;foo("5");}'; |
| 758 testDart2Dart(src, | 759 testDart2Dart(src, |
| 759 (String result) { Expect.equals(expectedResult, result); }, | 760 continuation: (String result) { Expect.equals(expectedResult, result); }, |
| 760 stripTypes: true); | 761 stripTypes: true); |
| 761 } | 762 } |
| 762 | 763 |
| 763 testPlatformLibraryMemberNamesAreFixed() { | 764 testPlatformLibraryMemberNamesAreFixed() { |
| 764 var src = ''' | 765 var src = ''' |
| 765 #import('dart:html'); | 766 #import('dart:html'); |
| 766 | 767 |
| 767 class A { | 768 class A { |
| 768 static String get userAgent => window.navigator.userAgent; | 769 static String get userAgent => window.navigator.userAgent; |
| 769 } | 770 } |
| 770 | 771 |
| 771 main() { | 772 main() { |
| 772 A.userAgent; | 773 A.userAgent; |
| 773 } | 774 } |
| 774 '''; | 775 '''; |
| 775 var expectedResult = 'import "dart:html" as p;' | 776 var expectedResult = 'import "dart:html" as p;' |
| 776 'class A{static String get userAgent=>p.window.navigator.userAgent;}' | 777 'class A{static String get userAgent=>p.window.navigator.userAgent;}' |
| 777 'main(){A.userAgent;}'; | 778 'main(){A.userAgent;}'; |
| 778 testDart2Dart(src, | 779 testDart2Dart(src, |
| 779 (String result) { Expect.equals(expectedResult, result); }); | 780 continuation: (String result) { Expect.equals(expectedResult, result); }); |
| 780 } | 781 } |
| 781 | 782 |
| 782 main() { | 783 main() { |
| 783 testSimpleFileUnparse(); | 784 testSimpleFileUnparse(); |
| 784 testTopLevelField(); | 785 testTopLevelField(); |
| 785 testSimpleTopLevelClass(); | 786 testSimpleTopLevelClass(); |
| 786 testClassWithSynthesizedConstructor(); | 787 testClassWithSynthesizedConstructor(); |
| 787 testClassWithMethod(); | 788 testClassWithMethod(); |
| 788 testExtendsImplements(); | 789 testExtendsImplements(); |
| 789 testVariableDefinitions(); | 790 testVariableDefinitions(); |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 806 testInterfaceDefaultAnotherLib(); | 807 testInterfaceDefaultAnotherLib(); |
| 807 testStaticAccessIoLib(); | 808 testStaticAccessIoLib(); |
| 808 testLocalFunctionPlaceholder(); | 809 testLocalFunctionPlaceholder(); |
| 809 testMinification(); | 810 testMinification(); |
| 810 testClosureLocalsMinified(); | 811 testClosureLocalsMinified(); |
| 811 testParametersMinified(); | 812 testParametersMinified(); |
| 812 testTypeVariablesInDifferentLibraries(); | 813 testTypeVariablesInDifferentLibraries(); |
| 813 testDeclarationTypePlaceholders(); | 814 testDeclarationTypePlaceholders(); |
| 814 testPlatformLibraryMemberNamesAreFixed(); | 815 testPlatformLibraryMemberNamesAreFixed(); |
| 815 } | 816 } |
| OLD | NEW |