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

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

Issue 12082024: Use named arguments for messages. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Rebased Created 7 years, 10 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 | « tests/compiler/dart2js/part_of_test.dart ('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) 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:collection'; 5 import 'dart:collection';
6 import 'dart:uri'; 6 import 'dart:uri';
7 7
8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart"; 8 import "../../../sdk/lib/_internal/compiler/implementation/resolution/resolution .dart";
9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t"; 9 import "../../../sdk/lib/_internal/compiler/implementation/elements/elements.dar t";
10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart"; 10 import "../../../sdk/lib/_internal/compiler/implementation/tree/tree.dart";
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 testLocals([["foo", false], ["bar", true]]); 212 testLocals([["foo", false], ["bar", true]]);
213 testLocals([["foo", true], ["bar", true]]); 213 testLocals([["foo", true], ["bar", true]]);
214 214
215 testLocals([["foo", false], ["bar", false], ["foobar", true]]); 215 testLocals([["foo", false], ["bar", false], ["foobar", true]]);
216 testLocals([["foo", false], ["bar", true], ["foobar", true]]); 216 testLocals([["foo", false], ["bar", true], ["foobar", true]]);
217 testLocals([["foo", true], ["bar", true], ["foobar", true]]); 217 testLocals([["foo", true], ["bar", true], ["foobar", true]]);
218 218
219 MockCompiler compiler = testLocals([["foo", false], ["foo", false]]); 219 MockCompiler compiler = testLocals([["foo", false], ["foo", false]]);
220 Expect.equals(1, compiler.errors.length); 220 Expect.equals(1, compiler.errors.length);
221 Expect.equals( 221 Expect.equals(
222 new Message(MessageKind.DUPLICATE_DEFINITION, ['foo']), 222 new Message(MessageKind.DUPLICATE_DEFINITION, {'name': 'foo'}),
223 compiler.errors[0].message); 223 compiler.errors[0].message);
224 } 224 }
225 225
226 226
227 testLocalsTwo() { 227 testLocalsTwo() {
228 MockCompiler compiler = new MockCompiler(); 228 MockCompiler compiler = new MockCompiler();
229 ResolverVisitor visitor = compiler.resolverVisitor(); 229 ResolverVisitor visitor = compiler.resolverVisitor();
230 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }"); 230 Node tree = parseStatement("if (true) { var a = 1; var b = 2; }");
231 Element element = visitor.visit(tree); 231 Element element = visitor.visit(tree);
232 Expect.equals(null, element); 232 Expect.equals(null, element);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 394
395 // Test that we get a warning when Foo is not defined. 395 // Test that we get a warning when Foo is not defined.
396 Map mapping = compiler.resolveStatement(statement).map; 396 Map mapping = compiler.resolveStatement(statement).map;
397 397
398 Expect.equals(2, mapping.length); // Both Foo and bar have an element. 398 Expect.equals(2, mapping.length); // Both Foo and bar have an element.
399 Expect.equals(1, compiler.warnings.length); 399 Expect.equals(1, compiler.warnings.length);
400 400
401 Node warningNode = compiler.warnings[0].node; 401 Node warningNode = compiler.warnings[0].node;
402 402
403 Expect.equals( 403 Expect.equals(
404 new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['Foo']), 404 new Message(MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': 'Foo'}),
405 compiler.warnings[0].message); 405 compiler.warnings[0].message);
406 VariableDefinitions definition = compiler.parsedTree; 406 VariableDefinitions definition = compiler.parsedTree;
407 Expect.equals(warningNode, definition.type); 407 Expect.equals(warningNode, definition.type);
408 compiler.clearWarnings(); 408 compiler.clearWarnings();
409 409
410 // Test that there is no warning after defining Foo. 410 // Test that there is no warning after defining Foo.
411 compiler.parseScript("class Foo {}"); 411 compiler.parseScript("class Foo {}");
412 mapping = compiler.resolveStatement(statement).map; 412 mapping = compiler.resolveStatement(statement).map;
413 Expect.equals(2, mapping.length); 413 Expect.equals(2, mapping.length);
414 Expect.equals(0, compiler.warnings.length); 414 Expect.equals(0, compiler.warnings.length);
415 415
416 // Test that 'var' does not create a warning. 416 // Test that 'var' does not create a warning.
417 mapping = compiler.resolveStatement("var foo;").map; 417 mapping = compiler.resolveStatement("var foo;").map;
418 Expect.equals(1, mapping.length); 418 Expect.equals(1, mapping.length);
419 Expect.equals(0, compiler.warnings.length); 419 Expect.equals(0, compiler.warnings.length);
420 } 420 }
421 421
422 testSuperclass() { 422 testSuperclass() {
423 MockCompiler compiler = new MockCompiler(); 423 MockCompiler compiler = new MockCompiler();
424 compiler.parseScript("class Foo extends Bar {}"); 424 compiler.parseScript("class Foo extends Bar {}");
425 compiler.resolveStatement("Foo bar;"); 425 compiler.resolveStatement("Foo bar;");
426 // TODO(ahe): We get the same error twice: once from 426 // TODO(ahe): We get the same error twice: once from
427 // ClassResolverVisitor, and once from ClassSupertypeResolver. We 427 // ClassResolverVisitor, and once from ClassSupertypeResolver. We
428 // should only the get the error once. 428 // should only the get the error once.
429 Expect.equals(2, compiler.errors.length); 429 Expect.equals(2, compiler.errors.length);
430 var cannotResolveBar = new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['Bar']); 430 var cannotResolveBar = new Message(MessageKind.CANNOT_RESOLVE_TYPE,
431 {'typeName': 'Bar'});
431 Expect.equals(cannotResolveBar, compiler.errors[0].message); 432 Expect.equals(cannotResolveBar, compiler.errors[0].message);
432 Expect.equals(cannotResolveBar, compiler.errors[1].message); 433 Expect.equals(cannotResolveBar, compiler.errors[1].message);
433 compiler.clearErrors(); 434 compiler.clearErrors();
434 435
435 compiler = new MockCompiler(); 436 compiler = new MockCompiler();
436 compiler.parseScript("class Foo extends Bar {}"); 437 compiler.parseScript("class Foo extends Bar {}");
437 compiler.parseScript("class Bar {}"); 438 compiler.parseScript("class Bar {}");
438 Map mapping = compiler.resolveStatement("Foo bar;").map; 439 Map mapping = compiler.resolveStatement("Foo bar;").map;
439 Expect.equals(2, mapping.length); 440 Expect.equals(2, mapping.length);
440 441
441 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo')); 442 ClassElement fooElement = compiler.mainApp.find(buildSourceString('Foo'));
442 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar')); 443 ClassElement barElement = compiler.mainApp.find(buildSourceString('Bar'));
443 Expect.equals(barElement.computeType(compiler), 444 Expect.equals(barElement.computeType(compiler),
444 fooElement.supertype); 445 fooElement.supertype);
445 Expect.isTrue(fooElement.interfaces.isEmpty); 446 Expect.isTrue(fooElement.interfaces.isEmpty);
446 Expect.isTrue(barElement.interfaces.isEmpty); 447 Expect.isTrue(barElement.interfaces.isEmpty);
447 } 448 }
448 449
449 testVarSuperclass() { 450 testVarSuperclass() {
450 MockCompiler compiler = new MockCompiler(); 451 MockCompiler compiler = new MockCompiler();
451 compiler.parseScript("class Foo extends var {}"); 452 compiler.parseScript("class Foo extends var {}");
452 compiler.resolveStatement("Foo bar;"); 453 compiler.resolveStatement("Foo bar;");
453 Expect.equals(1, compiler.errors.length); 454 Expect.equals(1, compiler.errors.length);
454 Expect.equals( 455 Expect.equals(
455 new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['var']), 456 new Message(MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': 'var'}),
456 compiler.errors[0].message); 457 compiler.errors[0].message);
457 compiler.clearErrors(); 458 compiler.clearErrors();
458 } 459 }
459 460
460 testOneInterface() { 461 testOneInterface() {
461 MockCompiler compiler = new MockCompiler(); 462 MockCompiler compiler = new MockCompiler();
462 compiler.parseScript("class Foo implements Bar {}"); 463 compiler.parseScript("class Foo implements Bar {}");
463 compiler.resolveStatement("Foo bar;"); 464 compiler.resolveStatement("Foo bar;");
464 Expect.equals(1, compiler.errors.length); 465 Expect.equals(1, compiler.errors.length);
465 Expect.equals( 466 Expect.equals(
466 new Message(MessageKind.CANNOT_RESOLVE_TYPE, ['bar']), 467 new Message(MessageKind.CANNOT_RESOLVE_TYPE, {'typeName': 'bar'}),
467 compiler.errors[0].message); 468 compiler.errors[0].message);
468 compiler.clearErrors(); 469 compiler.clearErrors();
469 470
470 // Add the interface to the world and make sure everything is setup correctly. 471 // Add the interface to the world and make sure everything is setup correctly.
471 compiler.parseScript("interface Bar {}"); 472 compiler.parseScript("interface Bar {}");
472 473
473 ResolverVisitor visitor = 474 ResolverVisitor visitor =
474 new ResolverVisitor(compiler, null, new CollectingTreeElements(null)); 475 new ResolverVisitor(compiler, null, new CollectingTreeElements(null));
475 compiler.resolveStatement("Foo bar;"); 476 compiler.resolveStatement("Foo bar;");
476 477
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 var d = new D(); 841 var d = new D();
841 --d; 842 --d;
842 }"""; 843 }""";
843 final compiler = compileScript(script); 844 final compiler = compileScript(script);
844 845
845 checkMemberResolved(compiler, 'A', operatorName('+', false)); 846 checkMemberResolved(compiler, 'A', operatorName('+', false));
846 checkMemberResolved(compiler, 'B', operatorName('+', false)); 847 checkMemberResolved(compiler, 'B', operatorName('+', false));
847 checkMemberResolved(compiler, 'C', operatorName('-', false)); 848 checkMemberResolved(compiler, 'C', operatorName('-', false));
848 checkMemberResolved(compiler, 'D', operatorName('-', false)); 849 checkMemberResolved(compiler, 'D', operatorName('-', false));
849 } 850 }
OLDNEW
« no previous file with comments | « tests/compiler/dart2js/part_of_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698