Chromium Code Reviews| Index: frog/tests/leg/src/ResolverTest.dart |
| diff --git a/frog/tests/leg/src/ResolverTest.dart b/frog/tests/leg/src/ResolverTest.dart |
| index 481f3c820290e821699a40710585bf6e6ac32692..d2ab700edf0095a913a138146a5320eac97dc683 100644 |
| --- a/frog/tests/leg/src/ResolverTest.dart |
| +++ b/frog/tests/leg/src/ResolverTest.dart |
| @@ -64,6 +64,7 @@ main() { |
| testFunctionExpression(); |
| testNewExpression(); |
| testTopLevelFields(); |
| + testInitializers(); |
| } |
| testLocalsOne() { |
| @@ -378,6 +379,77 @@ testTopLevelFields() { |
| Expect.isTrue(bNode.modifiers.isVar()); |
| } |
| +resolveConstructor(String script, String statement, String className, |
| + String constructor, int expectedElementCount, |
| + [List expectedWarnings = const [], |
| + List expectedErrors = const []]) { |
| + MockCompiler compiler = new MockCompiler(); |
| + compiler.parseScript(script); |
| + compiler.resolveStatement(statement); |
| + ClassElement classElement = |
| + compiler.universe.find(buildSourceString(className)); |
| + Element element = |
| + classElement.lookupLocalElement(buildSourceString(constructor)); |
| + FunctionExpression tree = element.parseNode(compiler, compiler); |
| + ResolverVisitor visitor = new SignatureResolverVisitor(compiler, element); |
| + visitor.visit(tree); |
| + Expect.equals(expectedElementCount, visitor.mapping.map.length); |
| + |
| + visitor = new FullResolverVisitor.from(visitor); |
| + for (Link<Node> link = tree.initializers.nodes; |
| + !link.isEmpty(); |
| + link = link.tail) { |
| + if (link.head.asSendSet() != null) { |
| + SendSet init = link.head; |
| + Node value = init.arguments.head; |
| + visitor.visitInStaticContext(value); |
| + } else { |
| + // TODO(karlklose): super(...), this(...). |
| + Expect.fail('SendSet expected'); |
| + } |
| + } |
| + |
| + compareWarningKinds(script, expectedWarnings, compiler.warnings); |
| + compareWarningKinds(script, expectedErrors, compiler.errors); |
| +} |
| + |
| +testInitializers() { |
| + String script; |
| + script = """class A { |
| + int foo; int bar; |
| + A() : this.foo = 1, bar = 2; |
| + }"""; |
| + resolveConstructor(script, "A a = new A();", "A", "A", 3); |
| + |
| + script = """class A { |
| + int foo; A a; |
| + A() : a.foo = 1; |
| + }"""; |
| + resolveConstructor(script, "A a = new A();", "A", "A", 2, |
| + [], [MessageKind.INVALID_RECEIVER_IN_INITIALIZER]); |
| + |
| + script = """class A { |
| + int foo; |
| + A() : this.foo = 1, this.foo = 2; |
| + }"""; |
| + resolveConstructor(script, "A a = new A();", "A", "A", 3, |
| + [MessageKind.DUPLICATE_INITIALIZER]); |
|
ahe
2011/12/21 12:01:58
I expected two diagnostics here:
foo.dart:line:co
karlklose
2011/12/21 16:33:46
Done.
|
| + |
| + script = """class A { |
| + A() : this.foo = 1; |
| + }"""; |
| + resolveConstructor(script, "A a = new A();", "A", "A", 1, |
| + [], [MessageKind.CANNOT_RESOLVE]); |
| + |
| + script = """class A { |
| + int foo; |
| + int bar; |
| + A() : this.foo = bar; |
| + }"""; |
| + resolveConstructor(script, "A a = new A();", "A", "A", 2, |
| + [], [MessageKind.CANNOT_RESOLVE]); |
| +} |
| + |
| length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; |
| at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); |