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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | pkg/unittest/test/matchers_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 part of matcher; 5 part of matcher;
6 6
7 /** 7 /**
8 * Returns a matcher that matches empty strings, maps or iterables 8 * Returns a matcher that matches empty strings, maps or iterables
9 * (including collections). 9 * (including collections).
10 */ 10 */
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 Description reason = null; 128 Description reason = null;
129 // If _limit is 1 we can only recurse one level into object. 129 // If _limit is 1 we can only recurse one level into object.
130 bool canRecurse = depth == 0 || _limit > 1; 130 bool canRecurse = depth == 0 || _limit > 1;
131 if (expected == actual) { 131 if (expected == actual) {
132 // Do nothing. 132 // Do nothing.
133 } else if (depth > _limit) { 133 } else if (depth > _limit) {
134 reason = new StringDescription('recursion depth limit exceeded'); 134 reason = new StringDescription('recursion depth limit exceeded');
135 } else { 135 } else {
136 if (expected is Iterable && canRecurse) { 136 if (expected is Iterable && canRecurse) {
137 String r = _compareIterables(expected, actual, 137 String r = _compareIterables(expected, actual,
138 _recursiveMatch, depth+1); 138 _recursiveMatch, depth+1);
139 if (r != null) reason = new StringDescription(r); 139 if (r != null) reason = new StringDescription(r);
140 } else if (expected is Map && canRecurse) { 140 } else if (expected is Map && canRecurse) {
141 if (actual is !Map) { 141 if (actual is !Map) {
142 reason = new StringDescription('expected a map'); 142 reason = new StringDescription('expected a map');
143 } else if (expected.length != actual.length) {
144 reason = new StringDescription('different map lengths');
145 } else { 143 } else {
144 var err = (expected.length == actual.length) ? '' :
145 'different map lengths; ';
146 for (var key in expected.keys) { 146 for (var key in expected.keys) {
147 if (!actual.containsKey(key)) { 147 if (!actual.containsKey(key)) {
148 reason = new StringDescription('missing map key '); 148 reason = new StringDescription(err);
149 reason.add('missing map key ');
149 reason.addDescriptionOf(key); 150 reason.addDescriptionOf(key);
150 break; 151 break;
151 } 152 }
152 reason = _recursiveMatch(expected[key], actual[key], 153 }
153 'with key <${key}> ${location}', depth+1); 154 if (reason == null) {
154 if (reason != null) { 155 for (var key in actual.keys) {
155 break; 156 if (!expected.containsKey(key)) {
157 reason = new StringDescription(err);
158 reason.add('extra map key ');
159 reason.addDescriptionOf(key);
160 break;
161 }
162 }
163 if (reason == null) {
164 for (var key in expected.keys) {
165 reason = _recursiveMatch(expected[key], actual[key],
166 'with key <${key}> ${location}', depth+1);
167 if (reason != null) {
168 break;
169 }
170 }
156 } 171 }
157 } 172 }
158 } 173 }
159 } else { 174 } else {
160 // If we have recursed, show the expected value too; if not, 175 // If we have recursed, show the expected value too; if not,
161 // expect() will show it for us. 176 // expect() will show it for us.
162 reason = new StringDescription(); 177 reason = new StringDescription();
163 if (depth > 1) { 178 if (depth > 1) {
164 reason.add('expected ').addDescriptionOf(expected).add(' but was '). 179 reason.add('expected ').addDescriptionOf(expected).add(' but was ').
165 addDescriptionOf(actual); 180 addDescriptionOf(actual);
(...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
697 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); 712 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher);
698 713
699 Description describeMismatch(item, Description mismatchDescription, 714 Description describeMismatch(item, Description mismatchDescription,
700 MatchState matchState, bool verbose) { 715 MatchState matchState, bool verbose) {
701 mismatchDescription.add(_featureName).add(' '); 716 mismatchDescription.add(_featureName).add(' ');
702 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, 717 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription,
703 matchState.state['innerState'], verbose); 718 matchState.state['innerState'], verbose);
704 return mismatchDescription; 719 return mismatchDescription;
705 } 720 }
706 } 721 }
OLDNEW
« 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