| 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 library matcher.operator_matchers; | 5 library matcher.operator_matchers; |
| 6 | 6 |
| 7 import 'interfaces.dart'; | 7 import 'interfaces.dart'; |
| 8 import 'util.dart'; | 8 import 'util.dart'; |
| 9 | 9 |
| 10 /// This returns a matcher that inverts [matcher] to its logical negation. | 10 /// This returns a matcher that inverts [matcher] to its logical negation. |
| 11 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); | 11 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); |
| 12 | 12 |
| 13 class _IsNot extends Matcher { | 13 class _IsNot extends Matcher { |
| 14 final Matcher _matcher; | 14 final Matcher _matcher; |
| 15 | 15 |
| 16 const _IsNot(this._matcher); | 16 const _IsNot(this._matcher); |
| 17 | 17 |
| 18 bool matches(item, Map matchState) => !_matcher.matches(item, matchState); | 18 bool matches(item, Map matchState) => !_matcher.matches(item, matchState); |
| 19 | 19 |
| 20 Description describe(Description description) => | 20 Description describe(Description description) => |
| 21 description.add('not ').addDescriptionOf(_matcher); | 21 description.add('not ').addDescriptionOf(_matcher); |
| 22 } | 22 } |
| 23 | 23 |
| 24 /// This returns a matcher that matches if all of the matchers passed as | 24 /// This returns a matcher that matches if all of the matchers passed as |
| 25 /// arguments (up to 7) match. Instead of passing the matchers separately | 25 /// arguments (up to 7) match. |
| 26 /// they can be passed as a single List argument. | 26 /// |
| 27 /// Any argument that is not a matcher is implicitly wrapped in a | 27 /// Instead of passing the matchers separately they can be passed as a single |
| 28 /// List argument. Any argument that is not a matcher is implicitly wrapped in a |
| 28 /// Matcher to check for equality. | 29 /// Matcher to check for equality. |
| 29 Matcher allOf(arg0, | 30 Matcher allOf(arg0, |
| 30 [arg1 = null, | 31 [arg1 = null, |
| 31 arg2 = null, | 32 arg2 = null, |
| 32 arg3 = null, | 33 arg3 = null, |
| 33 arg4 = null, | 34 arg4 = null, |
| 34 arg5 = null, | 35 arg5 = null, |
| 35 arg6 = null]) { | 36 arg6 = null]) { |
| 36 return new _AllOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6)); | 37 return new _AllOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6)); |
| 37 } | 38 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 56 var matcher = matchState['matcher']; | 57 var matcher = matchState['matcher']; |
| 57 matcher.describeMismatch(item, mismatchDescription, | 58 matcher.describeMismatch(item, mismatchDescription, |
| 58 matchState['state'], verbose); | 59 matchState['state'], verbose); |
| 59 return mismatchDescription; | 60 return mismatchDescription; |
| 60 } | 61 } |
| 61 | 62 |
| 62 Description describe(Description description) => | 63 Description describe(Description description) => |
| 63 description.addAll('(', ' and ', ')', _matchers); | 64 description.addAll('(', ' and ', ')', _matchers); |
| 64 } | 65 } |
| 65 | 66 |
| 66 /// Matches if any of the given matchers evaluate to true. The | 67 /// Matches if any of the given matchers evaluate to true. |
| 67 /// arguments can be a set of matchers as separate parameters | 68 /// |
| 69 /// The arguments can be a set of matchers as separate parameters |
| 68 /// (up to 7), or a List of matchers. | 70 /// (up to 7), or a List of matchers. |
| 69 /// | 71 /// |
| 70 /// The matchers are evaluated from left to right using short-circuit | 72 /// The matchers are evaluated from left to right using short-circuit |
| 71 /// evaluation, so evaluation stops as soon as a matcher returns true. | 73 /// evaluation, so evaluation stops as soon as a matcher returns true. |
| 72 /// | 74 /// |
| 73 /// Any argument that is not a matcher is implicitly wrapped in a | 75 /// Any argument that is not a matcher is implicitly wrapped in a |
| 74 /// Matcher to check for equality. | 76 /// Matcher to check for equality. |
| 75 | |
| 76 Matcher anyOf(arg0, | 77 Matcher anyOf(arg0, |
| 77 [arg1 = null, | 78 [arg1 = null, |
| 78 arg2 = null, | 79 arg2 = null, |
| 79 arg3 = null, | 80 arg3 = null, |
| 80 arg4 = null, | 81 arg4 = null, |
| 81 arg5 = null, | 82 arg5 = null, |
| 82 arg6 = null]) { | 83 arg6 = null]) { |
| 83 return new _AnyOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6)); | 84 return new _AnyOf(_wrapArgs(arg0, arg1, arg2, arg3, arg4, arg5, arg6)); |
| 84 } | 85 } |
| 85 | 86 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 113 matchers = arg0; | 114 matchers = arg0; |
| 114 } else { | 115 } else { |
| 115 matchers = [arg0, arg1, arg2, arg3, arg4, arg5, arg6] | 116 matchers = [arg0, arg1, arg2, arg3, arg4, arg5, arg6] |
| 116 .where((e) => e != null); | 117 .where((e) => e != null); |
| 117 } | 118 } |
| 118 | 119 |
| 119 return matchers | 120 return matchers |
| 120 .map((e) => wrapMatcher(e)) | 121 .map((e) => wrapMatcher(e)) |
| 121 .toList(); | 122 .toList(); |
| 122 } | 123 } |
| OLD | NEW |