Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 165 reason = _recursiveMatch(expected[key], actual[key], | 165 reason = _recursiveMatch(expected[key], actual[key], |
| 166 'with key <${key}> ${location}', depth+1); | 166 'with key <${key}> ${location}', depth+1); |
| 167 if (reason != null) { | 167 if (reason != null) { |
| 168 break; | 168 break; |
| 169 } | 169 } |
| 170 } | 170 } |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 } | 173 } |
| 174 } else { | 174 } else { |
| 175 reason = new StringDescription(); | |
| 176 var includeTypes = expected.runtimeType != actual.runtimeType; | |
| 175 // If we have recursed, show the expected value too; if not, | 177 // If we have recursed, show the expected value too; if not, |
| 176 // expect() will show it for us. | 178 // expect() will show it for us. As expect will not show type |
| 177 reason = new StringDescription(); | 179 // mismatches at the top level we handle those here too. |
| 178 if (depth > 1) { | 180 if (includeTypes || depth > 1) { |
| 179 reason.add('expected ').addDescriptionOf(expected).add(' but was '). | 181 reason.add('expected '); |
| 180 addDescriptionOf(actual); | 182 if (includeTypes) { |
| 181 } else { | 183 reason..add(expected.runtimeType).add(':'); |
| 182 reason.add('was ').addDescriptionOf(actual); | 184 } |
| 185 reason.addDescriptionOf(expected).add(' but '); | |
| 183 } | 186 } |
| 187 reason.add('was '); | |
| 188 if (includeTypes) { | |
| 189 reason..add(actual.runtimeType).add(':'); | |
| 190 } | |
| 191 reason.addDescriptionOf(actual); | |
| 184 } | 192 } |
| 185 } | 193 } |
| 186 if (reason != null && location.length > 0) { | 194 if (reason != null && location.length > 0) { |
| 187 reason.add(' ').add(location); | 195 reason.add(' ').add(location); |
| 188 } | 196 } |
| 189 return reason; | 197 return reason; |
| 190 } | 198 } |
| 191 | 199 |
| 192 String _match(expected, actual) { | 200 String _match(expected, actual) { |
| 193 Description reason = _recursiveMatch(expected, actual, '', 0); | 201 Description reason = _recursiveMatch(expected, actual, '', 0); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 313 var stackTrace = e.stackTrace.toString(); | 321 var stackTrace = e.stackTrace.toString(); |
| 314 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; | 322 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; |
| 315 reason = "Actual exception trace:\n$stackTrace"; | 323 reason = "Actual exception trace:\n$stackTrace"; |
| 316 } | 324 } |
| 317 expect(e.error, _matcher, reason: reason); | 325 expect(e.error, _matcher, reason: reason); |
| 318 }); | 326 }); |
| 319 }); | 327 }); |
| 320 | 328 |
| 321 // It hasn't failed yet. | 329 // It hasn't failed yet. |
| 322 return true; | 330 return true; |
| 331 } else if (item is! Function) { | |
|
Siggi Cherem (dart-lang)
2013/02/12 21:07:09
btw seems that the fix didn't make it to this patc
| |
| 332 return false; | |
| 323 } | 333 } |
| 324 | 334 |
| 325 try { | 335 try { |
| 326 item(); | 336 item(); |
| 327 return false; | 337 return false; |
| 328 } catch (e, s) { | 338 } catch (e, s) { |
| 329 if (_matcher == null ||_matcher.matches(e, matchState)) { | 339 if (_matcher == null ||_matcher.matches(e, matchState)) { |
| 330 return true; | 340 return true; |
| 331 } else { | 341 } else { |
| 332 matchState.state = { | 342 matchState.state = { |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 343 return description.add("throws an exception"); | 353 return description.add("throws an exception"); |
| 344 } else { | 354 } else { |
| 345 return description.add('throws an exception which matches '). | 355 return description.add('throws an exception which matches '). |
| 346 addDescriptionOf(_matcher); | 356 addDescriptionOf(_matcher); |
| 347 } | 357 } |
| 348 } | 358 } |
| 349 | 359 |
| 350 Description describeMismatch(item, Description mismatchDescription, | 360 Description describeMismatch(item, Description mismatchDescription, |
| 351 MatchState matchState, | 361 MatchState matchState, |
| 352 bool verbose) { | 362 bool verbose) { |
| 353 if (_matcher == null || matchState.state == null) { | 363 if (item is! Function && item is! Future) { |
| 364 return mismatchDescription.add(' not a Function or Future'); | |
| 365 } else if (_matcher == null || matchState.state == null) { | |
| 354 return mismatchDescription.add(' no exception'); | 366 return mismatchDescription.add(' no exception'); |
| 355 } else { | 367 } else { |
| 356 mismatchDescription. | 368 mismatchDescription. |
| 357 add(' exception ').addDescriptionOf(matchState.state['exception']); | 369 add(' exception ').addDescriptionOf(matchState.state['exception']); |
| 358 if (verbose) { | 370 if (verbose) { |
| 359 mismatchDescription.add(' at '). | 371 mismatchDescription.add(' at '). |
| 360 add(matchState.state['stack'].toString()); | 372 add(matchState.state['stack'].toString()); |
| 361 } | 373 } |
| 362 mismatchDescription.add(' does not match ').addDescriptionOf(_matcher); | 374 mismatchDescription.add(' does not match ').addDescriptionOf(_matcher); |
| 363 return mismatchDescription; | 375 return mismatchDescription; |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 712 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); | 724 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); |
| 713 | 725 |
| 714 Description describeMismatch(item, Description mismatchDescription, | 726 Description describeMismatch(item, Description mismatchDescription, |
| 715 MatchState matchState, bool verbose) { | 727 MatchState matchState, bool verbose) { |
| 716 mismatchDescription.add(_featureName).add(' '); | 728 mismatchDescription.add(_featureName).add(' '); |
| 717 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, | 729 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, |
| 718 matchState.state['innerState'], verbose); | 730 matchState.state['innerState'], verbose); |
| 719 return mismatchDescription; | 731 return mismatchDescription; |
| 720 } | 732 } |
| 721 } | 733 } |
| OLD | NEW |