| 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 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 '''; | 41 '''; |
| 42 | 42 |
| 43 final ioLib = @''' | 43 final 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)]) { | 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); }; |
| 54 } | 54 } |
| 55 testDart2DartWithLibrary(src, '', continuation); | 55 testDart2DartWithLibrary(src, '', continuation, minify); |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 59 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 60 */ | 60 */ |
| 61 testDart2DartWithLibrary( | 61 testDart2DartWithLibrary( |
| 62 String srcMain, String srcLibrary, [void continuation(String s)]) { | 62 String srcMain, String srcLibrary, |
| 63 [void continuation(String s), bool minify = false]) { |
| 63 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); | 64 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); |
| 64 | 65 |
| 65 final scriptUri = fileUri('script.dart'); | 66 final scriptUri = fileUri('script.dart'); |
| 66 final libUri = fileUri('mylib.dart'); | 67 final libUri = fileUri('mylib.dart'); |
| 67 | 68 |
| 68 provider(uri) { | 69 provider(uri) { |
| 69 if (uri == scriptUri) return new Future.immediate(srcMain); | 70 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 70 if (uri.toString() == libUri.toString()) { | 71 if (uri.toString() == libUri.toString()) { |
| 71 return new Future.immediate(srcLibrary); | 72 return new Future.immediate(srcLibrary); |
| 72 } | 73 } |
| 73 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 74 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 74 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); | 75 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); |
| 75 return new Future.immediate(''); | 76 return new Future.immediate(''); |
| 76 } | 77 } |
| 77 | 78 |
| 78 handler(uri, begin, end, message, kind) { | 79 handler(uri, begin, end, message, kind) { |
| 79 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 80 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 80 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 81 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 81 } | 82 } |
| 82 } | 83 } |
| 83 | 84 |
| 85 final options = <String>['--output-type=dart']; |
| 86 if (minify) options.add('--minify'); |
| 87 |
| 84 compile( | 88 compile( |
| 85 scriptUri, | 89 scriptUri, |
| 86 fileUri('libraryRoot'), | 90 fileUri('libraryRoot'), |
| 87 fileUri('packageRoot'), | 91 fileUri('packageRoot'), |
| 88 provider, | 92 provider, |
| 89 handler, | 93 handler, |
| 90 const ['--output-type=dart']).then(continuation); | 94 options).then(continuation); |
| 91 } | 95 } |
| 92 | 96 |
| 93 testSignedConstants() { | 97 testSignedConstants() { |
| 94 testUnparse('var x=+42;'); | 98 testUnparse('var x=+42;'); |
| 95 testUnparse('var x=+.42;'); | 99 testUnparse('var x=+.42;'); |
| 96 testUnparse('var x=-42;'); | 100 testUnparse('var x=-42;'); |
| 97 testUnparse('var x=-.42;'); | 101 testUnparse('var x=-.42;'); |
| 98 testUnparse('var x=+0;'); | 102 testUnparse('var x=+0;'); |
| 99 testUnparse('var x=+0.0;'); | 103 testUnparse('var x=+0.0;'); |
| 100 testUnparse('var x=+.0;'); | 104 testUnparse('var x=+.0;'); |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 main() { | 671 main() { |
| 668 Platform.operatingSystem; | 672 Platform.operatingSystem; |
| 669 } | 673 } |
| 670 '''; | 674 '''; |
| 671 var expectedResult = '#import("dart:io", prefix: "p");' | 675 var expectedResult = '#import("dart:io", prefix: "p");' |
| 672 'main(){p.Platform.operatingSystem;}'; | 676 'main(){p.Platform.operatingSystem;}'; |
| 673 testDart2Dart(src, | 677 testDart2Dart(src, |
| 674 (String result) { Expect.equals(expectedResult, result); }); | 678 (String result) { Expect.equals(expectedResult, result); }); |
| 675 } | 679 } |
| 676 | 680 |
| 681 testMinification() { |
| 682 var src = ''' |
| 683 class ClassWithVeryVeryLongName {} |
| 684 main() { |
| 685 new ClassWithVeryVeryLongName(); |
| 686 } |
| 687 '''; |
| 688 var expectedResult = |
| 689 'class A{}' |
| 690 'main(){new A();}'; |
| 691 testDart2Dart(src, |
| 692 (String result) { Expect.equals(expectedResult, result); }, minify: true); |
| 693 } |
| 694 |
| 677 main() { | 695 main() { |
| 678 testSignedConstants(); | 696 testSignedConstants(); |
| 679 testGenericTypes(); | 697 testGenericTypes(); |
| 680 testForLoop(); | 698 testForLoop(); |
| 681 testEmptyList(); | 699 testEmptyList(); |
| 682 testClosure(); | 700 testClosure(); |
| 683 testIndexedOperatorDecl(); | 701 testIndexedOperatorDecl(); |
| 684 testNativeMethods(); | 702 testNativeMethods(); |
| 685 testPrefixIncrements(); | 703 testPrefixIncrements(); |
| 686 testConstModifier(); | 704 testConstModifier(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 704 testLibraryGetSet(); | 722 testLibraryGetSet(); |
| 705 testFieldTypeOutput(); | 723 testFieldTypeOutput(); |
| 706 testDefaultClassNamePlaceholder(); | 724 testDefaultClassNamePlaceholder(); |
| 707 testFactoryRename(); | 725 testFactoryRename(); |
| 708 testTypeVariablesAreRenamed(); | 726 testTypeVariablesAreRenamed(); |
| 709 testClassTypeArgumentBound(); | 727 testClassTypeArgumentBound(); |
| 710 testDoubleMains(); | 728 testDoubleMains(); |
| 711 testInterfaceDefaultAnotherLib(); | 729 testInterfaceDefaultAnotherLib(); |
| 712 testStaticAccessIoLib(); | 730 testStaticAccessIoLib(); |
| 713 testLocalFunctionPlaceholder(); | 731 testLocalFunctionPlaceholder(); |
| 732 testMinification(); |
| 714 } | 733 } |
| OLD | NEW |