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

Unified Diff: pkg/unittest/lib/src/core_matchers.dart

Issue 12210100: If two Maps are compared with an equals() matcher and they have the same length, (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/unittest/lib/src/core_matchers.dart
===================================================================
--- pkg/unittest/lib/src/core_matchers.dart (revision 18269)
+++ pkg/unittest/lib/src/core_matchers.dart (working copy)
@@ -135,25 +135,40 @@
} else {
if (expected is Iterable && canRecurse) {
String r = _compareIterables(expected, actual,
- _recursiveMatch, depth+1);
+ _recursiveMatch, depth+1);
if (r != null) reason = new StringDescription(r);
} else if (expected is Map && canRecurse) {
if (actual is !Map) {
reason = new StringDescription('expected a map');
- } else if (expected.length != actual.length) {
- reason = new StringDescription('different map lengths');
} else {
+ var err = (expected.length == actual.length) ? '' :
+ 'different map lengths; ';
for (var key in expected.keys) {
if (!actual.containsKey(key)) {
- reason = new StringDescription('missing map key ');
+ reason = new StringDescription(err);
+ reason.add('missing map key ');
reason.addDescriptionOf(key);
break;
}
- reason = _recursiveMatch(expected[key], actual[key],
- 'with key <${key}> ${location}', depth+1);
- if (reason != null) {
- break;
+ }
+ if (reason == null) {
+ for (var key in actual.keys) {
+ if (!expected.containsKey(key)) {
+ reason = new StringDescription(err);
+ reason.add('extra map key ');
+ reason.addDescriptionOf(key);
+ break;
+ }
}
+ if (reason == null) {
+ for (var key in expected.keys) {
+ reason = _recursiveMatch(expected[key], actual[key],
+ 'with key <${key}> ${location}', depth+1);
+ if (reason != null) {
+ break;
+ }
+ }
+ }
}
}
} else {
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698