| 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 library unittest.test_utils; | |
| 6 | |
| 7 import 'dart:collection'; | |
| 8 | |
| 9 import 'package:unittest/unittest.dart'; | |
| 10 | |
| 11 void shouldFail(value, Matcher matcher, expected) { | |
| 12 var failed = false; | |
| 13 try { | |
| 14 expect(value, matcher); | |
| 15 } on TestFailure catch (err) { | |
| 16 failed = true; | |
| 17 | |
| 18 var _errorString = err.message; | |
| 19 | |
| 20 if (expected is String) { | |
| 21 expect(_errorString, equalsIgnoringWhitespace(expected)); | |
| 22 } else { | |
| 23 expect(_errorString.replaceAll('\n', ''), expected); | |
| 24 } | |
| 25 } | |
| 26 | |
| 27 expect(failed, isTrue, reason: 'Expected to fail.'); | |
| 28 } | |
| 29 | |
| 30 void shouldPass(value, Matcher matcher) { | |
| 31 expect(value, matcher); | |
| 32 } | |
| 33 | |
| 34 class Widget { | |
| 35 int price; | |
| 36 } | |
| 37 | |
| 38 class HasPrice extends CustomMatcher { | |
| 39 HasPrice(matcher) : super("Widget with a price that is", "price", matcher); | |
| 40 featureValueOf(actual) => actual.price; | |
| 41 } | |
| 42 | |
| 43 class SimpleIterable extends IterableBase<int> { | |
| 44 final int count; | |
| 45 | |
| 46 SimpleIterable(this.count); | |
| 47 | |
| 48 bool contains(int val) => count < val ? false : true; | |
| 49 | |
| 50 bool any(bool f(element)) { | |
| 51 for (var i = 0; i <= count; i++) { | |
| 52 if (f(i)) return true; | |
| 53 } | |
| 54 return false; | |
| 55 } | |
| 56 | |
| 57 String toString() => "<[$count]>"; | |
| 58 | |
| 59 Iterator get iterator { | |
| 60 return new _SimpleIterator(count); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 class _SimpleIterator implements Iterator<int> { | |
| 65 int _count; | |
| 66 int _current; | |
| 67 | |
| 68 _SimpleIterator(this._count); | |
| 69 | |
| 70 bool moveNext() { | |
| 71 if (_count > 0) { | |
| 72 _current = _count; | |
| 73 _count--; | |
| 74 return true; | |
| 75 } | |
| 76 _current = null; | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 int get current => _current; | |
| 81 } | |
| OLD | NEW |