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

Side by Side Diff: tests/compiler/dart2js/resolver_test.dart

Issue 11267018: Make getKeys, getValues getters (keys, values). (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update status files with co19 issue number. Created 8 years, 1 month 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 | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/corelib/core_runtime_types_test.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 'dart:uri'; 5 import 'dart:uri';
6 6
7 import "../../../lib/compiler/implementation/dart2jslib.dart" 7 import "../../../lib/compiler/implementation/dart2jslib.dart"
8 hide TreeElementMapping, TreeElements; 8 hide TreeElementMapping, TreeElements;
9 import "../../../lib/compiler/implementation/resolution/resolution.dart"; 9 import "../../../lib/compiler/implementation/resolution/resolution.dart";
10 import "../../../lib/compiler/implementation/elements/elements.dart"; 10 import "../../../lib/compiler/implementation/elements/elements.dart";
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 compiler.resolveStatement("Foo foo;"); 167 compiler.resolveStatement("Foo foo;");
168 ClassElement fooElement = compiler.mainApp.find(buildSourceString("Foo")); 168 ClassElement fooElement = compiler.mainApp.find(buildSourceString("Foo"));
169 FunctionElement funElement = 169 FunctionElement funElement =
170 fooElement.lookupLocalMember(buildSourceString("foo")); 170 fooElement.lookupLocalMember(buildSourceString("foo"));
171 ResolverVisitor visitor = 171 ResolverVisitor visitor =
172 new ResolverVisitor(compiler, funElement, 172 new ResolverVisitor(compiler, funElement,
173 new CollectingTreeElements(funElement)); 173 new CollectingTreeElements(funElement));
174 FunctionExpression function = funElement.parseNode(compiler); 174 FunctionExpression function = funElement.parseNode(compiler);
175 visitor.visit(function.body); 175 visitor.visit(function.body);
176 Map mapping = map(visitor); 176 Map mapping = map(visitor);
177 List<Element> values = mapping.getValues(); 177 List<Element> values = mapping.values;
178 Expect.equals(0, mapping.length); 178 Expect.equals(0, mapping.length);
179 Expect.equals(0, compiler.warnings.length); 179 Expect.equals(0, compiler.warnings.length);
180 180
181 compiler = new MockCompiler(); 181 compiler = new MockCompiler();
182 compiler.resolveStatement("main() { return this; }"); 182 compiler.resolveStatement("main() { return this; }");
183 Expect.equals(0, compiler.warnings.length); 183 Expect.equals(0, compiler.warnings.length);
184 Expect.equals(1, compiler.errors.length); 184 Expect.equals(1, compiler.errors.length);
185 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 185 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
186 compiler.errors[0].message.kind); 186 compiler.errors[0].message.kind);
187 187
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 testLocalsTwo() { 225 testLocalsTwo() {
226 MockCompiler compiler = new MockCompiler(); 226 MockCompiler compiler = new MockCompiler();
227 ResolverVisitor visitor = compiler.resolverVisitor(); 227 ResolverVisitor visitor = compiler.resolverVisitor();
228 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }"); 228 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }");
229 Element element = visitor.visit(tree); 229 Element element = visitor.visit(tree);
230 Expect.equals(null, element); 230 Expect.equals(null, element);
231 MethodScope scope = visitor.scope; 231 MethodScope scope = visitor.scope;
232 Expect.equals(0, scope.elements.length); 232 Expect.equals(0, scope.elements.length);
233 Expect.equals(2, map(visitor).length); 233 Expect.equals(2, map(visitor).length);
234 234
235 List<Element> elements = map(visitor).getValues(); 235 List<Element> elements = map(visitor).values;
236 Expect.notEquals(elements[0], elements[1]); 236 Expect.notEquals(elements[0], elements[1]);
237 } 237 }
238 238
239 testLocalsThree() { 239 testLocalsThree() {
240 MockCompiler compiler = new MockCompiler(); 240 MockCompiler compiler = new MockCompiler();
241 ResolverVisitor visitor = compiler.resolverVisitor(); 241 ResolverVisitor visitor = compiler.resolverVisitor();
242 Node tree = parseStatement("{ var a = 1; if (true) { a; } }"); 242 Node tree = parseStatement("{ var a = 1; if (true) { a; } }");
243 Element element = visitor.visit(tree); 243 Element element = visitor.visit(tree);
244 Expect.equals(null, element); 244 Expect.equals(null, element);
245 MethodScope scope = visitor.scope; 245 MethodScope scope = visitor.scope;
246 Expect.equals(0, scope.elements.length); 246 Expect.equals(0, scope.elements.length);
247 Expect.equals(3, map(visitor).length); 247 Expect.equals(3, map(visitor).length);
248 List<Element> elements = map(visitor).getValues(); 248 List<Element> elements = map(visitor).values;
249 Expect.equals(elements[0], elements[1]); 249 Expect.equals(elements[0], elements[1]);
250 } 250 }
251 251
252 testLocalsFour() { 252 testLocalsFour() {
253 MockCompiler compiler = new MockCompiler(); 253 MockCompiler compiler = new MockCompiler();
254 ResolverVisitor visitor = compiler.resolverVisitor(); 254 ResolverVisitor visitor = compiler.resolverVisitor();
255 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }"); 255 Node tree = parseStatement("{ var a = 1; if (true) { var a = 1; } }");
256 Element element = visitor.visit(tree); 256 Element element = visitor.visit(tree);
257 Expect.equals(null, element); 257 Expect.equals(null, element);
258 MethodScope scope = visitor.scope; 258 MethodScope scope = visitor.scope;
259 Expect.equals(0, scope.elements.length); 259 Expect.equals(0, scope.elements.length);
260 Expect.equals(2, map(visitor).length); 260 Expect.equals(2, map(visitor).length);
261 List<Element> elements = map(visitor).getValues(); 261 List<Element> elements = map(visitor).values;
262 Expect.notEquals(elements[0], elements[1]); 262 Expect.notEquals(elements[0], elements[1]);
263 } 263 }
264 264
265 testLocalsFive() { 265 testLocalsFive() {
266 MockCompiler compiler = new MockCompiler(); 266 MockCompiler compiler = new MockCompiler();
267 ResolverVisitor visitor = compiler.resolverVisitor(); 267 ResolverVisitor visitor = compiler.resolverVisitor();
268 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}"); 268 If tree = parseStatement("if (true) { var a = 1; a; } else { var a = 2; a;}");
269 Element element = visitor.visit(tree); 269 Element element = visitor.visit(tree);
270 Expect.equals(null, element); 270 Expect.equals(null, element);
271 MethodScope scope = visitor.scope; 271 MethodScope scope = visitor.scope;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 Expect.equals(0, scope.elements.length); 318 Expect.equals(0, scope.elements.length);
319 Expect.equals(10, map(visitor).length); 319 Expect.equals(10, map(visitor).length);
320 320
321 VariableDefinitions initializer = tree.initializer; 321 VariableDefinitions initializer = tree.initializer;
322 Node iNode = initializer.definitions.nodes.head; 322 Node iNode = initializer.definitions.nodes.head;
323 Element iElement = visitor.mapping[iNode]; 323 Element iElement = visitor.mapping[iNode];
324 324
325 // Check that we have the expected nodes. This test relies on the mapping 325 // Check that we have the expected nodes. This test relies on the mapping
326 // field to be a linked hash map (preserving insertion order). 326 // field to be a linked hash map (preserving insertion order).
327 Expect.isTrue(map(visitor) is LinkedHashMap); 327 Expect.isTrue(map(visitor) is LinkedHashMap);
328 List<Node> nodes = map(visitor).getKeys(); 328 List<Node> nodes = map(visitor).keys;
329 List<Element> elements = map(visitor).getValues(); 329 List<Element> elements = map(visitor).values;
330 330
331 331
332 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 332 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
333 // ^^^ 333 // ^^^
334 Expect.isTrue(nodes[0] is TypeAnnotation); 334 Expect.isTrue(nodes[0] is TypeAnnotation);
335 335
336 // for (int i = 0; i < 10; i = i + 1) { i = 5; }; 336 // for (int i = 0; i < 10; i = i + 1) { i = 5; };
337 // ^^^^^ 337 // ^^^^^
338 checkSendSet(iElement, nodes[1], elements[1]); 338 checkSendSet(iElement, nodes[1], elements[1]);
339 339
(...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 var d = new D(); 800 var d = new D();
801 --d; 801 --d;
802 }"""; 802 }""";
803 final compiler = compileScript(script); 803 final compiler = compileScript(script);
804 804
805 checkMemberResolved(compiler, 'A', operatorName('+', false)); 805 checkMemberResolved(compiler, 'A', operatorName('+', false));
806 checkMemberResolved(compiler, 'B', operatorName('+', false)); 806 checkMemberResolved(compiler, 'B', operatorName('+', false));
807 checkMemberResolved(compiler, 'C', operatorName('-', false)); 807 checkMemberResolved(compiler, 'C', operatorName('-', false));
808 checkMemberResolved(compiler, 'D', operatorName('-', false)); 808 checkMemberResolved(compiler, 'D', operatorName('-', false));
809 } 809 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/mock_compiler.dart ('k') | tests/corelib/core_runtime_types_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698