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 unittestTests; | 5 library unittestTests; |
6 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 part 'test_utils.dart'; | 9 part 'test_utils.dart'; |
10 | 10 |
(...skipping 17 matching lines...) Expand all Loading... |
28 class Widget { | 28 class Widget { |
29 int price; | 29 int price; |
30 } | 30 } |
31 | 31 |
32 class HasPrice extends CustomMatcher { | 32 class HasPrice extends CustomMatcher { |
33 const HasPrice(matcher) : | 33 const HasPrice(matcher) : |
34 super("Widget with a price that is", "price", matcher); | 34 super("Widget with a price that is", "price", matcher); |
35 featureValueOf(actual) => actual.price; | 35 featureValueOf(actual) => actual.price; |
36 } | 36 } |
37 | 37 |
38 class SimpleIterable extends Iterable { | 38 class SimpleIterable extends IterableBase { |
39 int count; | 39 int count; |
40 SimpleIterable(this.count); | 40 SimpleIterable(this.count); |
41 | 41 |
42 bool contains(int val) => count < val ? false : true; | 42 bool contains(int val) => count < val ? false : true; |
43 | 43 |
44 bool any(bool f(element)) { | 44 bool any(bool f(element)) { |
45 for(var i = 0; i <= count; i++) { | 45 for(var i = 0; i <= count; i++) { |
46 if(f(i)) return true; | 46 if(f(i)) return true; |
47 } | 47 } |
48 return false; | 48 return false; |
49 } | 49 } |
50 | 50 |
51 String toString() => "<[$count]>"; | 51 String toString() => "<[$count]>"; |
52 | 52 |
53 Iterator get iterator { | 53 Iterator get iterator { |
54 return new SimpleIterator(count); | 54 return new SimpleIterator(count); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 class SimpleIterator implements Iterator { | 58 class SimpleIterator implements Iterator { |
59 int _count; | 59 int _count; |
60 int _current; | 60 int _current; |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 190 |
191 test('throwsUnsupportedError', () { | 191 test('throwsUnsupportedError', () { |
192 shouldPass(() { throw new UnsupportedError(''); }, | 192 shouldPass(() { throw new UnsupportedError(''); }, |
193 throwsUnsupportedError); | 193 throwsUnsupportedError); |
194 shouldFail(() { throw new Exception(); }, | 194 shouldFail(() { throw new Exception(); }, |
195 throwsUnsupportedError, | 195 throwsUnsupportedError, |
196 "Expected: throws an exception which matches UnsupportedError " | 196 "Expected: throws an exception which matches UnsupportedError " |
197 "but: exception <Exception> does not match " | 197 "but: exception <Exception> does not match " |
198 "UnsupportedError."); | 198 "UnsupportedError."); |
199 }); | 199 }); |
200 | 200 |
201 test('throwsStateError', () { | 201 test('throwsStateError', () { |
202 shouldPass(() { throw new StateError(''); }, | 202 shouldPass(() { throw new StateError(''); }, |
203 throwsStateError); | 203 throwsStateError); |
204 shouldFail(() { throw new Exception(); }, | 204 shouldFail(() { throw new Exception(); }, |
205 throwsStateError, | 205 throwsStateError, |
206 "Expected: throws an exception which matches StateError " | 206 "Expected: throws an exception which matches StateError " |
207 "but: exception <Exception> does not match " | 207 "but: exception <Exception> does not match " |
208 "StateError."); | 208 "StateError."); |
209 }); | 209 }); |
210 | 210 |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 }); | 446 }); |
447 }); | 447 }); |
448 | 448 |
449 group('Iterable Matchers', () { | 449 group('Iterable Matchers', () { |
450 test('isEmpty', () { | 450 test('isEmpty', () { |
451 var d = new SimpleIterable(0); | 451 var d = new SimpleIterable(0); |
452 var e = new SimpleIterable(1); | 452 var e = new SimpleIterable(1); |
453 shouldPass(d, isEmpty); | 453 shouldPass(d, isEmpty); |
454 shouldFail(e, isEmpty, "Expected: empty but: was <[1]>."); | 454 shouldFail(e, isEmpty, "Expected: empty but: was <[1]>."); |
455 }); | 455 }); |
456 | 456 |
457 test('contains', () { | 457 test('contains', () { |
458 var d = new SimpleIterable(3); | 458 var d = new SimpleIterable(3); |
459 shouldPass(d, contains(2)); | 459 shouldPass(d, contains(2)); |
460 shouldFail(d, contains(5), "Expected: contains <5> but: was <[3]>."); | 460 shouldFail(d, contains(5), "Expected: contains <5> but: was <[3]>."); |
461 }); | 461 }); |
462 }); | 462 }); |
463 | 463 |
464 group('Iterable Matchers', () { | 464 group('Iterable Matchers', () { |
465 | 465 |
466 test('isEmpty', () { | 466 test('isEmpty', () { |
467 shouldPass([], isEmpty); | 467 shouldPass([], isEmpty); |
468 shouldFail([1], isEmpty, "Expected: empty but: was <[1]>."); | 468 shouldFail([1], isEmpty, "Expected: empty but: was <[1]>."); |
469 }); | 469 }); |
470 | 470 |
471 test('contains', () { | 471 test('contains', () { |
472 var d = [1, 2]; | 472 var d = [1, 2]; |
473 shouldPass(d, contains(1)); | 473 shouldPass(d, contains(1)); |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 var w = new Widget(); | 703 var w = new Widget(); |
704 w.price = 10; | 704 w.price = 10; |
705 shouldPass(w, new HasPrice(greaterThan(0))); | 705 shouldPass(w, new HasPrice(greaterThan(0))); |
706 shouldFail(w, new HasPrice(greaterThan(10)), | 706 shouldFail(w, new HasPrice(greaterThan(10)), |
707 'Expected: Widget with a price that is a value greater than <10> ' | 707 'Expected: Widget with a price that is a value greater than <10> ' |
708 'but: price was <10>.'); | 708 'but: price was <10>.'); |
709 }); | 709 }); |
710 }); | 710 }); |
711 } | 711 } |
712 | 712 |
OLD | NEW |