| 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 import 'dart:async'; | 6 import 'dart:async'; |
| 7 import "package:async_helper/async_helper.dart"; | 7 import "package:async_helper/async_helper.dart"; |
| 8 import '../mock_compiler.dart'; | 8 import '../mock_compiler.dart'; |
| 9 import '../mock_libraries.dart'; | 9 import '../mock_libraries.dart'; |
| 10 import 'package:compiler/compiler.dart'; | 10 import 'package:compiler/compiler.dart'; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 Window __window; | 25 Window __window; |
| 26 Window get window => __window; | 26 Window get window => __window; |
| 27 abstract class Window { | 27 abstract class Window { |
| 28 Navigator get navigator; | 28 Navigator get navigator; |
| 29 } | 29 } |
| 30 abstract class Navigator { | 30 abstract class Navigator { |
| 31 String get userAgent; | 31 String get userAgent; |
| 32 } | 32 } |
| 33 '''; | 33 '''; |
| 34 | 34 |
| 35 testDart2Dart(String src, {void continuation(String s), bool minify: false, | |
| 36 bool stripTypes: false}) { | |
| 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: continuation, minify: minify, | |
| 42 stripTypes: stripTypes); | |
| 43 } | |
| 44 | |
| 45 /** | 35 /** |
| 46 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 36 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 47 */ | 37 */ |
| 48 testDart2DartWithLibrary( | 38 testDart2Dart(String mainSrc, {String librarySrc, |
| 49 String srcMain, String srcLibrary, | 39 String expectedResult, |
| 50 {void continuation(String s), bool minify: false, | 40 bool minify: false, |
| 51 bool stripTypes: false}) { | 41 bool stripTypes: false}) { |
| 42 |
| 43 // If expectedResult is not provided, check that source string remains the |
| 44 // same. |
| 45 if (expectedResult == null) { |
| 46 Expect.equals(null, librarySrc); |
| 47 expectedResult = mainSrc; |
| 48 } |
| 49 |
| 52 fileUri(path) => new Uri(scheme: 'file', path: path); | 50 fileUri(path) => new Uri(scheme: 'file', path: path); |
| 53 | 51 |
| 54 final scriptUri = fileUri('script.dart'); | 52 final scriptUri = fileUri('script.dart'); |
| 55 final libUri = fileUri('mylib.dart'); | 53 final libUri = fileUri('mylib.dart'); |
| 56 | 54 |
| 57 provider(uri) { | 55 provider(uri) { |
| 58 if (uri == scriptUri) return new Future.value(srcMain); | 56 if (uri == scriptUri) return new Future.value(mainSrc); |
| 59 if (uri.toString() == libUri.toString()) { | 57 if (uri.toString() == libUri.toString()) { |
| 60 return new Future.value(srcLibrary); | 58 return new Future.value(librarySrc); |
| 61 } | 59 } |
| 62 if (uri.path.endsWith('/core.dart')) { | 60 if (uri.path.endsWith('/core.dart')) { |
| 63 return new Future.value(buildLibrarySource(DEFAULT_CORE_LIBRARY)); | 61 return new Future.value(buildLibrarySource(DEFAULT_CORE_LIBRARY)); |
| 64 } else if (uri.path.endsWith('/core_patch.dart')) { | 62 } else if (uri.path.endsWith('/core_patch.dart')) { |
| 65 return new Future.value(DEFAULT_PATCH_CORE_SOURCE); | 63 return new Future.value(DEFAULT_PATCH_CORE_SOURCE); |
| 66 } else if (uri.path.endsWith('/io.dart')) { | 64 } else if (uri.path.endsWith('/io.dart')) { |
| 67 return new Future.value(ioLib); | 65 return new Future.value(ioLib); |
| 68 } else if (uri.path.endsWith('/js_helper.dart')) { | 66 } else if (uri.path.endsWith('/js_helper.dart')) { |
| 69 return new Future.value(buildLibrarySource(DEFAULT_JS_HELPER_LIBRARY)); | 67 return new Future.value(buildLibrarySource(DEFAULT_JS_HELPER_LIBRARY)); |
| 70 } else if (uri.path.endsWith('/html_dart2js.dart')) { | 68 } else if (uri.path.endsWith('/html_dart2js.dart')) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 85 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 83 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 86 } | 84 } |
| 87 } | 85 } |
| 88 | 86 |
| 89 final options = <String>['--output-type=dart']; | 87 final options = <String>['--output-type=dart']; |
| 90 // Some tests below are using dart:io. | 88 // Some tests below are using dart:io. |
| 91 options.add('--categories=Client,Server'); | 89 options.add('--categories=Client,Server'); |
| 92 if (minify) options.add('--minify'); | 90 if (minify) options.add('--minify'); |
| 93 if (stripTypes) options.add('--force-strip=types'); | 91 if (stripTypes) options.add('--force-strip=types'); |
| 94 | 92 |
| 95 asyncTest(() => compile( | 93 asyncTest(() { |
| 96 scriptUri, | 94 return compile( |
| 97 fileUri('libraryRoot/'), | 95 scriptUri, |
| 98 fileUri('packageRoot/'), | 96 fileUri('libraryRoot/'), |
| 99 provider, | 97 fileUri('packageRoot/'), |
| 100 handler, | 98 provider, |
| 101 options).then(continuation)); | 99 handler, |
| 100 options).then((s) { |
| 101 Expect.equals(expectedResult, s); |
| 102 }); |
| 103 }); |
| 102 } | 104 } |
| 103 | 105 |
| 104 testSimpleFileUnparse() { | 106 testSimpleFileUnparse() { |
| 105 final src = ''' | 107 final src = ''' |
| 106 should_be_dropped() { | 108 should_be_dropped() { |
| 107 } | 109 } |
| 108 | 110 |
| 109 should_be_kept() { | 111 should_be_kept() { |
| 110 } | 112 } |
| 111 | 113 |
| 112 main() { | 114 main() { |
| 113 should_be_kept(); | 115 should_be_kept(); |
| 114 } | 116 } |
| 115 '''; | 117 '''; |
| 116 testDart2Dart(src, continuation: (String s) { | 118 testDart2Dart(src, expectedResult: ''' |
| 117 print(s); | |
| 118 Expect.equals(''' | |
| 119 should_be_kept() {} | 119 should_be_kept() {} |
| 120 main() { | 120 main() { |
| 121 should_be_kept(); | 121 should_be_kept(); |
| 122 } | 122 } |
| 123 ''', s); | 123 '''); |
| 124 }); | |
| 125 } | 124 } |
| 126 testTopLevelField() { | 125 testTopLevelField() { |
| 127 testDart2Dart(''' | 126 testDart2Dart(''' |
| 128 final String x = "asd"; | 127 final String x = "asd"; |
| 129 main() { | 128 main() { |
| 130 x; | 129 x; |
| 131 } | 130 } |
| 132 '''); | 131 '''); |
| 133 } | 132 } |
| 134 | 133 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 mylib.globalVarInitialized2; | 322 mylib.globalVarInitialized2; |
| 324 mylib.globalfoo(); | 323 mylib.globalfoo(); |
| 325 mylib.A.field; | 324 mylib.A.field; |
| 326 mylib.A.staticfoo(); | 325 mylib.A.staticfoo(); |
| 327 new mylib.A(); | 326 new mylib.A(); |
| 328 new mylib.A.fromFoo(); | 327 new mylib.A.fromFoo(); |
| 329 new mylib.A().foo(); | 328 new mylib.A().foo(); |
| 330 } | 329 } |
| 331 '''; | 330 '''; |
| 332 var expectedResult = ''' | 331 var expectedResult = ''' |
| 332 globalfoo_A() {} |
| 333 var globalVar_A; |
| 334 var globalVarInitialized_A = 6; |
| 335 var globalVarInitialized2_A = 7; |
| 336 class A_A { |
| 337 A_A() {} |
| 338 A_A.fromFoo_A() {} |
| 339 static staticfoo_A() {} |
| 340 foo() {} |
| 341 static const field_A = 5; |
| 342 } |
| 333 globalfoo() {} | 343 globalfoo() {} |
| 334 var globalVar; | 344 var globalVar; |
| 335 var globalVarInitialized = 6; | 345 var globalVarInitialized = 6; |
| 336 var globalVarInitialized2 = 7; | 346 var globalVarInitialized2 = 7; |
| 337 class A { | 347 class A { |
| 338 A() {} | 348 A() {} |
| 339 A.fromFoo() {} | 349 A.fromFoo() {} |
| 340 static staticfoo() {} | 350 static staticfoo() {} |
| 341 foo() {} | 351 foo() {} |
| 342 static const field = 5; | 352 static const field = 5; |
| 343 } | 353 } |
| 344 A_globalfoo() {} | |
| 345 var A_globalVar; | |
| 346 var A_globalVarInitialized = 6; | |
| 347 var A_globalVarInitialized2 = 7; | |
| 348 class A_A { | |
| 349 A_A() {} | |
| 350 A_A.A_fromFoo() {} | |
| 351 static A_staticfoo() {} | |
| 352 foo() {} | |
| 353 static const A_field = 5; | |
| 354 } | |
| 355 main() { | 354 main() { |
| 356 A_globalVar; | |
| 357 A_globalVarInitialized; | |
| 358 A_globalVarInitialized2; | |
| 359 A_globalfoo(); | |
| 360 A_A.A_field; | |
| 361 A_A.A_staticfoo(); | |
| 362 new A_A(); | |
| 363 new A_A.A_fromFoo(); | |
| 364 new A_A().foo(); | |
| 365 globalVar; | 355 globalVar; |
| 366 globalVarInitialized; | 356 globalVarInitialized; |
| 367 globalVarInitialized2; | 357 globalVarInitialized2; |
| 368 globalfoo(); | 358 globalfoo(); |
| 369 A.field; | 359 A.field; |
| 370 A.staticfoo(); | 360 A.staticfoo(); |
| 371 new A(); | 361 new A(); |
| 372 new A.fromFoo(); | 362 new A.fromFoo(); |
| 373 new A().foo(); | 363 new A().foo(); |
| 364 globalVar_A; |
| 365 globalVarInitialized_A; |
| 366 globalVarInitialized2_A; |
| 367 globalfoo_A(); |
| 368 A_A.field_A; |
| 369 A_A.staticfoo_A(); |
| 370 new A_A(); |
| 371 new A_A.fromFoo_A(); |
| 372 new A_A().foo(); |
| 374 } | 373 } |
| 375 '''; | 374 '''; |
| 376 testDart2DartWithLibrary(mainSrc, librarySrc, | 375 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 377 continuation: (String result) { Expect.equals(expectedResult, result); }); | 376 expectedResult: expectedResult); |
| 378 } | 377 } |
| 379 | 378 |
| 380 testNoConflictSendsRename() { | 379 testNoConflictSendsRename() { |
| 381 // Various Send-s to current library and external library. Nothing should be | 380 // Various Send-s to current library and external library. Nothing should be |
| 382 // renamed here, only library prefixes must be cut. | 381 // renamed here, only library prefixes must be cut. |
| 383 var librarySrc = ''' | 382 var librarySrc = ''' |
| 384 library mylib; | 383 library mylib; |
| 385 | 384 |
| 386 globalfoo() {} | 385 globalfoo() {} |
| 387 | 386 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 new MyA.myfromFoo(); | 446 new MyA.myfromFoo(); |
| 448 new MyA().myfoo(); | 447 new MyA().myfoo(); |
| 449 globalfoo(); | 448 globalfoo(); |
| 450 A.field; | 449 A.field; |
| 451 A.staticfoo(); | 450 A.staticfoo(); |
| 452 new A(); | 451 new A(); |
| 453 new A.fromFoo(); | 452 new A.fromFoo(); |
| 454 new A().foo(); | 453 new A().foo(); |
| 455 } | 454 } |
| 456 '''; | 455 '''; |
| 457 testDart2DartWithLibrary(mainSrc, librarySrc, | 456 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 458 continuation: (String result) { Expect.equals(expectedResult, result); }); | 457 expectedResult: expectedResult); |
| 459 } | 458 } |
| 460 | 459 |
| 461 testConflictLibraryClassRename() { | 460 testConflictLibraryClassRename() { |
| 462 var librarySrc = ''' | 461 var librarySrc = ''' |
| 463 library mylib; | 462 library mylib; |
| 464 | 463 |
| 465 topfoo() {} | 464 topfoo() {} |
| 466 | 465 |
| 467 class A { | 466 class A { |
| 468 foo() {} | 467 foo() {} |
| (...skipping 17 matching lines...) Expand all Loading... |
| 486 var b = new A.fromFoo(); | 485 var b = new A.fromFoo(); |
| 487 b.foo(); | 486 b.foo(); |
| 488 var GREATVAR = b.myliba; | 487 var GREATVAR = b.myliba; |
| 489 b.mylist; | 488 b.mylist; |
| 490 a = getA(); | 489 a = getA(); |
| 491 topfoo(); | 490 topfoo(); |
| 492 mylib.topfoo(); | 491 mylib.topfoo(); |
| 493 } | 492 } |
| 494 '''; | 493 '''; |
| 495 var expectedResult = ''' | 494 var expectedResult = ''' |
| 496 topfoo() {} | 495 topfoo_A() {} |
| 497 class A { | 496 class A { |
| 498 foo() {} | 497 foo() {} |
| 499 } | 498 } |
| 500 A_topfoo() { | 499 topfoo() { |
| 501 var x = 5; | 500 var x = 5; |
| 502 } | 501 } |
| 503 class A_A { | 502 class A_A { |
| 504 num foo() {} | 503 num foo() {} |
| 505 A_A.fromFoo() {} | 504 A_A.fromFoo() {} |
| 506 A myliba; | 505 A myliba; |
| 507 List<A_A> mylist; | 506 List<A_A> mylist; |
| 508 } | 507 } |
| 509 A getA() => null; | 508 A getA() => null; |
| 510 main() { | 509 main() { |
| 511 var a = new A(); | 510 var a = new A(); |
| 512 a.foo(); | 511 a.foo(); |
| 513 var b = new A_A.fromFoo(); | 512 var b = new A_A.fromFoo(); |
| 514 b.foo(); | 513 b.foo(); |
| 515 var GREATVAR = b.myliba; | 514 var GREATVAR = b.myliba; |
| 516 b.mylist; | 515 b.mylist; |
| 517 a = getA(); | 516 a = getA(); |
| 518 A_topfoo(); | |
| 519 topfoo(); | 517 topfoo(); |
| 518 topfoo_A(); |
| 520 } | 519 } |
| 521 '''; | 520 '''; |
| 522 testDart2DartWithLibrary(mainSrc, librarySrc, | 521 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 523 continuation: (String result) { Expect.equals(expectedResult, result); }); | 522 expectedResult: expectedResult); |
| 524 } | 523 } |
| 525 | 524 |
| 526 testClassExtendsWithArgs() { | 525 testClassExtendsWithArgs() { |
| 527 testDart2Dart(''' | 526 testDart2Dart(''' |
| 528 main() { | 527 main() { |
| 529 new B<Object>(); | 528 new B<Object>(); |
| 530 } | 529 } |
| 531 class A<T extends Object> {} | 530 class A<T extends Object> {} |
| 532 class B<T extends Object> extends A<T> {} | 531 class B<T extends Object> extends A<T> {} |
| 533 '''); | 532 '''); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 556 | 555 |
| 557 main() { | 556 main() { |
| 558 topgetset; | 557 topgetset; |
| 559 topgetset = 6; | 558 topgetset = 6; |
| 560 | 559 |
| 561 mylib.topgetset; | 560 mylib.topgetset; |
| 562 mylib.topgetset = 5; | 561 mylib.topgetset = 5; |
| 563 } | 562 } |
| 564 '''; | 563 '''; |
| 565 var expectedResult = ''' | 564 var expectedResult = ''' |
| 566 get topgetset => 5; | 565 get topgetset_A => 5; |
| 566 set topgetset_A(arg) {} |
| 567 get topgetset => 6; |
| 567 set topgetset(arg) {} | 568 set topgetset(arg) {} |
| 568 get A_topgetset => 6; | |
| 569 set A_topgetset(arg) {} | |
| 570 main() { | 569 main() { |
| 571 A_topgetset; | |
| 572 A_topgetset = 6; | |
| 573 topgetset; | 570 topgetset; |
| 574 topgetset = 5; | 571 topgetset = 6; |
| 572 topgetset_A; |
| 573 topgetset_A = 5; |
| 575 } | 574 } |
| 576 '''; | 575 '''; |
| 577 testDart2DartWithLibrary(mainSrc, librarySrc, | 576 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 578 continuation: (String result) { Expect.equals(expectedResult, result); }); | 577 expectedResult: expectedResult); |
| 579 } | 578 } |
| 580 | 579 |
| 581 testFieldTypeOutput() { | 580 testFieldTypeOutput() { |
| 582 testDart2Dart(''' | 581 testDart2Dart(''' |
| 583 main() { | 582 main() { |
| 584 new A().field; | 583 new A().field; |
| 585 } | 584 } |
| 586 class B {} | 585 class B {} |
| 587 class A { | 586 class A { |
| 588 B field; | 587 B field; |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 650 MyFunction myf1; | 649 MyFunction myf1; |
| 651 mylib.MyFunction myf2; | 650 mylib.MyFunction myf2; |
| 652 new A<int>().f; | 651 new A<int>().f; |
| 653 new T(); | 652 new T(); |
| 654 | 653 |
| 655 new mylib.A<int>().f; | 654 new mylib.A<int>().f; |
| 656 new mylib.T(); | 655 new mylib.T(); |
| 657 } | 656 } |
| 658 '''; | 657 '''; |
| 659 var expectedResult = ''' | 658 var expectedResult = ''' |
| 660 typedef void MyFunction<T extends num>(T arg); | 659 typedef void MyFunction_A<T_B extends num>(T_B arg); |
| 660 class T_A {} |
| 661 class B_A<T_B> {} |
| 662 class A_A<T_B> extends B_A<T_B> { |
| 663 T_B f; |
| 664 } |
| 665 typedef void MyFunction<T_B extends num>(T_B arg); |
| 661 class T {} | 666 class T {} |
| 662 class B<T> {} | 667 class B<T_B> {} |
| 663 class A<T> extends B<T> { | 668 class A<T_B> extends B<T_B> { |
| 664 T f; | 669 T_B f; |
| 665 } | |
| 666 typedef void A_MyFunction<A_T extends num>(A_T arg); | |
| 667 class A_T {} | |
| 668 class A_B<A_T> {} | |
| 669 class A_A<A_T> extends A_B<A_T> { | |
| 670 A_T f; | |
| 671 } | 670 } |
| 672 main() { | 671 main() { |
| 673 A_MyFunction myf1; | 672 MyFunction myf1; |
| 674 MyFunction myf2; | 673 MyFunction_A myf2; |
| 675 new A_A<int>().f; | |
| 676 new A_T(); | |
| 677 new A<int>().f; | 674 new A<int>().f; |
| 678 new T(); | 675 new T(); |
| 676 new A_A<int>().f; |
| 677 new T_A(); |
| 679 } | 678 } |
| 680 '''; | 679 '''; |
| 681 testDart2DartWithLibrary(mainSrc, librarySrc, | 680 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 682 continuation: (String result) { Expect.equals(expectedResult, result); }); | 681 expectedResult: expectedResult); |
| 683 } | 682 } |
| 684 | 683 |
| 685 testClassTypeArgumentBound() { | 684 testClassTypeArgumentBound() { |
| 686 var librarySrc = ''' | 685 var librarySrc = ''' |
| 687 library mylib; | 686 library mylib; |
| 688 | 687 |
| 689 class I {} | 688 class I {} |
| 690 class A<T extends I> {} | 689 class A<T extends I> {} |
| 691 | 690 |
| 692 '''; | 691 '''; |
| 693 var mainSrc = ''' | 692 var mainSrc = ''' |
| 694 import 'mylib.dart' as mylib; | 693 import 'mylib.dart' as mylib; |
| 695 | 694 |
| 696 class I {} | 695 class I {} |
| 697 class A<T extends I> {} | 696 class A<T extends I> {} |
| 698 | 697 |
| 699 main() { | 698 main() { |
| 700 new A(); | 699 new A(); |
| 701 new mylib.A(); | 700 new mylib.A(); |
| 702 } | 701 } |
| 703 '''; | 702 '''; |
| 704 var expectedResult = ''' | 703 var expectedResult = ''' |
| 704 class I_A {} |
| 705 class A_A<T extends I_A> {} |
| 705 class I {} | 706 class I {} |
| 706 class A<T extends I> {} | 707 class A<T extends I> {} |
| 707 class A_I {} | |
| 708 class A_A<A_T extends A_I> {} | |
| 709 main() { | 708 main() { |
| 709 new A(); |
| 710 new A_A(); | 710 new A_A(); |
| 711 new A(); | |
| 712 } | 711 } |
| 713 '''; | 712 '''; |
| 714 testDart2DartWithLibrary(mainSrc, librarySrc, | 713 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 715 continuation: (String result) { Expect.equals(expectedResult, result); }); | 714 expectedResult: expectedResult); |
| 716 } | 715 } |
| 717 | 716 |
| 718 testDoubleMains() { | 717 testDoubleMains() { |
| 719 var librarySrc = ''' | 718 var librarySrc = ''' |
| 720 library mylib; | 719 library mylib; |
| 721 main() {} | 720 main() {} |
| 722 '''; | 721 '''; |
| 723 var mainSrc = ''' | 722 var mainSrc = ''' |
| 724 import 'mylib.dart' as mylib; | 723 import 'mylib.dart' as mylib; |
| 725 main() { | 724 main() { |
| 726 mylib.main(); | 725 mylib.main(); |
| 727 } | 726 } |
| 728 '''; | 727 '''; |
| 729 var expectedResult = ''' | 728 var expectedResult = ''' |
| 730 A_main() {} | 729 main_A() {} |
| 731 main() { | 730 main() { |
| 732 A_main(); | 731 main_A(); |
| 733 } | 732 } |
| 734 '''; | 733 '''; |
| 735 testDart2DartWithLibrary(mainSrc, librarySrc, | 734 testDart2Dart(mainSrc, librarySrc: librarySrc, |
| 736 continuation: (String result) { Expect.equals(expectedResult, result); }); | 735 expectedResult: expectedResult); |
| 737 } | 736 } |
| 738 | 737 |
| 739 testStaticAccessIoLib() { | 738 testStaticAccessIoLib() { |
| 740 var src = ''' | 739 var src = ''' |
| 741 import 'dart:io'; | 740 import 'dart:io'; |
| 742 | 741 |
| 743 main() { | 742 main() { |
| 744 Platform.operatingSystem; | 743 Platform.operatingSystem; |
| 745 } | 744 } |
| 746 '''; | 745 '''; |
| 747 var expectedResult = ''' | 746 var expectedResult = ''' |
| 748 import "dart:io" as p; | 747 import "dart:io"; |
| 749 main() { | 748 main() { |
| 750 p.Platform.operatingSystem; | 749 Platform.operatingSystem; |
| 751 } | 750 } |
| 752 '''; | 751 '''; |
| 753 testDart2Dart(src, | 752 testDart2Dart(src, expectedResult: expectedResult); |
| 754 continuation: (String result) { Expect.equals(expectedResult, result); }); | |
| 755 } | 753 } |
| 756 | 754 |
| 757 testMinification() { | 755 testMinification() { |
| 758 var src = ''' | 756 var src = ''' |
| 759 class ClassWithVeryVeryLongName {} | 757 class ClassWithVeryVeryLongName {} |
| 760 main() { | 758 main() { |
| 761 new ClassWithVeryVeryLongName(); | 759 new ClassWithVeryVeryLongName(); |
| 762 } | 760 } |
| 763 '''; | 761 '''; |
| 764 var expectedResult = | 762 var expectedResult = |
| 765 'class A{}' | 763 'class A{}' |
| 766 'main(){new A();}'; | 764 'main(){new A();}'; |
| 767 testDart2Dart(src, continuation: | 765 testDart2Dart(src, expectedResult: expectedResult, minify: true); |
| 768 (String result) { Expect.equals(expectedResult, result); }, minify: true); | |
| 769 } | 766 } |
| 770 | 767 |
| 771 testClosureLocalsMinified() { | 768 testClosureLocalsMinified() { |
| 772 var src = ''' | 769 var src = ''' |
| 773 main() { | 770 main() { |
| 774 var a = 7; | 771 var a = 7; |
| 775 void foo1(a,b) { | 772 void foo1(a,b) { |
| 776 void foo2(c,d) { | 773 void foo2(c,d) { |
| 777 var E = a; | 774 var E = a; |
| 778 } | 775 } |
| 779 foo2(b, a); | 776 foo2(b, a); |
| 780 } | 777 } |
| 781 foo1(a, 8); | 778 foo1(a, 8); |
| 782 } | 779 } |
| 783 '''; | 780 '''; |
| 784 var expectedResult = | 781 var expectedResult = |
| 785 'main(){var A=7; B(A,C){ D(E,F){var G=A;}D(C,A);}B(A,8);}'; | 782 'main(){var A=7; B(A,C){ D(E,F){var G=A;}D(C,A);}B(A,8);}'; |
| 786 testDart2Dart(src, continuation: | 783 testDart2Dart(src, expectedResult: expectedResult, minify: true); |
| 787 (String result) { Expect.equals(expectedResult, result); }, minify: true); | |
| 788 } | 784 } |
| 789 | 785 |
| 790 testParametersMinified() { | 786 testParametersMinified() { |
| 791 var src = ''' | 787 var src = ''' |
| 792 class A { | 788 class A { |
| 793 var a; | 789 var a; |
| 794 static foo(arg1) { | 790 static foo(arg1) { |
| 795 // Should not rename arg1 to a. | 791 // Should not rename arg1 to a. |
| 796 arg1 = 5; | 792 arg1 = 5; |
| 797 } | 793 } |
| 798 } | 794 } |
| 799 | 795 |
| 800 fooglobal(arg,{optionalarg: 7}) { | 796 fooglobal(arg,{optionalarg: 7}) { |
| 801 arg = 6; | 797 arg = 6; |
| 802 } | 798 } |
| 803 | 799 |
| 804 main() { | 800 main() { |
| 805 new A().a; | 801 new A().a; |
| 806 A.foo(8); | 802 A.foo(8); |
| 807 fooglobal(8); | 803 fooglobal(8); |
| 808 } | 804 } |
| 809 '''; | 805 '''; |
| 810 var expectedResult = | 806 var expectedResult = |
| 811 'class B{var E;static C(A){A=5;}}D(A,{optionalarg: 7}){A=6;}' | 807 'class B{var E;static C(A){A=5;}}D(A,{optionalarg: 7}){A=6;}' |
| 812 'main(){new B().E;B.C(8);D(8);}'; | 808 'main(){new B().E;B.C(8);D(8);}'; |
| 813 testDart2Dart(src, continuation: | 809 testDart2Dart(src, expectedResult: expectedResult, minify: true); |
| 814 (String result) { Expect.equals(expectedResult, result); }, minify: true); | |
| 815 } | 810 } |
| 816 | 811 |
| 817 testDeclarationTypePlaceholders() { | 812 testDeclarationTypePlaceholders() { |
| 818 var src = ''' | 813 var src = ''' |
| 819 String globalfield; | 814 String globalfield; |
| 820 const String globalconstfield; | 815 const String globalconstfield; |
| 821 | 816 |
| 822 void foo(String arg) {} | 817 void foo(String arg) {} |
| 823 | 818 |
| 824 main() { | 819 main() { |
| 825 String localvar; | 820 String localvar; |
| 826 foo("5"); | 821 foo("5"); |
| 827 } | 822 } |
| 828 '''; | 823 '''; |
| 829 var expectedResult = ''' | 824 var expectedResult = ''' |
| 830 foo( arg) {} | 825 foo( arg) {} |
| 831 main() { | 826 main() { |
| 832 var localvar; | 827 var localvar; |
| 833 foo("5"); | 828 foo("5"); |
| 834 } | 829 } |
| 835 '''; | 830 '''; |
| 836 testDart2Dart(src, | 831 testDart2Dart(src, expectedResult: expectedResult, stripTypes: true); |
| 837 continuation: (String result) { Expect.equals(expectedResult, result); }, | |
| 838 stripTypes: true); | |
| 839 } | 832 } |
| 840 | 833 |
| 841 testPlatformLibraryMemberNamesAreFixed() { | 834 testPlatformLibraryMemberNamesAreFixed() { |
| 842 var src = ''' | 835 var src = ''' |
| 843 import 'dart:html'; | 836 import 'dart:html'; |
| 844 | 837 |
| 845 class A { | 838 class A { |
| 846 static String get userAgent => window.navigator.userAgent; | 839 static String get userAgent => window.navigator.userAgent; |
| 847 } | 840 } |
| 848 | 841 |
| 849 main() { | 842 main() { |
| 850 A.userAgent; | 843 A.userAgent; |
| 851 } | 844 } |
| 852 '''; | 845 '''; |
| 853 var expectedResult = ''' | 846 var expectedResult = ''' |
| 854 import "dart:html" as p; | 847 import "dart:html"; |
| 855 class A { | 848 class A { |
| 856 static String get A_userAgent => p.window.navigator.userAgent; | 849 static String get userAgent_A => window.navigator.userAgent; |
| 857 } | 850 } |
| 858 main() { | 851 main() { |
| 859 A.A_userAgent; | 852 A.userAgent_A; |
| 860 } | 853 } |
| 861 '''; | 854 '''; |
| 862 testDart2Dart(src, | 855 testDart2Dart(src, expectedResult: expectedResult); |
| 863 continuation: (String result) { Expect.equals(expectedResult, result); }); | |
| 864 } | 856 } |
| 865 | 857 |
| 866 testConflictsWithCoreLib() { | 858 testConflictsWithCoreLib() { |
| 867 var src = ''' | 859 var src = ''' |
| 868 import 'dart:core' as fisk; | 860 import 'dart:core' as fisk; |
| 869 | 861 |
| 870 print(x) { throw 'fisk'; } | 862 print(x) { throw 'fisk'; } |
| 871 | 863 |
| 872 main() { | 864 main() { |
| 873 fisk.print('corelib'); | 865 fisk.print('corelib'); |
| 874 print('local'); | 866 print('local'); |
| 875 } | 867 } |
| 876 '''; | 868 '''; |
| 877 var expectedResult = """ | 869 var expectedResult = """ |
| 878 A_print(x) { | 870 print_A(x) { |
| 879 throw 'fisk'; | 871 throw 'fisk'; |
| 880 } | 872 } |
| 881 main() { | 873 main() { |
| 882 print('corelib'); | 874 print('corelib'); |
| 883 A_print('local'); | 875 print_A('local'); |
| 884 } | 876 } |
| 885 """; | 877 """; |
| 886 testDart2Dart(src, | 878 testDart2Dart(src, expectedResult: expectedResult); |
| 887 continuation: (String result) { Expect.equals(expectedResult, result); }); | |
| 888 } | 879 } |
| 889 | 880 |
| 890 testUnresolvedNamedConstructor() { | 881 testUnresolvedNamedConstructor() { |
| 891 var src = ''' | 882 var src = ''' |
| 892 class A { | 883 class A { |
| 893 A() {} | 884 A() {} |
| 894 } | 885 } |
| 895 | 886 |
| 896 main() { | 887 main() { |
| 897 new A(); | 888 new A(); |
| 898 new A.named(); | 889 new A.named(); |
| 899 } | 890 } |
| 900 '''; | 891 '''; |
| 901 var expectedResult = """ | 892 var expectedResult = """ |
| 902 class A { | 893 class A { |
| 903 A() {} | 894 A() {} |
| 904 } | 895 } |
| 905 main() { | 896 main() { |
| 906 new A(); | 897 new A(); |
| 907 new A_Unresolved(); | 898 new Unresolved_A(); |
| 908 } | 899 } |
| 909 """; | 900 """; |
| 910 testDart2Dart(src, | 901 testDart2Dart(src, expectedResult: expectedResult); |
| 911 continuation: (String result) { Expect.equals(expectedResult, result); }); | |
| 912 } | 902 } |
| 913 | 903 |
| 914 main() { | 904 main() { |
| 915 testSimpleFileUnparse(); | 905 testSimpleFileUnparse(); |
| 916 testTopLevelField(); | 906 testTopLevelField(); |
| 917 testSimpleTopLevelClass(); | 907 testSimpleTopLevelClass(); |
| 918 testClassWithSynthesizedConstructor(); | 908 testClassWithSynthesizedConstructor(); |
| 919 testClassWithMethod(); | 909 testClassWithMethod(); |
| 920 testExtendsImplements(); | 910 testExtendsImplements(); |
| 921 testVariableDefinitions(); | 911 testVariableDefinitions(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 934 testStaticAccessIoLib(); | 924 testStaticAccessIoLib(); |
| 935 testLocalFunctionPlaceholder(); | 925 testLocalFunctionPlaceholder(); |
| 936 testMinification(); | 926 testMinification(); |
| 937 testClosureLocalsMinified(); | 927 testClosureLocalsMinified(); |
| 938 testParametersMinified(); | 928 testParametersMinified(); |
| 939 testDeclarationTypePlaceholders(); | 929 testDeclarationTypePlaceholders(); |
| 940 testPlatformLibraryMemberNamesAreFixed(); | 930 testPlatformLibraryMemberNamesAreFixed(); |
| 941 testConflictsWithCoreLib(); | 931 testConflictsWithCoreLib(); |
| 942 testUnresolvedNamedConstructor(); | 932 testUnresolvedNamedConstructor(); |
| 943 } | 933 } |
| OLD | NEW |