OLD | NEW |
---|---|
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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
51 main() { | 51 main() { |
52 testLocalsOne(); | 52 testLocalsOne(); |
53 testLocalsTwo(); | 53 testLocalsTwo(); |
54 testLocalsThree(); | 54 testLocalsThree(); |
55 testLocalsFour(); | 55 testLocalsFour(); |
56 testLocalsFive(); | 56 testLocalsFive(); |
57 testParametersOne(); | 57 testParametersOne(); |
58 testFor(); | 58 testFor(); |
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'. |
ahe
2012/04/12 15:05:23
Really?
| |
62 // testOneInterface(); // The parser does not handle interfaces. | 62 // testOneInterface(); // The parser does not handle interfaces. |
ahe
2012/04/12 15:05:23
Really?
| |
63 // testTwoInterfaces(); // The parser does not handle interfaces. | 63 // testTwoInterfaces(); // The parser does not handle interfaces. |
ahe
2012/04/12 15:05:23
Really?
| |
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) { | |
ahe
2012/04/12 15:05:23
I think it is confusing when a helper function sta
| |
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()) { | |
ahe
2012/04/12 15:05:23
Expect.isTrue(index < expectedElements.length);
| |
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;')); | |
ahe
2012/04/12 15:05:23
What is the purpose of this?
| |
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 Loading... | |
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 } |
OLD | NEW |