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

Unified 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, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/dart_backend/renamer.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/unparser_test.dart
diff --git a/tests/compiler/dart2js/unparser_test.dart b/tests/compiler/dart2js/unparser_test.dart
index 7eda5fdf597507cde94d9f58b6f028c84d837603..26cc3c8eae042d30d1db29e55aeb52a2ef81a5e2 100644
--- a/tests/compiler/dart2js/unparser_test.dart
+++ b/tests/compiler/dart2js/unparser_test.dart
@@ -9,6 +9,7 @@
#import("../../../lib/compiler/implementation/leg.dart", prefix:'leg');
#import("../../../lib/compiler/implementation/dart_backend/dart_backend.dart");
#import("../../../lib/compiler/implementation/elements/elements.dart");
+#import("../../../lib/compiler/implementation/scanner/scannerlib.dart");
#import("../../../lib/compiler/implementation/tree/tree.dart");
testUnparse(String statement) {
@@ -781,6 +782,68 @@ main() {
(String result) { Expect.equals(expectedResult, result); });
}
+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.
+ var src = '''
+String globalfield;
+const String globalconstfield;
+
+void foo(String arg) {}
+
+main() {
+ String localvar;
+ foo('5');
+}
+''';
+ MockCompiler compiler = new MockCompiler();
+ compiler.parseScript(src);
+ FunctionElement mainElement = compiler.mainApp.find(leg.Compiler.MAIN);
+ compiler.processQueue(compiler.enqueuer.resolution, mainElement);
+ PlaceholderCollector collector = new PlaceholderCollector(compiler);
+ FunctionExpression mainNode = mainElement.parseNode(compiler);
+
+ bool collectorHasDeclarationTypePlaceholder(
+ TypeAnnotation type, bool requiresVar) {
+ for (DeclarationTypePlaceholder placeholder
+ in collector.declarationTypePlaceholders) {
+ if (placeholder.typeNode == type) {
+ Expect.equals(requiresVar, placeholder.requiresVar);
+ return true;
+ }
+ }
+ return false;
+ }
+
+ collector.collect(mainElement,
+ compiler.enqueuer.resolution.resolvedElements[mainElement]);
+ VariableDefinitions localVarNode = mainNode.body.statements.nodes.head;
+ Expect.isTrue(
+ collectorHasDeclarationTypePlaceholder(localVarNode.type, true));
+
+ FunctionElement fooElement = compiler.mainApp.find(new SourceString('foo'));
+ collector.collect(fooElement,
+ compiler.enqueuer.resolution.resolvedElements[fooElement]);
+ FunctionExpression fooNode = fooElement.cachedNode;
+ Expect.isTrue(
+ collectorHasDeclarationTypePlaceholder(fooNode.returnType, false));
+ VariableDefinitions fooParamNode = fooNode.parameters.nodes.head;
+ Expect.isTrue(
+ collectorHasDeclarationTypePlaceholder(fooParamNode.type, false));
+
+ VariableElement globalFieldElement =
+ compiler.mainApp.find(new SourceString('globalfield'));
+ collector.collect(globalFieldElement, new leg.TreeElementMapping());
+ VariableDefinitions globalFieldNode = globalFieldElement.variables.cachedNode;
+ Expect.isTrue(
+ collectorHasDeclarationTypePlaceholder(globalFieldNode.type, true));
+
+ globalFieldElement = compiler.mainApp.find(
+ new SourceString('globalconstfield'));
+ collector.collect(globalFieldElement, new leg.TreeElementMapping());
+ globalFieldNode = globalFieldElement.variables.cachedNode;
+ Expect.isTrue(
+ collectorHasDeclarationTypePlaceholder(globalFieldNode.type, false));
+}
+
main() {
testSignedConstants();
testGenericTypes();
@@ -822,4 +885,5 @@ main() {
testClosureLocalsMinified();
testParametersMinified();
testTypeVariablesInDifferentLibraries();
+ testDeclarationTypePlaceholders();
}
« 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