| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 '''; | 42 '''; |
| 43 | 43 |
| 44 const ioLib = r''' | 44 const ioLib = r''' |
| 45 #library('io'); | 45 #library('io'); |
| 46 class Platform { | 46 class Platform { |
| 47 static int operatingSystem; | 47 static int operatingSystem; |
| 48 } | 48 } |
| 49 '''; | 49 '''; |
| 50 | 50 |
| 51 testDart2Dart(String src, [void continuation(String s), bool minify = false, | 51 testDart2Dart(String src, [void continuation(String s), bool minify = false, |
| 52 bool cutDeclarationTypes = false]) { | 52 bool stripTypes = false]) { |
| 53 // If continuation is not provided, check that source string remains the same. | 53 // If continuation is not provided, check that source string remains the same. |
| 54 if (continuation === null) { | 54 if (continuation === null) { |
| 55 continuation = (s) { Expect.equals(src, s); }; | 55 continuation = (s) { Expect.equals(src, s); }; |
| 56 } | 56 } |
| 57 testDart2DartWithLibrary(src, '', continuation, minify, cutDeclarationTypes); | 57 testDart2DartWithLibrary(src, '', continuation, minify, stripTypes); |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** | 60 /** |
| 61 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 61 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 62 */ | 62 */ |
| 63 testDart2DartWithLibrary( | 63 testDart2DartWithLibrary( |
| 64 String srcMain, String srcLibrary, | 64 String srcMain, String srcLibrary, |
| 65 [void continuation(String s), bool minify = false, | 65 [void continuation(String s), bool minify = false, |
| 66 bool cutDeclarationTypes = false]) { | 66 bool stripTypes = false]) { |
| 67 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); | 67 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); |
| 68 | 68 |
| 69 final scriptUri = fileUri('script.dart'); | 69 final scriptUri = fileUri('script.dart'); |
| 70 final libUri = fileUri('mylib.dart'); | 70 final libUri = fileUri('mylib.dart'); |
| 71 | 71 |
| 72 provider(uri) { | 72 provider(uri) { |
| 73 if (uri == scriptUri) return new Future.immediate(srcMain); | 73 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 74 if (uri.toString() == libUri.toString()) { | 74 if (uri.toString() == libUri.toString()) { |
| 75 return new Future.immediate(srcLibrary); | 75 return new Future.immediate(srcLibrary); |
| 76 } | 76 } |
| 77 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 77 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 78 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); | 78 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); |
| 79 return new Future.immediate(''); | 79 return new Future.immediate(''); |
| 80 } | 80 } |
| 81 | 81 |
| 82 handler(uri, begin, end, message, kind) { | 82 handler(uri, begin, end, message, kind) { |
| 83 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 83 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 84 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 84 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 85 } | 85 } |
| 86 } | 86 } |
| 87 | 87 |
| 88 final options = <String>['--output-type=dart']; | 88 final options = <String>['--output-type=dart']; |
| 89 if (minify) options.add('--minify'); | 89 if (minify) options.add('--minify'); |
| 90 if (cutDeclarationTypes) options.add('--force-cut-declaration-types'); | 90 if (stripTypes) options.add('--force-strip=types'); |
| 91 | 91 |
| 92 compile( | 92 compile( |
| 93 scriptUri, | 93 scriptUri, |
| 94 fileUri('libraryRoot'), | 94 fileUri('libraryRoot'), |
| 95 fileUri('packageRoot'), | 95 fileUri('packageRoot'), |
| 96 provider, | 96 provider, |
| 97 handler, | 97 handler, |
| 98 options).then(continuation); | 98 options).then(continuation); |
| 99 } | 99 } |
| 100 | 100 |
| (...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 | 802 |
| 803 main() { | 803 main() { |
| 804 String localvar; | 804 String localvar; |
| 805 foo("5"); | 805 foo("5"); |
| 806 } | 806 } |
| 807 '''; | 807 '''; |
| 808 var expectedResult = | 808 var expectedResult = |
| 809 ' foo( arg){}main(){var localvar;foo("5");}'; | 809 ' foo( arg){}main(){var localvar;foo("5");}'; |
| 810 testDart2Dart(src, | 810 testDart2Dart(src, |
| 811 (String result) { Expect.equals(expectedResult, result); }, | 811 (String result) { Expect.equals(expectedResult, result); }, |
| 812 cutDeclarationTypes: true); | 812 stripTypes: true); |
| 813 } | 813 } |
| 814 | 814 |
| 815 main() { | 815 main() { |
| 816 testSignedConstants(); | 816 testSignedConstants(); |
| 817 testGenericTypes(); | 817 testGenericTypes(); |
| 818 testForLoop(); | 818 testForLoop(); |
| 819 testEmptyList(); | 819 testEmptyList(); |
| 820 testClosure(); | 820 testClosure(); |
| 821 testIndexedOperatorDecl(); | 821 testIndexedOperatorDecl(); |
| 822 testNativeMethods(); | 822 testNativeMethods(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 848 testDoubleMains(); | 848 testDoubleMains(); |
| 849 testInterfaceDefaultAnotherLib(); | 849 testInterfaceDefaultAnotherLib(); |
| 850 testStaticAccessIoLib(); | 850 testStaticAccessIoLib(); |
| 851 testLocalFunctionPlaceholder(); | 851 testLocalFunctionPlaceholder(); |
| 852 testMinification(); | 852 testMinification(); |
| 853 testClosureLocalsMinified(); | 853 testClosureLocalsMinified(); |
| 854 testParametersMinified(); | 854 testParametersMinified(); |
| 855 testTypeVariablesInDifferentLibraries(); | 855 testTypeVariablesInDifferentLibraries(); |
| 856 testDeclarationTypePlaceholders(); | 856 testDeclarationTypePlaceholders(); |
| 857 } | 857 } |
| OLD | NEW |