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 581 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
592 } catch (e) { | 592 } catch (e) { |
593 return mismatchDescription.add(' has no length property'); | 593 return mismatchDescription.add(' has no length property'); |
594 } | 594 } |
595 } | 595 } |
596 } | 596 } |
597 | 597 |
598 /** | 598 /** |
599 * Returns a matcher that matches if the match argument contains | 599 * Returns a matcher that matches if the match argument contains |
600 * the expected value. For [String]s this means substring matching; | 600 * the expected value. For [String]s this means substring matching; |
601 * for [Map]s it means the map has the key, and for [Iterable]s | 601 * for [Map]s it means the map has the key, and for [Iterable]s |
602 * (including [Collection]s) it means the iterable has a matching | 602 * (including [Iterable]s) it means the iterable has a matching |
603 * element. In the case of iterables, [expected] can itself be a | 603 * element. In the case of iterables, [expected] can itself be a |
604 * matcher. | 604 * matcher. |
605 */ | 605 */ |
606 Matcher contains(expected) => new _Contains(expected); | 606 Matcher contains(expected) => new _Contains(expected); |
607 | 607 |
608 class _Contains extends BaseMatcher { | 608 class _Contains extends BaseMatcher { |
609 | 609 |
610 final _expected; | 610 final _expected; |
611 | 611 |
612 const _Contains(this._expected); | 612 const _Contains(this._expected); |
(...skipping 25 matching lines...) Expand all Loading... |
638 | 638 |
639 class _In extends BaseMatcher { | 639 class _In extends BaseMatcher { |
640 | 640 |
641 final _expected; | 641 final _expected; |
642 | 642 |
643 const _In(this._expected); | 643 const _In(this._expected); |
644 | 644 |
645 bool matches(item, MatchState matchState) { | 645 bool matches(item, MatchState matchState) { |
646 if (_expected is String) { | 646 if (_expected is String) { |
647 return _expected.indexOf(item) >= 0; | 647 return _expected.indexOf(item) >= 0; |
648 } else if (_expected is Collection) { | 648 } else if (_expected is Iterable) { |
649 return _expected.any((e) => e == item); | 649 return _expected.any((e) => e == item); |
650 } else if (_expected is Map) { | 650 } else if (_expected is Map) { |
651 return _expected.containsKey(item); | 651 return _expected.containsKey(item); |
652 } | 652 } |
653 return false; | 653 return false; |
654 } | 654 } |
655 | 655 |
656 Description describe(Description description) => | 656 Description describe(Description description) => |
657 description.add('is in ').addDescriptionOf(_expected); | 657 description.add('is in ').addDescriptionOf(_expected); |
658 } | 658 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); | 722 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); |
723 | 723 |
724 Description describeMismatch(item, Description mismatchDescription, | 724 Description describeMismatch(item, Description mismatchDescription, |
725 MatchState matchState, bool verbose) { | 725 MatchState matchState, bool verbose) { |
726 mismatchDescription.add(_featureName).add(' '); | 726 mismatchDescription.add(_featureName).add(' '); |
727 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, | 727 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, |
728 matchState.state['innerState'], verbose); | 728 matchState.state['innerState'], verbose); |
729 return mismatchDescription; | 729 return mismatchDescription; |
730 } | 730 } |
731 } | 731 } |
OLD | NEW |