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.operator_matchers_test; | 5 library matcher.operator_matchers_test; |
6 | 6 |
7 import 'package:matcher/matcher.dart'; | 7 import 'package:matcher/matcher.dart'; |
8 import 'package:unittest/unittest.dart' show test, group; | 8 import 'package:unittest/unittest.dart' show test, group; |
9 | 9 |
10 import 'test_utils.dart'; | 10 import 'test_utils.dart'; |
11 | 11 |
12 void main() { | 12 void main() { |
13 initUtils(); | 13 initUtils(); |
14 | 14 |
15 test('anyOf', () { | 15 test('anyOf', () { |
| 16 // with a list |
16 shouldFail(0, anyOf([equals(1), equals(2)]), | 17 shouldFail(0, anyOf([equals(1), equals(2)]), |
17 "Expected: (<1> or <2>) Actual: <0>"); | 18 "Expected: (<1> or <2>) Actual: <0>"); |
18 shouldPass(1, anyOf([equals(1), equals(2)])); | 19 shouldPass(1, anyOf([equals(1), equals(2)])); |
| 20 |
| 21 // with individual items |
| 22 shouldFail(0, anyOf(equals(1), equals(2)), |
| 23 "Expected: (<1> or <2>) Actual: <0>"); |
| 24 shouldPass(1, anyOf(equals(1), equals(2))); |
19 }); | 25 }); |
20 | 26 |
21 test('allOf', () { | 27 test('allOf', () { |
| 28 // with a list |
22 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 29 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
23 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 30 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
24 "Expected: (a value less than <10> and a value greater than <0>) " | 31 "Expected: (a value less than <10> and a value greater than <0>) " |
25 "Actual: <-1> " | 32 "Actual: <-1> " |
26 "Which: is not a value greater than <0>"); | 33 "Which: is not a value greater than <0>"); |
| 34 |
| 35 // with individual items |
| 36 shouldPass(1, allOf(lessThan(10), greaterThan(0))); |
| 37 shouldFail(-1, allOf(lessThan(10), greaterThan(0)), |
| 38 "Expected: (a value less than <10> and a value greater than <0>) " |
| 39 "Actual: <-1> " |
| 40 "Which: is not a value greater than <0>"); |
| 41 |
| 42 // with maximum items |
| 43 shouldPass(1, allOf(lessThan(10), lessThan(9), lessThan(8), lessThan(7), |
| 44 lessThan(6), lessThan(5), lessThan(4))); |
| 45 shouldFail(4, allOf(lessThan(10), lessThan(9), lessThan(8), lessThan(7), |
| 46 lessThan(6), lessThan(5), lessThan(4)), |
| 47 "Expected: (a value less than <10> and a value less than <9> and a " |
| 48 "value less than <8> and a value less than <7> and a value less than " |
| 49 "<6> and a value less than <5> and a value less than <4>) " |
| 50 "Actual: <4> " |
| 51 "Which: is not a value less than <4>"); |
| 52 }); |
| 53 |
| 54 test('If the first argument is a List, the rest must be null', () { |
| 55 expect(() => allOf([], 5), throwsArgumentError); |
| 56 expect(() => anyOf([], null, null, null, null, null, 42), |
| 57 throwsArgumentError); |
27 }); | 58 }); |
28 } | 59 } |
OLD | NEW |