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