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

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

Issue 1892183002: Refactor Parsing to remove compiler dependency (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 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
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:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:async_helper/async_helper.dart'; 8 import 'package:async_helper/async_helper.dart';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'package:compiler/src/constants/expressions.dart'; 10 import 'package:compiler/src/constants/expressions.dart';
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 ClassElement classB = compiler.mainApp.find("B"); 220 ClassElement classB = compiler.mainApp.find("B");
221 FunctionElement fooB = classB.lookupLocalMember("foo"); 221 FunctionElement fooB = classB.lookupLocalMember("foo");
222 ClassElement classA = compiler.mainApp.find("A"); 222 ClassElement classA = compiler.mainApp.find("A");
223 FunctionElement fooA = classA.lookupLocalMember("foo"); 223 FunctionElement fooA = classA.lookupLocalMember("foo");
224 224
225 ResolverVisitor visitor = 225 ResolverVisitor visitor =
226 new ResolverVisitor(compiler, fooB, 226 new ResolverVisitor(compiler, fooB,
227 new ResolutionRegistry(compiler, 227 new ResolutionRegistry(compiler,
228 new CollectingTreeElements(fooB))); 228 new CollectingTreeElements(fooB)));
229 FunctionExpression node = 229 FunctionExpression node =
230 (fooB as FunctionElementX).parseNode(compiler.parsing); 230 (fooB as FunctionElementX).parseNode(compiler.parsingContext);
231 visitor.visit(node.body); 231 visitor.visit(node.body);
232 Map mapping = map(visitor); 232 Map mapping = map(visitor);
233 233
234 Send superCall = node.body.asReturn().expression; 234 Send superCall = node.body.asReturn().expression;
235 FunctionElement called = mapping[superCall]; 235 FunctionElement called = mapping[superCall];
236 Expect.isNotNull(called); 236 Expect.isNotNull(called);
237 Expect.equals(fooA, called); 237 Expect.equals(fooA, called);
238 }); 238 });
239 } 239 }
240 240
(...skipping 23 matching lines...) Expand all
264 MockCompiler.create((MockCompiler compiler) { 264 MockCompiler.create((MockCompiler compiler) {
265 compiler.parseScript("class Foo { foo() { return this; } }"); 265 compiler.parseScript("class Foo { foo() { return this; } }");
266 compiler.resolveStatement("Foo foo;"); 266 compiler.resolveStatement("Foo foo;");
267 ClassElement fooElement = compiler.mainApp.find("Foo"); 267 ClassElement fooElement = compiler.mainApp.find("Foo");
268 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 268 FunctionElement funElement = fooElement.lookupLocalMember("foo");
269 ResolverVisitor visitor = 269 ResolverVisitor visitor =
270 new ResolverVisitor(compiler, funElement, 270 new ResolverVisitor(compiler, funElement,
271 new ResolutionRegistry(compiler, 271 new ResolutionRegistry(compiler,
272 new CollectingTreeElements(funElement))); 272 new CollectingTreeElements(funElement)));
273 FunctionExpression function = 273 FunctionExpression function =
274 (funElement as FunctionElementX).parseNode(compiler.parsing); 274 (funElement as FunctionElementX).parseNode(compiler.parsingContext);
275 visitor.visit(function.body); 275 visitor.visit(function.body);
276 Map mapping = map(visitor); 276 Map mapping = map(visitor);
277 List<Element> values = mapping.values.toList(); 277 List<Element> values = mapping.values.toList();
278 DiagnosticCollector collector = compiler.diagnosticCollector; 278 DiagnosticCollector collector = compiler.diagnosticCollector;
279 Expect.equals(0, mapping.length); 279 Expect.equals(0, mapping.length);
280 Expect.equals(0, collector.warnings.length); 280 Expect.equals(0, collector.warnings.length);
281 }), 281 }),
282 MockCompiler.create((MockCompiler compiler) { 282 MockCompiler.create((MockCompiler compiler) {
283 compiler.resolveStatement("main() { return this; }"); 283 compiler.resolveStatement("main() { return this; }");
284 DiagnosticCollector collector = compiler.diagnosticCollector; 284 DiagnosticCollector collector = compiler.diagnosticCollector;
285 Expect.equals(0, collector.warnings.length); 285 Expect.equals(0, collector.warnings.length);
286 Expect.equals(1, collector.errors.length); 286 Expect.equals(1, collector.errors.length);
287 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 287 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
288 collector.errors.first.message.kind); 288 collector.errors.first.message.kind);
289 }), 289 }),
290 MockCompiler.create((MockCompiler compiler) { 290 MockCompiler.create((MockCompiler compiler) {
291 compiler.parseScript("class Foo { static foo() { return this; } }"); 291 compiler.parseScript("class Foo { static foo() { return this; } }");
292 compiler.resolveStatement("Foo foo;"); 292 compiler.resolveStatement("Foo foo;");
293 ClassElement fooElement = compiler.mainApp.find("Foo"); 293 ClassElement fooElement = compiler.mainApp.find("Foo");
294 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 294 FunctionElement funElement = fooElement.lookupLocalMember("foo");
295 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, 295 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement,
296 new ResolutionRegistry(compiler, 296 new ResolutionRegistry(compiler,
297 new CollectingTreeElements(funElement))); 297 new CollectingTreeElements(funElement)));
298 FunctionExpression function = 298 FunctionExpression function =
299 (funElement as FunctionElementX).parseNode(compiler.parsing); 299 (funElement as FunctionElementX).parseNode(compiler.parsingContext);
300 visitor.visit(function.body); 300 visitor.visit(function.body);
301 DiagnosticCollector collector = compiler.diagnosticCollector; 301 DiagnosticCollector collector = compiler.diagnosticCollector;
302 Expect.equals(0, collector.warnings.length); 302 Expect.equals(0, collector.warnings.length);
303 Expect.equals(1, collector.errors.length); 303 Expect.equals(1, collector.errors.length);
304 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 304 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
305 collector.errors.first.message.kind); 305 collector.errors.first.message.kind);
306 }), 306 }),
307 ]); 307 ]);
308 } 308 }
309 309
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 Expect.isTrue(element.isSynthesized); 658 Expect.isTrue(element.isSynthesized);
659 }); 659 });
660 } 660 }
661 661
662 Future testTopLevelFields() { 662 Future testTopLevelFields() {
663 return MockCompiler.create((MockCompiler compiler) { 663 return MockCompiler.create((MockCompiler compiler) {
664 compiler.parseScript("int a;"); 664 compiler.parseScript("int a;");
665 VariableElementX element = compiler.mainApp.find("a"); 665 VariableElementX element = compiler.mainApp.find("a");
666 Expect.equals(ElementKind.FIELD, element.kind); 666 Expect.equals(ElementKind.FIELD, element.kind);
667 VariableDefinitions node = 667 VariableDefinitions node =
668 element.variables.parseNode(element, compiler.parsing); 668 element.variables.parseNode(element, compiler.parsingContext);
669 Identifier typeName = node.type.typeName; 669 Identifier typeName = node.type.typeName;
670 Expect.equals(typeName.source, 'int'); 670 Expect.equals(typeName.source, 'int');
671 671
672 compiler.parseScript("var b, c;"); 672 compiler.parseScript("var b, c;");
673 VariableElementX bElement = compiler.mainApp.find("b"); 673 VariableElementX bElement = compiler.mainApp.find("b");
674 VariableElementX cElement = compiler.mainApp.find("c"); 674 VariableElementX cElement = compiler.mainApp.find("c");
675 Expect.equals(ElementKind.FIELD, bElement.kind); 675 Expect.equals(ElementKind.FIELD, bElement.kind);
676 Expect.equals(ElementKind.FIELD, cElement.kind); 676 Expect.equals(ElementKind.FIELD, cElement.kind);
677 Expect.isTrue(bElement != cElement); 677 Expect.isTrue(bElement != cElement);
678 678
679 VariableDefinitions bNode = 679 VariableDefinitions bNode =
680 bElement.variables.parseNode(bElement, compiler.parsing); 680 bElement.variables.parseNode(bElement, compiler.parsingContext);
681 VariableDefinitions cNode = 681 VariableDefinitions cNode =
682 cElement.variables.parseNode(cElement, compiler.parsing); 682 cElement.variables.parseNode(cElement, compiler.parsingContext);
683 Expect.equals(bNode, cNode); 683 Expect.equals(bNode, cNode);
684 Expect.isNull(bNode.type); 684 Expect.isNull(bNode.type);
685 Expect.isTrue(bNode.modifiers.isVar); 685 Expect.isTrue(bNode.modifiers.isVar);
686 }); 686 });
687 } 687 }
688 688
689 Future resolveConstructor( 689 Future resolveConstructor(
690 String script, String statement, String className, 690 String script, String statement, String className,
691 String constructor, int expectedElementCount, 691 String constructor, int expectedElementCount,
692 {List expectedWarnings: const [], 692 {List expectedWarnings: const [],
(...skipping 748 matching lines...) Expand 10 before | Expand all | Expand 10 after
1441 } 1441 }
1442 main() => A.m(); 1442 main() => A.m();
1443 ''', functionName: 'm'); 1443 ''', functionName: 'm');
1444 check(''' 1444 check('''
1445 class A { 1445 class A {
1446 m() => () => await - 3; 1446 m() => () => await - 3;
1447 } 1447 }
1448 main() => new A().m(); 1448 main() => new A().m();
1449 ''', className: 'A'); 1449 ''', className: 'A');
1450 } 1450 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/patch_test.dart ('k') | tests/compiler/dart2js/serialization_helper.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698