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"); |
| 11 #import("../../../lib/compiler/implementation/elements/elements.dart"); | 11 #import("../../../lib/compiler/implementation/elements/elements.dart"); |
| 12 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart"); | |
|
Anton Muhin
2012/08/28 13:39:45
why?
Roman
2012/08/28 14:48:55
Thanks, now obsolete.
| |
| 12 #import("../../../lib/compiler/implementation/tree/tree.dart"); | 13 #import("../../../lib/compiler/implementation/tree/tree.dart"); |
| 13 | 14 |
| 14 testUnparse(String statement) { | 15 testUnparse(String statement) { |
| 15 Node node = parseStatement(statement); | 16 Node node = parseStatement(statement); |
| 16 Expect.equals(statement, node.unparse()); | 17 Expect.equals(statement, node.unparse()); |
| 17 } | 18 } |
| 18 | 19 |
| 19 testUnparseMember(String member) { | 20 testUnparseMember(String member) { |
| 20 Node node = parseMember(member); | 21 Node node = parseMember(member); |
| 21 Expect.equals(member, node.unparse()); | 22 Expect.equals(member, node.unparse()); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 40 } | 41 } |
| 41 '''; | 42 '''; |
| 42 | 43 |
| 43 const ioLib = @''' | 44 const ioLib = @''' |
| 44 #library('io'); | 45 #library('io'); |
| 45 class Platform { | 46 class Platform { |
| 46 static int operatingSystem; | 47 static int operatingSystem; |
| 47 } | 48 } |
| 48 '''; | 49 '''; |
| 49 | 50 |
| 50 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]) { | |
| 51 // 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. |
| 52 if (continuation === null) { | 54 if (continuation === null) { |
| 53 continuation = (s) { Expect.equals(src, s); }; | 55 continuation = (s) { Expect.equals(src, s); }; |
| 54 } | 56 } |
| 55 testDart2DartWithLibrary(src, '', continuation, minify); | 57 testDart2DartWithLibrary(src, '', continuation, minify, cutDeclarationTypes); |
| 56 } | 58 } |
| 57 | 59 |
| 58 /** | 60 /** |
| 59 * Library name is assumed to be 'mylib' in 'mylib.dart' file. | 61 * Library name is assumed to be 'mylib' in 'mylib.dart' file. |
| 60 */ | 62 */ |
| 61 testDart2DartWithLibrary( | 63 testDart2DartWithLibrary( |
| 62 String srcMain, String srcLibrary, | 64 String srcMain, String srcLibrary, |
| 63 [void continuation(String s), bool minify = false]) { | 65 [void continuation(String s), bool minify = false, |
| 66 bool cutDeclarationTypes = false]) { | |
| 64 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); | 67 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); |
| 65 | 68 |
| 66 final scriptUri = fileUri('script.dart'); | 69 final scriptUri = fileUri('script.dart'); |
| 67 final libUri = fileUri('mylib.dart'); | 70 final libUri = fileUri('mylib.dart'); |
| 68 | 71 |
| 69 provider(uri) { | 72 provider(uri) { |
| 70 if (uri == scriptUri) return new Future.immediate(srcMain); | 73 if (uri == scriptUri) return new Future.immediate(srcMain); |
| 71 if (uri.toString() == libUri.toString()) { | 74 if (uri.toString() == libUri.toString()) { |
| 72 return new Future.immediate(srcLibrary); | 75 return new Future.immediate(srcLibrary); |
| 73 } | 76 } |
| 74 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); | 77 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); |
| 75 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); | 78 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); |
| 76 return new Future.immediate(''); | 79 return new Future.immediate(''); |
| 77 } | 80 } |
| 78 | 81 |
| 79 handler(uri, begin, end, message, kind) { | 82 handler(uri, begin, end, message, kind) { |
| 80 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { | 83 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { |
| 81 Expect.fail('$uri: $begin-$end: $message [$kind]'); | 84 Expect.fail('$uri: $begin-$end: $message [$kind]'); |
| 82 } | 85 } |
| 83 } | 86 } |
| 84 | 87 |
| 85 final options = <String>['--output-type=dart']; | 88 final options = <String>['--output-type=dart']; |
| 86 if (minify) options.add('--minify'); | 89 if (minify) options.add('--minify'); |
| 90 if (cutDeclarationTypes) options.add('--cutDeclarationTypes'); | |
| 87 | 91 |
| 88 compile( | 92 compile( |
| 89 scriptUri, | 93 scriptUri, |
| 90 fileUri('libraryRoot'), | 94 fileUri('libraryRoot'), |
| 91 fileUri('packageRoot'), | 95 fileUri('packageRoot'), |
| 92 provider, | 96 provider, |
| 93 handler, | 97 handler, |
| 94 options).then(continuation); | 98 options).then(continuation); |
| 95 } | 99 } |
| 96 | 100 |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 774 '''; | 778 '''; |
| 775 var expectedResult = | 779 var expectedResult = |
| 776 'interface Iterable<K>{}' | 780 'interface Iterable<K>{}' |
| 777 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}' | 781 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}' |
| 778 'class LinkFactory<T>{factory Link(){}}' | 782 'class LinkFactory<T>{factory Link(){}}' |
| 779 'main(){new Link<int>();}'; | 783 'main(){new Link<int>();}'; |
| 780 testDart2DartWithLibrary(mainSrc, librarySrc, | 784 testDart2DartWithLibrary(mainSrc, librarySrc, |
| 781 (String result) { Expect.equals(expectedResult, result); }); | 785 (String result) { Expect.equals(expectedResult, result); }); |
| 782 } | 786 } |
| 783 | 787 |
| 788 testDeclarationTypePlaceholders() { | |
| 789 var src = ''' | |
| 790 String globalfield; | |
| 791 const String globalconstfield; | |
| 792 | |
| 793 void foo(String arg) {} | |
| 794 | |
| 795 main() { | |
| 796 String localvar; | |
| 797 foo("5"); | |
| 798 } | |
| 799 '''; | |
| 800 var expectedResult = | |
| 801 ' foo( arg){}main(){var localvar; foo("5");}'; | |
| 802 testDart2Dart(src, | |
| 803 (String result) { Expect.equals(expectedResult, result); }, | |
| 804 cutDeclarationTypes: true); | |
| 805 } | |
| 806 | |
| 784 main() { | 807 main() { |
| 785 testSignedConstants(); | 808 testSignedConstants(); |
| 786 testGenericTypes(); | 809 testGenericTypes(); |
| 787 testForLoop(); | 810 testForLoop(); |
| 788 testEmptyList(); | 811 testEmptyList(); |
| 789 testClosure(); | 812 testClosure(); |
| 790 testIndexedOperatorDecl(); | 813 testIndexedOperatorDecl(); |
| 791 testNativeMethods(); | 814 testNativeMethods(); |
| 792 testPrefixIncrements(); | 815 testPrefixIncrements(); |
| 793 testConstModifier(); | 816 testConstModifier(); |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 815 testTypeVariablesAreRenamed(); | 838 testTypeVariablesAreRenamed(); |
| 816 testClassTypeArgumentBound(); | 839 testClassTypeArgumentBound(); |
| 817 testDoubleMains(); | 840 testDoubleMains(); |
| 818 testInterfaceDefaultAnotherLib(); | 841 testInterfaceDefaultAnotherLib(); |
| 819 testStaticAccessIoLib(); | 842 testStaticAccessIoLib(); |
| 820 testLocalFunctionPlaceholder(); | 843 testLocalFunctionPlaceholder(); |
| 821 testMinification(); | 844 testMinification(); |
| 822 testClosureLocalsMinified(); | 845 testClosureLocalsMinified(); |
| 823 testParametersMinified(); | 846 testParametersMinified(); |
| 824 testTypeVariablesInDifferentLibraries(); | 847 testTypeVariablesInDifferentLibraries(); |
| 848 testDeclarationTypePlaceholders(); | |
| 825 } | 849 } |
| OLD | NEW |