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

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

Issue 88483002: Compute suggestions for failed type promotions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years 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
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 library mock_compiler; 5 library mock_compiler;
6 6
7 import "package:expect/expect.dart"; 7 import "package:expect/expect.dart";
8 import 'dart:async'; 8 import 'dart:async';
9 import 'dart:collection'; 9 import 'dart:collection';
10 10
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 } 427 }
428 428
429 Element lookupElementIn(ScopeContainerElement container, name) { 429 Element lookupElementIn(ScopeContainerElement container, name) {
430 Element element = container.localLookup(name); 430 Element element = container.localLookup(name);
431 return element != null 431 return element != null
432 ? element 432 ? element
433 : new ErroneousElementX(null, null, name, container); 433 : new ErroneousElementX(null, null, name, container);
434 } 434 }
435 } 435 }
436 436
437 void compareWarningKinds(String text, expectedWarnings, foundWarnings) { 437 /// A function the checks [message]. If the check fails or if [message] is
438 /// `null`, an error string is returned. Otherwise `null` is returned.
439 typedef String CheckMessage(Message message);
440
441 CheckMessage checkMessage(MessageKind kind, Map arguments) {
442 return (Message message) {
443 if (message == null) return '$kind';
444 if (message.kind != kind) return 'Expected message $kind, found $message.';
445 for (var key in arguments.keys) {
446 if (!message.arguments.containsKey(key)) {
447 return 'Expected argument $key not found in $message.kind.';
448 }
449 String expectedValue = '${arguments[key]}';
450 String foundValue = '${message.arguments[key]}';
451 if (expectedValue != foundValue) {
452 return 'Expected argument $key with value $expectedValue, '
453 'found $foundValue.';
454 }
455 }
456 return null;
457 };
458 }
459
460 /// [expectedWarnings] must be a list of either [MessageKind] or [CheckMessage].
461 void compareWarningKinds(String text,
462 List expectedWarnings,
463 List<WarningMessage> foundWarnings) {
438 var fail = (message) => Expect.fail('$text: $message'); 464 var fail = (message) => Expect.fail('$text: $message');
439 HasNextIterator<MessageKind> expected = 465 HasNextIterator expectedIterator =
440 new HasNextIterator(expectedWarnings.iterator); 466 new HasNextIterator(expectedWarnings.iterator);
441 HasNextIterator<WarningMessage> found = 467 HasNextIterator<WarningMessage> foundIterator =
442 new HasNextIterator(foundWarnings.iterator); 468 new HasNextIterator(foundWarnings.iterator);
443 while (expected.hasNext && found.hasNext) { 469 while (expectedIterator.hasNext && foundIterator.hasNext) {
444 Expect.equals(expected.next(), found.next().message.kind); 470 var expected = expectedIterator.next();
471 var found = foundIterator.next();
472 if (expected is MessageKind) {
473 Expect.equals(expected, found.message.kind);
474 } else if (expected is CheckMessage) {
475 String error = expected(found.message);
476 Expect.isNull(error, error);
477 } else {
478 Expect.fail("Unexpected expectedWarnings value: $expected.");
479 }
445 } 480 }
446 if (expected.hasNext) { 481 if (expectedIterator.hasNext) {
447 do { 482 do {
448 print('Expected warning "${expected.next()}" did not occur'); 483 var expected = expectedIterator.next();
449 } while (expected.hasNext); 484 if (expected is CheckMessage) expected = expected(null);
485 print('Expected warning "${expected}" did not occur');
486 } while (expectedIterator.hasNext);
450 fail('Too few warnings'); 487 fail('Too few warnings');
451 } 488 }
452 if (found.hasNext) { 489 if (foundIterator.hasNext) {
453 do { 490 do {
454 print('Additional warning "${found.next()}"'); 491 print('Additional warning "${foundIterator.next()}"');
455 } while (found.hasNext); 492 } while (foundIterator.hasNext);
456 fail('Too many warnings'); 493 fail('Too many warnings');
457 } 494 }
458 } 495 }
459 496
460 void importLibrary(LibraryElement target, LibraryElementX imported, 497 void importLibrary(LibraryElement target, LibraryElementX imported,
461 Compiler compiler) { 498 Compiler compiler) {
462 for (var element in imported.localMembers) { 499 for (var element in imported.localMembers) {
463 compiler.withCurrentElement(element, () { 500 compiler.withCurrentElement(element, () {
464 target.addToScope(element, compiler); 501 target.addToScope(element, compiler);
465 }); 502 });
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 } else { 543 } else {
507 sourceFile = compiler.sourceFiles[uri.toString()]; 544 sourceFile = compiler.sourceFiles[uri.toString()];
508 } 545 }
509 if (sourceFile != null && begin != null && end != null) { 546 if (sourceFile != null && begin != null && end != null) {
510 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x)); 547 print(sourceFile.getLocationMessage(message, begin, end, true, (x) => x));
511 } else { 548 } else {
512 print(message); 549 print(message);
513 } 550 }
514 }; 551 };
515 } 552 }
OLDNEW
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/warnings.dart ('k') | tests/compiler/dart2js/type_checker_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698