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

Side by Side Diff: frog/tests/leg/src/ResolverTest.dart

Issue 9166010: Implement super calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments. Created 8 years, 11 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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("../../../leg/leg.dart"); 5 #import("../../../leg/leg.dart");
6 #import("../../../leg/elements/elements.dart"); 6 #import("../../../leg/elements/elements.dart");
7 #import("../../../leg/tree/tree.dart"); 7 #import("../../../leg/tree/tree.dart");
8 #import("../../../leg/util/util.dart"); 8 #import("../../../leg/util/util.dart");
9 #import("mock_compiler.dart"); 9 #import("mock_compiler.dart");
10 #import("parser_helper.dart"); 10 #import("parser_helper.dart");
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 testTypeAnnotation(); 59 testTypeAnnotation();
60 testSuperclass(); 60 testSuperclass();
61 // testVarSuperclass(); // The parser crashes with 'class Foo extends var'. 61 // testVarSuperclass(); // The parser crashes with 'class Foo extends var'.
62 // testOneInterface(); // The parser does not handle interfaces. 62 // testOneInterface(); // The parser does not handle interfaces.
63 // testTwoInterfaces(); // The parser does not handle interfaces. 63 // testTwoInterfaces(); // The parser does not handle interfaces.
64 testFunctionExpression(); 64 testFunctionExpression();
65 testNewExpression(); 65 testNewExpression();
66 testTopLevelFields(); 66 testTopLevelFields();
67 testInitializers(); 67 testInitializers();
68 testThis(); 68 testThis();
69 testSuperCalls();
70 }
71
72 testSuperCalls() {
73 MockCompiler compiler = new MockCompiler();
74 Universe universe = compiler.universe;
75 String script = """class A { foo() {} }
76 class B extends A { foo() => super.foo(); }""";
77 compiler.parseScript(script);
78 compiler.resolveStatement("B b;");
79
80 ClassElement classB = compiler.universe.find(buildSourceString("B"));
81 FunctionElement fooB = classB.lookupLocalMember(buildSourceString("foo"));
82 ClassElement classA = compiler.universe.find(buildSourceString("A"));
83 FunctionElement fooA = classA.lookupLocalMember(buildSourceString("foo"));
84
85 FullResolverVisitor visitor = new FullResolverVisitor(compiler, fooB);
86 FunctionExpression node = fooB.parseNode(compiler, compiler);
87 visitor.visit(node.body);
88 Map mapping = visitor.mapping.map;
89
90 Send superCall = node.body.asReturn().expression;
91 FunctionElement called = mapping[superCall];
92 Expect.isTrue(called !== null);
93 Expect.equals(fooA, called);
69 } 94 }
70 95
71 testThis() { 96 testThis() {
72 MockCompiler compiler = new MockCompiler(); 97 MockCompiler compiler = new MockCompiler();
73 Universe universe = compiler.universe; 98 Universe universe = compiler.universe;
74 compiler.parseScript("class Foo { foo() { return this; } }"); 99 compiler.parseScript("class Foo { foo() { return this; } }");
75 compiler.resolveStatement("Foo foo;"); 100 compiler.resolveStatement("Foo foo;");
76 ClassElement fooElement = universe.find(buildSourceString("Foo")); 101 ClassElement fooElement = universe.find(buildSourceString("Foo"));
77 FunctionElement funElement = 102 FunctionElement funElement =
78 fooElement.lookupLocalMember(buildSourceString("foo")); 103 fooElement.lookupLocalMember(buildSourceString("foo"));
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 Expect.equals(ElementKind.GENERATIVE_CONSTRUCTOR, element.kind); 420 Expect.equals(ElementKind.GENERATIVE_CONSTRUCTOR, element.kind);
396 Expect.isTrue(element is SynthesizedConstructorElement); 421 Expect.isTrue(element is SynthesizedConstructorElement);
397 } 422 }
398 423
399 testTopLevelFields() { 424 testTopLevelFields() {
400 MockCompiler compiler = new MockCompiler(); 425 MockCompiler compiler = new MockCompiler();
401 compiler.parseScript("int a;"); 426 compiler.parseScript("int a;");
402 Element element = compiler.universe.find(buildSourceString("a")); 427 Element element = compiler.universe.find(buildSourceString("a"));
403 Expect.equals(ElementKind.FIELD, element.kind); 428 Expect.equals(ElementKind.FIELD, element.kind);
404 VariableDefinitions node = element.variables.parseNode(compiler, compiler); 429 VariableDefinitions node = element.variables.parseNode(compiler, compiler);
405 Expect.equals(node.type.typeName.source.stringValue, 'int'); 430 Expect.equals(node.type.typeName.asIdentifier().source.stringValue, 'int');
406 431
407 compiler.parseScript("var b, c;"); 432 compiler.parseScript("var b, c;");
408 Element bElement = compiler.universe.find(buildSourceString("b")); 433 Element bElement = compiler.universe.find(buildSourceString("b"));
409 Element cElement = compiler.universe.find(buildSourceString("c")); 434 Element cElement = compiler.universe.find(buildSourceString("c"));
410 Expect.equals(ElementKind.FIELD, bElement.kind); 435 Expect.equals(ElementKind.FIELD, bElement.kind);
411 Expect.equals(ElementKind.FIELD, cElement.kind); 436 Expect.equals(ElementKind.FIELD, cElement.kind);
412 Expect.isTrue(bElement != cElement); 437 Expect.isTrue(bElement != cElement);
413 438
414 VariableDefinitions bNode = bElement.variables.parseNode(compiler, compiler); 439 VariableDefinitions bNode = bElement.variables.parseNode(compiler, compiler);
415 VariableDefinitions cNode = cElement.variables.parseNode(compiler, compiler); 440 VariableDefinitions cNode = cElement.variables.parseNode(compiler, compiler);
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
472 int bar; 497 int bar;
473 A() : this.foo = bar; 498 A() : this.foo = bar;
474 }"""; 499 }""";
475 resolveConstructor(script, "A a = new A();", "A", "A", 2, 500 resolveConstructor(script, "A a = new A();", "A", "A", 2,
476 [], [MessageKind.NOT_STATIC]); 501 [], [MessageKind.NOT_STATIC]);
477 } 502 }
478 503
479 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; 504 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1;
480 505
481 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 506 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698