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

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

Issue 10095014: Implement interface types. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 8 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 | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | 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("../../../../lib/compiler/implementation/leg.dart"); 5 #import("../../../../lib/compiler/implementation/leg.dart");
6 #import("../../../../lib/compiler/implementation/elements/elements.dart"); 6 #import("../../../../lib/compiler/implementation/elements/elements.dart");
7 #import("../../../../lib/compiler/implementation/tree/tree.dart"); 7 #import("../../../../lib/compiler/implementation/tree/tree.dart");
8 #import("../../../../lib/compiler/implementation/util/util.dart"); 8 #import("../../../../lib/compiler/implementation/util/util.dart");
9 #import("mock_compiler.dart"); 9 #import("mock_compiler.dart");
10 #import("parser_helper.dart"); 10 #import("parser_helper.dart");
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 testClassHierarchy(); 67 testClassHierarchy();
68 testInitializers(); 68 testInitializers();
69 testThis(); 69 testThis();
70 testSuperCalls(); 70 testSuperCalls();
71 testTypeVariables();
72 }
73
74 testTypeVariables() {
75 testTypeResolving(visitor, text, name, expectedElements) {
76 VariableDefinitions definition = parseStatement(text);
77 visitor.visit(definition.type);
78 InterfaceType type = visitor.mapping.getType(definition.type);
79 Expect.equals(definition.type.typeArguments.length(),
80 length(type.arguments));
81 int index = 0;
82 Link<Type> arguments = type.arguments;
83 while (!arguments.isEmpty()) {
84 Expect.equals(expectedElements[index], arguments.head.element);
85 index++;
86 arguments = arguments.tail;
87 }
88 }
89
90 MockCompiler compiler = new MockCompiler();
91 ResolverVisitor visitor = compiler.resolverVisitor();
92 compiler.parseScript('class Foo<T, U> {}');
93 visitor.visit(parseStatement('Foo foo;'));
94 ClassElement foo = compiler.mainApp.find(buildSourceString('Foo'));
95 testTypeResolving(visitor, 'Foo<int, String> x;', 'Foo',
96 [compiler.intClass, compiler.stringClass]);
97 testTypeResolving(visitor, 'Foo<Foo, Foo> x;', 'Foo',
98 [foo, foo]);
99
100 compiler = new MockCompiler();
101 compiler.parseScript('class Foo<T, U> {}');
102 compiler.resolveStatement('Foo<notype, int> x;');
103 Expect.equals(1, compiler.warnings.length);
104 Expect.equals(MessageKind.CANNOT_RESOLVE_TYPE,
105 compiler.warnings[0].message.kind);
106 Expect.equals(0, compiler.errors.length);
107
108 compiler = new MockCompiler();
109 compiler.parseScript('class Foo<T, U> {}');
110 compiler.resolveStatement('var x = new Foo<notype, int>();');
111 Expect.equals(0, compiler.warnings.length);
112 Expect.equals(1, compiler.errors.length);
113 Expect.equals(MessageKind.CANNOT_RESOLVE_TYPE,
114 compiler.errors[0].message.kind);
71 } 115 }
72 116
73 testSuperCalls() { 117 testSuperCalls() {
74 MockCompiler compiler = new MockCompiler(); 118 MockCompiler compiler = new MockCompiler();
75 String script = """class A { foo() {} } 119 String script = """class A { foo() {} }
76 class B extends A { foo() => super.foo(); }"""; 120 class B extends A { foo() => super.foo(); }""";
77 compiler.parseScript(script); 121 compiler.parseScript(script);
78 compiler.resolveStatement("B b;"); 122 compiler.resolveStatement("B b;");
79 123
80 ClassElement classB = compiler.mainApp.find(buildSourceString("B")); 124 ClassElement classB = compiler.mainApp.find(buildSourceString("B"));
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1; 683 length(Link link) => link.isEmpty() ? 0 : length(link.tail) + 1;
640 684
641 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1); 685 at(Link link, int index) => (index == 0) ? link.head : at(link.tail, index - 1);
642 686
643 List<String> asSortedStrings(Link link) { 687 List<String> asSortedStrings(Link link) {
644 List<String> result = <String>[]; 688 List<String> result = <String>[];
645 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString()); 689 for (; !link.isEmpty(); link = link.tail) result.add(link.head.toString());
646 result.sort((s1, s2) => s1.compareTo(s2)); 690 result.sort((s1, s2) => s1.compareTo(s2));
647 return result; 691 return result;
648 } 692 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/compiler.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698