Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(689)

Side by Side Diff: tests/compiler/dart2js/dart_backend_test.dart

Issue 10990053: [dart2dart] Force-compile top-level elements in libraries to get local members correctly. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 20 matching lines...) Expand all
31 } 31 }
32 '''; 32 ''';
33 33
34 const ioLib = r''' 34 const ioLib = r'''
35 #library('io'); 35 #library('io');
36 class Platform { 36 class Platform {
37 static int operatingSystem; 37 static int operatingSystem;
38 } 38 }
39 '''; 39 ''';
40 40
41 const htmlLib = r'''
42 #library('html');
43 Window __window;
44 Window get window() => __window;
45 abstract class Window {
46 abstract Navigator get navigator;
47 }
48 abstract class Navigator {
49 abstract String get userAgent;
50 }
51 ''';
52
41 testDart2Dart(String src, [void continuation(String s), bool minify = false, 53 testDart2Dart(String src, [void continuation(String s), bool minify = false,
42 bool cutDeclarationTypes = false]) { 54 bool cutDeclarationTypes = false]) {
43 // If continuation is not provided, check that source string remains the same. 55 // If continuation is not provided, check that source string remains the same.
44 if (continuation === null) { 56 if (continuation === null) {
45 continuation = (s) { Expect.equals(src, s); }; 57 continuation = (s) { Expect.equals(src, s); };
46 } 58 }
47 testDart2DartWithLibrary(src, '', continuation, minify, cutDeclarationTypes); 59 testDart2DartWithLibrary(src, '', continuation, minify, cutDeclarationTypes);
48 } 60 }
49 61
50 /** 62 /**
51 * Library name is assumed to be 'mylib' in 'mylib.dart' file. 63 * Library name is assumed to be 'mylib' in 'mylib.dart' file.
52 */ 64 */
53 testDart2DartWithLibrary( 65 testDart2DartWithLibrary(
54 String srcMain, String srcLibrary, 66 String srcMain, String srcLibrary,
55 [void continuation(String s), bool minify = false, 67 [void continuation(String s), bool minify = false,
56 bool cutDeclarationTypes = false]) { 68 bool cutDeclarationTypes = false]) {
57 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path); 69 fileUri(path) => new Uri.fromComponents(scheme: 'file', path: path);
58 70
59 final scriptUri = fileUri('script.dart'); 71 final scriptUri = fileUri('script.dart');
60 final libUri = fileUri('mylib.dart'); 72 final libUri = fileUri('mylib.dart');
61 73
62 provider(uri) { 74 provider(uri) {
63 if (uri == scriptUri) return new Future.immediate(srcMain); 75 if (uri == scriptUri) return new Future.immediate(srcMain);
64 if (uri.toString() == libUri.toString()) { 76 if (uri.toString() == libUri.toString()) {
65 return new Future.immediate(srcLibrary); 77 return new Future.immediate(srcLibrary);
66 } 78 }
67 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib); 79 if (uri.path.endsWith('/core.dart')) return new Future.immediate(coreLib);
68 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib); 80 if (uri.path.endsWith('/io.dart')) return new Future.immediate(ioLib);
81 // TODO(smok): The file should change to html_dartium at some point.
82 if (uri.path.endsWith('/html_dart2js.dart')) return new Future.immediate(htm lLib);
69 return new Future.immediate(''); 83 return new Future.immediate('');
70 } 84 }
71 85
72 handler(uri, begin, end, message, kind) { 86 handler(uri, begin, end, message, kind) {
73 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) { 87 if (kind === Diagnostic.ERROR || kind === Diagnostic.CRASH) {
74 Expect.fail('$uri: $begin-$end: $message [$kind]'); 88 Expect.fail('$uri: $begin-$end: $message [$kind]');
75 } 89 }
76 } 90 }
77 91
78 final options = <String>['--output-type=dart']; 92 final options = <String>['--output-type=dart'];
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 foo("5"); 748 foo("5");
735 } 749 }
736 '''; 750 ''';
737 var expectedResult = 751 var expectedResult =
738 ' foo( arg){}main(){var localvar;foo("5");}'; 752 ' foo( arg){}main(){var localvar;foo("5");}';
739 testDart2Dart(src, 753 testDart2Dart(src,
740 (String result) { Expect.equals(expectedResult, result); }, 754 (String result) { Expect.equals(expectedResult, result); },
741 cutDeclarationTypes: true); 755 cutDeclarationTypes: true);
742 } 756 }
743 757
758 testPlatformLibraryMemberNamesAreFixed() {
759 var src = '''
760 #import('dart:html');
761
762 class A {
763 static String get userAgent => window.navigator.userAgent;
764 }
765
766 main() {
767 A.userAgent;
768 }
769 ''';
770 var expectedResult = '#import("dart:html",prefix:"p");'
771 'class A{static String get userAgent=>p.window.navigator.userAgent;}'
772 'main(){A.userAgent;}';
773 testDart2Dart(src,
774 (String result) { Expect.equals(expectedResult, result); });
775 }
776
744 main() { 777 main() {
745 testSimpleFileUnparse(); 778 testSimpleFileUnparse();
746 testTopLevelField(); 779 testTopLevelField();
747 testSimpleTopLevelClass(); 780 testSimpleTopLevelClass();
748 testClassWithSynthesizedConstructor(); 781 testClassWithSynthesizedConstructor();
749 testClassWithMethod(); 782 testClassWithMethod();
750 testExtendsImplements(); 783 testExtendsImplements();
751 testVariableDefinitions(); 784 testVariableDefinitions();
752 testGetSet(); 785 testGetSet();
753 testFactoryConstructor(); 786 testFactoryConstructor();
(...skipping 12 matching lines...) Expand all
766 testClassTypeArgumentBound(); 799 testClassTypeArgumentBound();
767 testDoubleMains(); 800 testDoubleMains();
768 testInterfaceDefaultAnotherLib(); 801 testInterfaceDefaultAnotherLib();
769 testStaticAccessIoLib(); 802 testStaticAccessIoLib();
770 testLocalFunctionPlaceholder(); 803 testLocalFunctionPlaceholder();
771 testMinification(); 804 testMinification();
772 testClosureLocalsMinified(); 805 testClosureLocalsMinified();
773 testParametersMinified(); 806 testParametersMinified();
774 testTypeVariablesInDifferentLibraries(); 807 testTypeVariablesInDifferentLibraries();
775 testDeclarationTypePlaceholders(); 808 testDeclarationTypePlaceholders();
809 testPlatformLibraryMemberNamesAreFixed();
776 } 810 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698