Chromium Code Reviews| 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(); |
| } |