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

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

Issue 10891004: [dart2dart] Optionally cut types in variable declarations: (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 3 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
« no previous file with comments | « lib/compiler/implementation/dart_backend/renamer.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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");
11 #import("../../../lib/compiler/implementation/elements/elements.dart"); 11 #import("../../../lib/compiler/implementation/elements/elements.dart");
12 #import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
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 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
774 '''; 775 ''';
775 var expectedResult = 776 var expectedResult =
776 'interface Iterable<K>{}' 777 'interface Iterable<K>{}'
777 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}' 778 'interface Link<T> extends Iterable<T> default LinkFactory<T>{Link();}'
778 'class LinkFactory<T>{factory Link(){}}' 779 'class LinkFactory<T>{factory Link(){}}'
779 'main(){new Link<int>();}'; 780 'main(){new Link<int>();}';
780 testDart2DartWithLibrary(mainSrc, librarySrc, 781 testDart2DartWithLibrary(mainSrc, librarySrc,
781 (String result) { Expect.equals(expectedResult, result); }); 782 (String result) { Expect.equals(expectedResult, result); });
782 } 783 }
783 784
785 testDeclarationTypePlaceholders() {
Anton Muhin 2012/08/28 13:06:32 why some complicated? why not pass a flag to omit
Roman 2012/08/28 13:27:51 Done.
786 var src = '''
787 String globalfield;
788 const String globalconstfield;
789
790 void foo(String arg) {}
791
792 main() {
793 String localvar;
794 foo('5');
795 }
796 ''';
797 MockCompiler compiler = new MockCompiler();
798 compiler.parseScript(src);
799 FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN);
800 compiler.processQueue(compiler.enqueuer.resolution, mainElement);
801 PlaceholderCollector collector = new PlaceholderCollector(compiler);
802 FunctionExpression mainNode = mainElement.parseNode(compiler);
803
804 bool collectorHasDeclarationTypePlaceholder(
805 TypeAnnotation type, bool requiresVar) {
806 for (DeclarationTypePlaceholder placeholder
807 in collector.declarationTypePlaceholders) {
808 if (placeholder.typeNode == type) {
809 Expect.equals(requiresVar, placeholder.requiresVar);
810 return true;
811 }
812 }
813 return false;
814 }
815
816 collector.collect(mainElement,
817 compiler.enqueuer.resolution.resolvedElements[mainElement]);
818 VariableDefinitions localVarNode = mainNode.body.statements.nodes.head;
819 Expect.isTrue(
820 collectorHasDeclarationTypePlaceholder(localVarNode.type, true));
821
822 FunctionElement fooElement = compiler.mainApp.find(new SourceString('foo'));
823 collector.collect(fooElement,
824 compiler.enqueuer.resolution.resolvedElements[fooElement]);
825 FunctionExpression fooNode = fooElement.cachedNode;
826 Expect.isTrue(
827 collectorHasDeclarationTypePlaceholder(fooNode.returnType, false));
828 VariableDefinitions fooParamNode = fooNode.parameters.nodes.head;
829 Expect.isTrue(
830 collectorHasDeclarationTypePlaceholder(fooParamNode.type, false));
831
832 VariableElement globalFieldElement =
833 compiler.mainApp.find(new SourceString('globalfield'));
834 collector.collect(globalFieldElement, new leg.TreeElementMapping());
835 VariableDefinitions globalFieldNode = globalFieldElement.variables.cachedNode;
836 Expect.isTrue(
837 collectorHasDeclarationTypePlaceholder(globalFieldNode.type, true));
838
839 globalFieldElement = compiler.mainApp.find(
840 new SourceString('globalconstfield'));
841 collector.collect(globalFieldElement, new leg.TreeElementMapping());
842 globalFieldNode = globalFieldElement.variables.cachedNode;
843 Expect.isTrue(
844 collectorHasDeclarationTypePlaceholder(globalFieldNode.type, false));
845 }
846
784 main() { 847 main() {
785 testSignedConstants(); 848 testSignedConstants();
786 testGenericTypes(); 849 testGenericTypes();
787 testForLoop(); 850 testForLoop();
788 testEmptyList(); 851 testEmptyList();
789 testClosure(); 852 testClosure();
790 testIndexedOperatorDecl(); 853 testIndexedOperatorDecl();
791 testNativeMethods(); 854 testNativeMethods();
792 testPrefixIncrements(); 855 testPrefixIncrements();
793 testConstModifier(); 856 testConstModifier();
(...skipping 21 matching lines...) Expand all
815 testTypeVariablesAreRenamed(); 878 testTypeVariablesAreRenamed();
816 testClassTypeArgumentBound(); 879 testClassTypeArgumentBound();
817 testDoubleMains(); 880 testDoubleMains();
818 testInterfaceDefaultAnotherLib(); 881 testInterfaceDefaultAnotherLib();
819 testStaticAccessIoLib(); 882 testStaticAccessIoLib();
820 testLocalFunctionPlaceholder(); 883 testLocalFunctionPlaceholder();
821 testMinification(); 884 testMinification();
822 testClosureLocalsMinified(); 885 testClosureLocalsMinified();
823 testParametersMinified(); 886 testParametersMinified();
824 testTypeVariablesInDifferentLibraries(); 887 testTypeVariablesInDifferentLibraries();
888 testDeclarationTypePlaceholders();
825 } 889 }
OLDNEW
« no previous file with comments | « lib/compiler/implementation/dart_backend/renamer.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698