| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 part of unittest.matcher; | |
| 6 | |
| 7 /** | |
| 8 * This returns a matcher that inverts [matcher] to its logical negation. | |
| 9 */ | |
| 10 Matcher isNot(matcher) => new _IsNot(wrapMatcher(matcher)); | |
| 11 | |
| 12 class _IsNot extends Matcher { | |
| 13 final Matcher _matcher; | |
| 14 | |
| 15 const _IsNot(Matcher this._matcher); | |
| 16 | |
| 17 bool matches(item, Map matchState) => !_matcher.matches(item, matchState); | |
| 18 | |
| 19 Description describe(Description description) => | |
| 20 description.add('not ').addDescriptionOf(_matcher); | |
| 21 } | |
| 22 | |
| 23 /** | |
| 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 | |
| 26 * they can be passed as a single List argument. | |
| 27 * Any argument that is not a matcher is implicitly wrapped in a | |
| 28 * Matcher to check for equality. | |
| 29 */ | |
| 30 Matcher allOf(arg0, | |
| 31 [arg1 = null, | |
| 32 arg2 = null, | |
| 33 arg3 = null, | |
| 34 arg4 = null, | |
| 35 arg5 = null, | |
| 36 arg6 = null]) { | |
| 37 if (arg0 is List) { | |
| 38 expect(arg1, isNull); | |
| 39 expect(arg2, isNull); | |
| 40 expect(arg3, isNull); | |
| 41 expect(arg4, isNull); | |
| 42 expect(arg5, isNull); | |
| 43 expect(arg6, isNull); | |
| 44 for (int i = 0; i < arg0.length; i++) { | |
| 45 arg0[i] = wrapMatcher(arg0[i]); | |
| 46 } | |
| 47 return new _AllOf(arg0); | |
| 48 } else { | |
| 49 List matchers = new List(); | |
| 50 if (arg0 != null) { | |
| 51 matchers.add(wrapMatcher(arg0)); | |
| 52 } | |
| 53 if (arg1 != null) { | |
| 54 matchers.add(wrapMatcher(arg1)); | |
| 55 } | |
| 56 if (arg2 != null) { | |
| 57 matchers.add(wrapMatcher(arg2)); | |
| 58 } | |
| 59 if (arg3 != null) { | |
| 60 matchers.add(wrapMatcher(arg3)); | |
| 61 } | |
| 62 if (arg4 != null) { | |
| 63 matchers.add(wrapMatcher(arg4)); | |
| 64 } | |
| 65 if (arg5 != null) { | |
| 66 matchers.add(wrapMatcher(arg5)); | |
| 67 } | |
| 68 if (arg6 != null) { | |
| 69 matchers.add(wrapMatcher(arg6)); | |
| 70 } | |
| 71 return new _AllOf(matchers); | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 class _AllOf extends Matcher { | |
| 76 final Iterable<Matcher> _matchers; | |
| 77 | |
| 78 const _AllOf(this._matchers); | |
| 79 | |
| 80 bool matches(item, Map matchState) { | |
| 81 for (var matcher in _matchers) { | |
| 82 if (!matcher.matches(item, matchState)) { | |
| 83 addStateInfo(matchState, {'matcher': matcher}); | |
| 84 return false; | |
| 85 } | |
| 86 } | |
| 87 return true; | |
| 88 } | |
| 89 | |
| 90 Description describeMismatch(item, Description mismatchDescription, | |
| 91 Map matchState, bool verbose) { | |
| 92 var matcher = matchState['matcher']; | |
| 93 matcher.describeMismatch(item, mismatchDescription, | |
| 94 matchState['state'], verbose); | |
| 95 return mismatchDescription; | |
| 96 } | |
| 97 | |
| 98 Description describe(Description description) => | |
| 99 description.addAll('(', ' and ', ')', _matchers); | |
| 100 } | |
| 101 | |
| 102 /** | |
| 103 * Matches if any of the given matchers evaluate to true. The | |
| 104 * arguments can be a set of matchers as separate parameters | |
| 105 * (up to 7), or a List of matchers. | |
| 106 * | |
| 107 * The matchers are evaluated from left to right using short-circuit | |
| 108 * evaluation, so evaluation stops as soon as a matcher returns true. | |
| 109 * | |
| 110 * Any argument that is not a matcher is implicitly wrapped in a | |
| 111 * Matcher to check for equality. | |
| 112 */ | |
| 113 | |
| 114 Matcher anyOf(arg0, | |
| 115 [arg1 = null, | |
| 116 arg2 = null, | |
| 117 arg3 = null, | |
| 118 arg4 = null, | |
| 119 arg5 = null, | |
| 120 arg6 = null]) { | |
| 121 if (arg0 is List) { | |
| 122 expect(arg1, isNull); | |
| 123 expect(arg2, isNull); | |
| 124 expect(arg3, isNull); | |
| 125 expect(arg4, isNull); | |
| 126 expect(arg5, isNull); | |
| 127 expect(arg6, isNull); | |
| 128 for (int i = 0; i < arg0.length; i++) { | |
| 129 arg0[i] = wrapMatcher(arg0[i]); | |
| 130 } | |
| 131 return new _AnyOf(arg0); | |
| 132 } else { | |
| 133 List matchers = new List(); | |
| 134 if (arg0 != null) { | |
| 135 matchers.add(wrapMatcher(arg0)); | |
| 136 } | |
| 137 if (arg1 != null) { | |
| 138 matchers.add(wrapMatcher(arg1)); | |
| 139 } | |
| 140 if (arg2 != null) { | |
| 141 matchers.add(wrapMatcher(arg2)); | |
| 142 } | |
| 143 if (arg3 != null) { | |
| 144 matchers.add(wrapMatcher(arg3)); | |
| 145 } | |
| 146 if (arg4 != null) { | |
| 147 matchers.add(wrapMatcher(arg4)); | |
| 148 } | |
| 149 if (arg5 != null) { | |
| 150 matchers.add(wrapMatcher(arg5)); | |
| 151 } | |
| 152 if (arg6 != null) { | |
| 153 matchers.add(wrapMatcher(arg6)); | |
| 154 } | |
| 155 return new _AnyOf(matchers); | |
| 156 } | |
| 157 } | |
| 158 | |
| 159 class _AnyOf extends Matcher { | |
| 160 final Iterable<Matcher> _matchers; | |
| 161 | |
| 162 const _AnyOf(this._matchers); | |
| 163 | |
| 164 bool matches(item, Map matchState) { | |
| 165 for (var matcher in _matchers) { | |
| 166 if (matcher.matches(item, matchState)) { | |
| 167 return true; | |
| 168 } | |
| 169 } | |
| 170 return false; | |
| 171 } | |
| 172 | |
| 173 Description describe(Description description) => | |
| 174 description.addAll('(', ' or ', ')', _matchers); | |
| 175 } | |
| 176 | |
| OLD | NEW |