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