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

Side by Side Diff: compiler/javatests/com/google/dart/compiler/resolver/ResolverCompilerTest.java

Issue 9138023: More setting of symbols on identifiers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Changes many assertEquals() to assertSame() 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
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/resolver/ResolverAuditVisitor.java ('k') | no next file » | 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) 2011, 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 package com.google.dart.compiler.resolver; 4 package com.google.dart.compiler.resolver;
5 5
6 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors; 6 import static com.google.dart.compiler.common.ErrorExpectation.assertErrors;
7 import static com.google.dart.compiler.common.ErrorExpectation.errEx; 7 import static com.google.dart.compiler.common.ErrorExpectation.errEx;
8 8
9 import com.google.common.base.Joiner; 9 import com.google.common.base.Joiner;
10 import com.google.dart.compiler.CompilerTestCase; 10 import com.google.dart.compiler.CompilerTestCase;
11 import com.google.dart.compiler.DartCompilationError; 11 import com.google.dart.compiler.DartCompilationError;
12 import com.google.dart.compiler.ast.DartClass;
12 import com.google.dart.compiler.ast.DartFunctionTypeAlias; 13 import com.google.dart.compiler.ast.DartFunctionTypeAlias;
13 import com.google.dart.compiler.ast.DartNewExpression; 14 import com.google.dart.compiler.ast.DartNewExpression;
14 import com.google.dart.compiler.ast.DartNode; 15 import com.google.dart.compiler.ast.DartNode;
16 import com.google.dart.compiler.ast.DartTypeNode;
17 import com.google.dart.compiler.ast.DartTypeParameter;
15 import com.google.dart.compiler.ast.DartUnit; 18 import com.google.dart.compiler.ast.DartUnit;
16 import com.google.dart.compiler.type.FunctionAliasType; 19 import com.google.dart.compiler.type.FunctionAliasType;
17 import com.google.dart.compiler.type.Type; 20 import com.google.dart.compiler.type.Type;
18 import com.google.dart.compiler.type.TypeVariable; 21 import com.google.dart.compiler.type.TypeVariable;
19 22
20 import java.util.List; 23 import java.util.List;
21 24
22 /** 25 /**
23 * Variant of {@link ResolverTest}, which is based on {@link CompilerTestCase}. It is probably 26 * Variant of {@link ResolverTest}, which is based on {@link CompilerTestCase}. It is probably
24 * slower, not actually unit test, but easier to use if you need access to DartN ode's. 27 * slower, not actually unit test, but easier to use if you need access to DartN ode's.
(...skipping 19 matching lines...) Expand all
44 assertEquals("T", arg0.getTypeVariableElement().getName()); 47 assertEquals("T", arg0.getTypeVariableElement().getName());
45 Type bound0 = arg0.getTypeVariableElement().getBound(); 48 Type bound0 = arg0.getTypeVariableElement().getBound();
46 assertEquals("Object", bound0.toString()); 49 assertEquals("Object", bound0.toString());
47 TypeVariable arg1 = (TypeVariable)arguments.get(1); 50 TypeVariable arg1 = (TypeVariable)arguments.get(1);
48 assertEquals("U", arg1.getTypeVariableElement().getName()); 51 assertEquals("U", arg1.getTypeVariableElement().getName());
49 Type bound1 = arg1.getTypeVariableElement().getBound(); 52 Type bound1 = arg1.getTypeVariableElement().getBound();
50 assertEquals("List<TypeAlias.T>", bound1.toString()); 53 assertEquals("List<TypeAlias.T>", bound1.toString());
51 } 54 }
52 55
53 /** 56 /**
57 * This test checks the class declarations to make sure that symbols are set f or
58 * all identifiers. This is useful to the editor and other consumers of the A ST.
59 */
60 public void test_resolution_on_class_decls() throws Exception {
61 AnalyzeLibraryResult libraryResult =
62 analyzeLibrary(
63 "Test.dart",
64 Joiner.on("\n").join(
65 "class A {}",
66 "interface B<T> default C {}",
67 "class C<T> extends A implements B<T> {}",
68 "class D extends C<int> {}",
69 "class E implements C<int> {}",
70 "class F<T extends A> {}",
71 "class G extends F<C<int>> {}",
72 "interface H<T> default C<T> {}"));
73 assertErrors(libraryResult.getCompilationErrors());
74 DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().n ext();
75 List<DartNode> nodes = unit.getTopLevelNodes();
76 DartClass A = (DartClass)nodes.get(0);
77 assertEquals("A", A.getClassName());
78 DartClass B = (DartClass)nodes.get(1);
79 assertEquals("B", B.getClassName());
80 DartClass C = (DartClass)nodes.get(2);
81 assertEquals("C", C.getClassName());
82 DartClass D = (DartClass)nodes.get(3);
83 assertEquals("D", D.getClassName());
84 DartClass E = (DartClass)nodes.get(4);
85 assertEquals("E", E.getClassName());
86 DartClass F = (DartClass)nodes.get(5);
87 assertEquals("F", F.getClassName());
88 DartClass G = (DartClass)nodes.get(6);
89 assertEquals("G", G.getClassName());
90 DartClass H = (DartClass)nodes.get(7);
91 assertEquals("H", H.getClassName());
92
93 // class A
94 assertNotNull(A.getName().getSymbol());
95 assertSame(A.getSymbol(), A.getName().getSymbol());
96
97 // interface B<T> default C
98 assertNotNull(B.getName().getSymbol());
99 assertSame(B.getName().getSymbol(), B.getSymbol());
100 assertEquals(1, B.getTypeParameters().size());
101 DartTypeParameter T;
102 T = B.getTypeParameters().get(0);
103 assertNotNull(T);
104 assertNotNull(T.getName().getSymbol());
105 assertTrue(T.getName().getSymbol() instanceof TypeVariableElement);
106 assertEquals("T", T.getName().getTargetName());
107 assertNotNull(B.getDefaultClass().getExpression().getSymbol());
108 assertSame(C.getSymbol(), B.getDefaultClass().getExpression().getSymbol());
109
110 // class C<T> extends A implements B<T> {}
111 assertNotNull(C.getName().getSymbol());
112 assertSame(C.getSymbol(), C.getName().getSymbol());
113 assertEquals(1, C.getTypeParameters().size());
114 T = C.getTypeParameters().get(0);
115 assertNotNull(T);
116 assertNotNull(T.getName().getSymbol());
117 assertTrue(T.getName().getSymbol() instanceof TypeVariableElement);
118 assertEquals("T", T.getName().getTargetName());
119 assertSame(A.getSymbol(), C.getSuperclass().getIdentifier().getSymbol());
120 assertEquals(1, C.getInterfaces().size());
121 DartTypeNode iface = C.getInterfaces().get(0);
122 assertNotNull(iface);
123 assertSame(B.getSymbol(), iface.getIdentifier().getSymbol());
124 assertSame(T.getName().getSymbol(),
125 iface.getTypeArguments().get(0).getIdentifier().getSymbol());
126
127 // class D extends C<int> {}
128 assertNotNull(D.getName().getSymbol());
129 assertSame(D.getSymbol(), D.getName().getSymbol());
130 assertEquals(0, D.getTypeParameters().size());
131 assertSame(C.getSymbol(), D.getSuperclass().getIdentifier().getSymbol());
132 DartTypeNode typeArg;
133 typeArg = D.getSuperclass().getTypeArguments().get(0);
134 assertNotNull(typeArg.getIdentifier());
135 assertEquals("int", typeArg.getIdentifier().getSymbol().getOriginalSymbolNam e());
136
137 // class E implements C<int> {}
138 assertNotNull(E.getName().getSymbol());
139 assertSame(E.getSymbol(), E.getName().getSymbol());
140 assertEquals(0, E.getTypeParameters().size());
141 assertSame(C.getSymbol(), E.getInterfaces().get(0).getIdentifier().getSymbol ());
142 typeArg = E.getInterfaces().get(0).getTypeArguments().get(0);
143 assertNotNull(typeArg.getIdentifier());
144 assertEquals("int", typeArg.getIdentifier().getSymbol().getOriginalSymbolNam e());
145
146 // class F<T extends A> {}",
147 assertNotNull(F.getName().getSymbol());
148 assertSame(F.getSymbol(), F.getName().getSymbol());
149 assertEquals(1, F.getTypeParameters().size());
150 T = F.getTypeParameters().get(0);
151 assertNotNull(T);
152 assertNotNull(T.getName().getSymbol());
153 assertTrue(T.getName().getSymbol() instanceof TypeVariableElement);
154 assertEquals("T", T.getName().getTargetName());
155 assertSame(A.getSymbol(), T.getBound().getIdentifier().getSymbol());
156
157 // class G extends F<C<int>> {}
158 assertNotNull(G.getName().getSymbol());
159 assertSame(G.getSymbol(), G.getName().getSymbol());
160 assertEquals(0, G.getTypeParameters().size());
161 assertNotNull(G.getSuperclass());
162 assertSame(F.getSymbol(), G.getSuperclass().getIdentifier().getSymbol());
163 typeArg = G.getSuperclass().getTypeArguments().get(0);
164 assertSame(C.getSymbol(), typeArg.getIdentifier().getSymbol());
165 assertEquals("int",
166 typeArg.getTypeArguments().get(0).getIdentifier().getSymbol().getOrigina lSymbolName());
167
168 // class H<T> extends C<T> {}",
169 assertNotNull(H.getName().getSymbol());
170 assertSame(H.getSymbol(), H.getName().getSymbol());
171 assertEquals(1, H.getTypeParameters().size());
172 T = H.getTypeParameters().get(0);
173 assertNotNull(T);
174 assertNotNull(T.getName().getSymbol());
175 assertTrue(T.getName().getSymbol() instanceof TypeVariableElement);
176 assertNotNull(H.getDefaultClass().getExpression().getSymbol());
177 assertSame(C.getSymbol(), H.getDefaultClass().getExpression().getSymbol());
178 // This type parameter T resolves to the Type variable on the default class, so it
179 // isn't the same type variable instance specified in this interface declara tion,
180 // though it must have the same name.
181 DartTypeParameter defaultT = H.getDefaultClass().getTypeParameters().get(0);
182 assertNotNull(defaultT.getName().getSymbol());
183 assertTrue(defaultT.getName().getSymbol() instanceof TypeVariableElement);
184 assertEquals(T.getName().getSymbol().getName(), defaultT.getName().getSymbol ().getName());
185 }
186
187 /**
54 * We should be able to resolve implicit default constructor. 188 * We should be able to resolve implicit default constructor.
55 */ 189 */
56 public void test_resolveConstructor_implicit() throws Exception { 190 public void test_resolveConstructor_implicit() throws Exception {
57 AnalyzeLibraryResult libraryResult = 191 AnalyzeLibraryResult libraryResult =
58 analyzeLibrary( 192 analyzeLibrary(
59 "Test.dart", 193 "Test.dart",
60 Joiner.on("\n").join( 194 Joiner.on("\n").join(
61 "class F {", 195 "class F {",
62 "}", 196 "}",
63 "class Test {", 197 "class Test {",
(...skipping 15 matching lines...) Expand all
79 "Test.dart", 213 "Test.dart",
80 Joiner.on("\n").join( 214 Joiner.on("\n").join(
81 "class A {", 215 "class A {",
82 "}", 216 "}",
83 "class Test {", 217 "class Test {",
84 " foo() {", 218 " foo() {",
85 " new A.foo();", 219 " new A.foo();",
86 " }", 220 " }",
87 "}")); 221 "}"));
88 assertErrors( 222 assertErrors(
89 libraryResult.getCompilationErrors(), 223 libraryResult.getCompilationErrors(),
90 errEx(ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR, 5, 9, 5)); 224 errEx(ResolverErrorCode.NEW_EXPRESSION_NOT_CONSTRUCTOR, 5, 9, 5));
91 DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().n ext(); 225 DartUnit unit = libraryResult.getLibraryUnitResult().getUnits().iterator().n ext();
92 DartNewExpression newExpression = findNewExpression(unit, "new A.foo()"); 226 DartNewExpression newExpression = findNewExpression(unit, "new A.foo()");
93 ConstructorElement constructorElement = newExpression.getSymbol(); 227 ConstructorElement constructorElement = newExpression.getSymbol();
94 assertNull(constructorElement); 228 assertNull(constructorElement);
95 } 229 }
96 230
97 /** 231 /**
98 * We should be able to resolve implicit default constructor. 232 * We should be able to resolve implicit default constructor.
99 */ 233 */
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 assertEquals(true, constructorNode.toSource().contains("F.bar(")); 711 assertEquals(true, constructorNode.toSource().contains("F.bar("));
578 } 712 }
579 // "new I.baz()" - resolved, but we produce error. 713 // "new I.baz()" - resolved, but we produce error.
580 { 714 {
581 DartNewExpression newExpression = findNewExpression(unit, "new I.baz(0)"); 715 DartNewExpression newExpression = findNewExpression(unit, "new I.baz(0)");
582 DartNode constructorNode = newExpression.getSymbol().getNode(); 716 DartNode constructorNode = newExpression.getSymbol().getNode();
583 assertEquals(true, constructorNode.toSource().contains("F.baz(")); 717 assertEquals(true, constructorNode.toSource().contains("F.baz("));
584 } 718 }
585 } 719 }
586 } 720 }
OLDNEW
« no previous file with comments | « compiler/javatests/com/google/dart/compiler/resolver/ResolverAuditVisitor.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698