| 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 which matches if the match argument is greater | 8 * Returns a matcher which matches if the match argument is greater |
| 9 * than the given [value]. | 9 * than the given [value]. |
| 10 */ | 10 */ |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 * A matcher which matches if the match argument is zero or positive. | 70 * A matcher which matches if the match argument is zero or positive. |
| 71 */ | 71 */ |
| 72 const Matcher isNonNegative = | 72 const Matcher isNonNegative = |
| 73 const _OrderingComparison(0, true, false, true, | 73 const _OrderingComparison(0, true, false, true, |
| 74 'a non-negative value', false); | 74 'a non-negative value', false); |
| 75 | 75 |
| 76 bool _isNumeric(value) { | 76 bool _isNumeric(value) { |
| 77 return value is int || value is double; | 77 return value is int || value is double; |
| 78 } | 78 } |
| 79 | 79 |
| 80 class _OrderingComparison extends BaseMatcher { | 80 class _OrderingComparison extends Matcher { |
| 81 /** Expected value. */ | 81 /** Expected value. */ |
| 82 final _value; | 82 final _value; |
| 83 /** What to return if actual == expected */ | 83 /** What to return if actual == expected */ |
| 84 final bool _equalValue; | 84 final bool _equalValue; |
| 85 /** What to return if actual < expected */ | 85 /** What to return if actual < expected */ |
| 86 final bool _lessThanValue; | 86 final bool _lessThanValue; |
| 87 /** What to return if actual > expected */ | 87 /** What to return if actual > expected */ |
| 88 final bool _greaterThanValue; | 88 final bool _greaterThanValue; |
| 89 /** Textual name of the inequality */ | 89 /** Textual name of the inequality */ |
| 90 final String _comparisonDescription; | 90 final String _comparisonDescription; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 } | 126 } |
| 127 } | 127 } |
| 128 | 128 |
| 129 /** | 129 /** |
| 130 * Returns a matcher which matches if the match argument is within [delta] | 130 * Returns a matcher which matches if the match argument is within [delta] |
| 131 * of some [value]; i.e. if the match argument is greater than | 131 * of some [value]; i.e. if the match argument is greater than |
| 132 * than or equal [value]-[delta] and less than or equal to [value]+[delta]. | 132 * than or equal [value]-[delta] and less than or equal to [value]+[delta]. |
| 133 */ | 133 */ |
| 134 Matcher closeTo(value, delta) => new _IsCloseTo(value, delta); | 134 Matcher closeTo(value, delta) => new _IsCloseTo(value, delta); |
| 135 | 135 |
| 136 class _IsCloseTo extends BaseMatcher { | 136 class _IsCloseTo extends Matcher { |
| 137 final num _value, _delta; | 137 final num _value, _delta; |
| 138 | 138 |
| 139 const _IsCloseTo(this._value, this._delta); | 139 const _IsCloseTo(this._value, this._delta); |
| 140 | 140 |
| 141 bool matches(item, Map matchState) { | 141 bool matches(item, Map matchState) { |
| 142 if (!_isNumeric(item)) { | 142 if (!_isNumeric(item)) { |
| 143 return false; | 143 return false; |
| 144 } | 144 } |
| 145 var diff = item - _value; | 145 var diff = item - _value; |
| 146 if (diff < 0) diff = -diff; | 146 if (diff < 0) diff = -diff; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 * than [low] and less than or equal to [high]. | 184 * than [low] and less than or equal to [high]. |
| 185 */ | 185 */ |
| 186 Matcher inOpenClosedRange(low, high) => new _InRange(low, high, false, true); | 186 Matcher inOpenClosedRange(low, high) => new _InRange(low, high, false, true); |
| 187 | 187 |
| 188 /** | 188 /** |
| 189 * Returns a matcher which matches if the match argument is greater | 189 * Returns a matcher which matches if the match argument is greater |
| 190 * than or equal to a [low] and less than [high]. | 190 * than or equal to a [low] and less than [high]. |
| 191 */ | 191 */ |
| 192 Matcher inClosedOpenRange(low, high) => new _InRange(low, high, true, false); | 192 Matcher inClosedOpenRange(low, high) => new _InRange(low, high, true, false); |
| 193 | 193 |
| 194 class _InRange extends BaseMatcher { | 194 class _InRange extends Matcher { |
| 195 final num _low, _high; | 195 final num _low, _high; |
| 196 final bool _lowMatchValue, _highMatchValue; | 196 final bool _lowMatchValue, _highMatchValue; |
| 197 | 197 |
| 198 const _InRange(this._low, this._high, | 198 const _InRange(this._low, this._high, |
| 199 this._lowMatchValue, this._highMatchValue); | 199 this._lowMatchValue, this._highMatchValue); |
| 200 | 200 |
| 201 bool matches(value, Map matchState) { | 201 bool matches(value, Map matchState) { |
| 202 if (value is !num) { | 202 if (value is !num) { |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 225 return mismatchDescription. | 225 return mismatchDescription. |
| 226 addDescriptionOf(item). | 226 addDescriptionOf(item). |
| 227 add(' not numeric'); | 227 add(' not numeric'); |
| 228 } else { | 228 } else { |
| 229 return super.describeMismatch(item, mismatchDescription, | 229 return super.describeMismatch(item, mismatchDescription, |
| 230 matchState, verbose); | 230 matchState, verbose); |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 } | 233 } |
| 234 | 234 |
| OLD | NEW |