| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 library mock.times_matcher; | |
| 6 | |
| 7 import 'package:matcher/matcher.dart'; | |
| 8 | |
| 9 /** | |
| 10 * [_TimesMatcher]s are used to make assertions about the number of | |
| 11 * times a method was called. | |
| 12 */ | |
| 13 class _TimesMatcher extends Matcher { | |
| 14 final int min, max; | |
| 15 | |
| 16 const _TimesMatcher(this.min, [this.max = -1]); | |
| 17 | |
| 18 bool matches(logList, Map matchState) => logList.length >= min && | |
| 19 (max < 0 || logList.length <= max); | |
| 20 | |
| 21 Description describe(Description description) { | |
| 22 description.add('to be called '); | |
| 23 if (max < 0) { | |
| 24 description.add('at least $min'); | |
| 25 } else if (max == min) { | |
| 26 description.add('$max'); | |
| 27 } else if (min == 0) { | |
| 28 description.add('at most $max'); | |
| 29 } else { | |
| 30 description.add('between $min and $max'); | |
| 31 } | |
| 32 return description.add(' times'); | |
| 33 } | |
| 34 | |
| 35 Description describeMismatch(logList, Description mismatchDescription, | |
| 36 Map matchState, bool verbose) => | |
| 37 mismatchDescription.add('was called ${logList.length} times'); | |
| 38 } | |
| 39 | |
| 40 /** [happenedExactly] matches an exact number of calls. */ | |
| 41 Matcher happenedExactly(count) { | |
| 42 return new _TimesMatcher(count, count); | |
| 43 } | |
| 44 | |
| 45 /** [happenedAtLeast] matches a minimum number of calls. */ | |
| 46 Matcher happenedAtLeast(count) { | |
| 47 return new _TimesMatcher(count); | |
| 48 } | |
| 49 | |
| 50 /** [happenedAtMost] matches a maximum number of calls. */ | |
| 51 Matcher happenedAtMost(count) { | |
| 52 return new _TimesMatcher(0, count); | |
| 53 } | |
| 54 | |
| 55 /** [neverHappened] matches zero calls. */ | |
| 56 const Matcher neverHappened = const _TimesMatcher(0, 0); | |
| 57 | |
| 58 /** [happenedOnce] matches exactly one call. */ | |
| 59 const Matcher happenedOnce = const _TimesMatcher(1, 1); | |
| 60 | |
| 61 /** [happenedAtLeastOnce] matches one or more calls. */ | |
| 62 const Matcher happenedAtLeastOnce = const _TimesMatcher(1); | |
| 63 | |
| 64 /** [happenedAtMostOnce] matches zero or one call. */ | |
| 65 const Matcher happenedAtMostOnce = const _TimesMatcher(0, 1); | |
| OLD | NEW |