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 | 5 |
6 /** | 6 /** |
7 * Returns a matcher that matches empty strings, maps or collections. | 7 * Returns a matcher that matches empty strings, maps or collections. |
8 */ | 8 */ |
9 final Matcher isEmpty = const _Empty(); | 9 final Matcher isEmpty = const _Empty(); |
10 | 10 |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 293 } |
294 })); | 294 })); |
295 | 295 |
296 // It hasn't failed yet. | 296 // It hasn't failed yet. |
297 return true; | 297 return true; |
298 } | 298 } |
299 | 299 |
300 try { | 300 try { |
301 item(); | 301 item(); |
302 return false; | 302 return false; |
303 } catch (final e, final s) { | 303 } catch (e, s) { |
304 if (_matcher == null ||_matcher.matches(e, matchState)) { | 304 if (_matcher == null ||_matcher.matches(e, matchState)) { |
305 return true; | 305 return true; |
306 } else { | 306 } else { |
307 matchState.state = { | 307 matchState.state = { |
308 'exception' :e, | 308 'exception' :e, |
309 'stack': s | 309 'stack': s |
310 }; | 310 }; |
311 return false; | 311 return false; |
312 } | 312 } |
313 } | 313 } |
(...skipping 26 matching lines...) Expand all Loading... |
340 } | 340 } |
341 } | 341 } |
342 | 342 |
343 class _ReturnsNormally extends BaseMatcher { | 343 class _ReturnsNormally extends BaseMatcher { |
344 const _ReturnsNormally(); | 344 const _ReturnsNormally(); |
345 | 345 |
346 bool matches(f, MatchState matchState) { | 346 bool matches(f, MatchState matchState) { |
347 try { | 347 try { |
348 f(); | 348 f(); |
349 return true; | 349 return true; |
350 } catch (final e, final s) { | 350 } catch (e, s) { |
351 matchState.state = { | 351 matchState.state = { |
352 'exception' : e, | 352 'exception' : e, |
353 'stack': s | 353 'stack': s |
354 }; | 354 }; |
355 return false; | 355 return false; |
356 } | 356 } |
357 } | 357 } |
358 | 358 |
359 Description describe(Description description) => | 359 Description describe(Description description) => |
360 description.add("return normally"); | 360 description.add("return normally"); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 MatchState matchState, bool verbose) { | 531 MatchState matchState, bool verbose) { |
532 super.describeMismatch(item, mismatchDescription, matchState, verbose); | 532 super.describeMismatch(item, mismatchDescription, matchState, verbose); |
533 try { | 533 try { |
534 // We want to generate a different description if there is no length | 534 // We want to generate a different description if there is no length |
535 // property. This is harmless code that will throw if no length property | 535 // property. This is harmless code that will throw if no length property |
536 // but subtle enough that an optimizer shouldn't strip it out. | 536 // but subtle enough that an optimizer shouldn't strip it out. |
537 if (item.length * item.length >= 0) { | 537 if (item.length * item.length >= 0) { |
538 return mismatchDescription.add(' with length of '). | 538 return mismatchDescription.add(' with length of '). |
539 addDescriptionOf(item.length); | 539 addDescriptionOf(item.length); |
540 } | 540 } |
541 } catch (var e) { | 541 } catch (e) { |
542 return mismatchDescription.add(' has no length property'); | 542 return mismatchDescription.add(' has no length property'); |
543 } | 543 } |
544 } | 544 } |
545 } | 545 } |
546 | 546 |
547 /** | 547 /** |
548 * Returns a matcher that matches if the match argument contains | 548 * Returns a matcher that matches if the match argument contains |
549 * the expected value. For [String]s this means substring matching; | 549 * the expected value. For [String]s this means substring matching; |
550 * for [Map]s is means the map has the key, and for [Collection]s it | 550 * for [Map]s is means the map has the key, and for [Collection]s it |
551 * means the collection has a matching element. In the case of collections, | 551 * means the collection has a matching element. In the case of collections, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
617 final _matcher; | 617 final _matcher; |
618 final String _description; | 618 final String _description; |
619 | 619 |
620 const _Predicate(this._matcher, this._description); | 620 const _Predicate(this._matcher, this._description); |
621 | 621 |
622 bool matches(item, MatchState matchState) => _matcher(item); | 622 bool matches(item, MatchState matchState) => _matcher(item); |
623 | 623 |
624 Description describe(Description description) => | 624 Description describe(Description description) => |
625 description.add(_description); | 625 description.add(_description); |
626 } | 626 } |
OLD | NEW |