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.test_utils; | |
6 | |
7 import 'dart:collection'; | |
8 | |
9 import 'package:test/test.dart'; | 5 import 'package:test/test.dart'; |
10 | 6 |
11 void shouldFail(value, Matcher matcher, expected) { | 7 void shouldFail(value, Matcher matcher, expected) { |
12 var failed = false; | 8 var failed = false; |
13 try { | 9 try { |
14 expect(value, matcher); | 10 expect(value, matcher); |
15 } on TestFailure catch (err) { | 11 } on TestFailure catch (err) { |
16 failed = true; | 12 failed = true; |
17 | 13 |
18 var _errorString = err.message; | 14 var _errorString = err.message; |
(...skipping 19 matching lines...) Expand all Loading... |
38 | 34 |
39 class Widget { | 35 class Widget { |
40 int price; | 36 int price; |
41 } | 37 } |
42 | 38 |
43 class HasPrice extends CustomMatcher { | 39 class HasPrice extends CustomMatcher { |
44 HasPrice(matcher) : super("Widget with a price that is", "price", matcher); | 40 HasPrice(matcher) : super("Widget with a price that is", "price", matcher); |
45 featureValueOf(actual) => actual.price; | 41 featureValueOf(actual) => actual.price; |
46 } | 42 } |
47 | 43 |
48 class SimpleIterable extends IterableBase<int> { | 44 class SimpleIterable extends Iterable<int> { |
49 final int count; | 45 final int count; |
50 | 46 |
51 SimpleIterable(this.count); | 47 SimpleIterable(this.count); |
52 | 48 |
53 bool contains(int val) => count < val ? false : true; | 49 Iterator<int> get iterator => new _SimpleIterator(count); |
54 | |
55 bool any(bool f(element)) { | |
56 for (var i = 0; i <= count; i++) { | |
57 if (f(i)) return true; | |
58 } | |
59 return false; | |
60 } | |
61 | |
62 String toString() => "<[$count]>"; | |
63 | |
64 Iterator get iterator { | |
65 return new _SimpleIterator(count); | |
66 } | |
67 } | 50 } |
68 | 51 |
69 class _SimpleIterator implements Iterator<int> { | 52 class _SimpleIterator implements Iterator<int> { |
70 int _count; | 53 int _count; |
71 int _current; | 54 int _current; |
72 | 55 |
73 _SimpleIterator(this._count); | 56 _SimpleIterator(this._count); |
74 | 57 |
75 bool moveNext() { | 58 bool moveNext() { |
76 if (_count > 0) { | 59 if (_count > 0) { |
77 _current = _count; | 60 _current = _count; |
78 _count--; | 61 _count--; |
79 return true; | 62 return true; |
80 } | 63 } |
81 _current = null; | 64 _current = null; |
82 return false; | 65 return false; |
83 } | 66 } |
84 | 67 |
85 int get current => _current; | 68 int get current => _current; |
86 } | 69 } |
OLD | NEW |