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 // This file is for matcher tests that rely on the names of various Dart types. | 5 // This file is for matcher tests that rely on the names of various Dart types. |
6 // These tests will fail when run in minified dart2js, since the names will be | 6 // These tests will fail when run in minified dart2js, since the names will be |
7 // mangled. A version of this file that works in minified dart2js is in | 7 // mangled. A version of this file that works in minified dart2js is in |
8 // matchers_minified_test.dart. | 8 // matchers_minified_test.dart. |
9 | 9 |
10 library matcher.unminified_test; | 10 library matcher.unminified_test; |
11 | 11 |
12 import 'package:matcher/matcher.dart'; | 12 import 'package:matcher/matcher.dart'; |
13 import 'package:unittest/unittest.dart' show group, test; | 13 import 'package:unittest/unittest.dart' show group, test; |
14 | 14 |
15 import 'test_common.dart'; | 15 import 'test_common.dart'; |
16 import 'test_utils.dart'; | 16 import 'test_utils.dart'; |
17 | 17 |
18 void main() { | 18 void main() { |
19 initUtils(); | 19 initUtils(); |
20 | 20 |
21 group('Core matchers', () { | 21 group('Core matchers', () { |
22 test('throwsFormatException', () { | 22 test('throwsFormatException', () { |
23 shouldPass(() { throw new FormatException(''); }, | 23 shouldPass(() { |
24 throwsFormatException); | 24 throw new FormatException(''); |
25 shouldFail(() { throw new Exception(); }, | 25 }, throwsFormatException); |
26 throwsFormatException, | 26 shouldFail(() { |
27 matches( | 27 throw new Exception(); |
28 r"Expected: throws FormatException +" | 28 }, throwsFormatException, matches(r"Expected: throws FormatException +" |
29 r"Actual: <Closure(: \(\) => dynamic)?> +" | 29 r"Actual: <Closure(: \(\) => dynamic)?> +" |
30 r"Which: threw \?:<Exception>")); | 30 r"Which: threw \?:<Exception>")); |
31 | |
32 }); | 31 }); |
33 | 32 |
34 test('throwsArgumentError', () { | 33 test('throwsArgumentError', () { |
35 shouldPass(() { throw new ArgumentError(''); }, | 34 shouldPass(() { |
36 throwsArgumentError); | 35 throw new ArgumentError(''); |
37 shouldFail(() { throw new Exception(); }, | 36 }, throwsArgumentError); |
38 throwsArgumentError, | 37 shouldFail(() { |
39 matches( | 38 throw new Exception(); |
40 r"Expected: throws ArgumentError +" | 39 }, throwsArgumentError, matches(r"Expected: throws ArgumentError +" |
41 r"Actual: <Closure(: \(\) => dynamic)?> +" | 40 r"Actual: <Closure(: \(\) => dynamic)?> +" |
42 r"Which: threw \?:<Exception>")); | 41 r"Which: threw \?:<Exception>")); |
43 }); | 42 }); |
44 | 43 |
45 test('throwsRangeError', () { | 44 test('throwsRangeError', () { |
46 shouldPass(() { throw new RangeError(0); }, | 45 shouldPass(() { |
47 throwsRangeError); | 46 throw new RangeError(0); |
48 shouldFail(() { throw new Exception(); }, | 47 }, throwsRangeError); |
49 throwsRangeError, | 48 shouldFail(() { |
50 matches( | 49 throw new Exception(); |
51 r"Expected: throws RangeError +" | 50 }, throwsRangeError, matches(r"Expected: throws RangeError +" |
52 r"Actual: <Closure(: \(\) => dynamic)?> +" | 51 r"Actual: <Closure(: \(\) => dynamic)?> +" |
53 r"Which: threw \?:<Exception>")); | 52 r"Which: threw \?:<Exception>")); |
54 }); | 53 }); |
55 | 54 |
56 test('throwsNoSuchMethodError', () { | 55 test('throwsNoSuchMethodError', () { |
57 shouldPass(() { | 56 shouldPass(() { |
58 throw new NoSuchMethodError(null, const Symbol(''), null, null); | 57 throw new NoSuchMethodError(null, const Symbol(''), null, null); |
59 }, throwsNoSuchMethodError); | 58 }, throwsNoSuchMethodError); |
60 shouldFail(() { throw new Exception(); }, | 59 shouldFail(() { |
61 throwsNoSuchMethodError, | 60 throw new Exception(); |
62 matches( | 61 }, throwsNoSuchMethodError, matches( |
63 r"Expected: throws NoSuchMethodError +" | 62 r"Expected: throws NoSuchMethodError +" |
64 r"Actual: <Closure(: \(\) => dynamic)?> +" | 63 r"Actual: <Closure(: \(\) => dynamic)?> +" |
65 r"Which: threw \?:<Exception>")); | 64 r"Which: threw \?:<Exception>")); |
66 }); | 65 }); |
67 | 66 |
68 test('throwsUnimplementedError', () { | 67 test('throwsUnimplementedError', () { |
69 shouldPass(() { throw new UnimplementedError(''); }, | 68 shouldPass(() { |
70 throwsUnimplementedError); | 69 throw new UnimplementedError(''); |
71 shouldFail(() { throw new Exception(); }, | 70 }, throwsUnimplementedError); |
72 throwsUnimplementedError, | 71 shouldFail(() { |
73 matches( | 72 throw new Exception(); |
74 r"Expected: throws UnimplementedError +" | 73 }, throwsUnimplementedError, matches( |
75 r"Actual: <Closure(: \(\) => dynamic)?> +" | 74 r"Expected: throws UnimplementedError +" |
76 r"Which: threw \?:<Exception>")); | 75 r"Actual: <Closure(: \(\) => dynamic)?> +" |
| 76 r"Which: threw \?:<Exception>")); |
77 }); | 77 }); |
78 | 78 |
79 test('throwsUnsupportedError', () { | 79 test('throwsUnsupportedError', () { |
80 shouldPass(() { throw new UnsupportedError(''); }, | 80 shouldPass(() { |
81 throwsUnsupportedError); | 81 throw new UnsupportedError(''); |
82 shouldFail(() { throw new Exception(); }, | 82 }, throwsUnsupportedError); |
83 throwsUnsupportedError, | 83 shouldFail(() { |
84 matches( | 84 throw new Exception(); |
85 r"Expected: throws UnsupportedError +" | 85 }, throwsUnsupportedError, matches(r"Expected: throws UnsupportedError +" |
86 r"Actual: <Closure(: \(\) => dynamic)?> +" | 86 r"Actual: <Closure(: \(\) => dynamic)?> +" |
87 r"Which: threw \?:<Exception>")); | 87 r"Which: threw \?:<Exception>")); |
88 }); | 88 }); |
89 | 89 |
90 test('throwsStateError', () { | 90 test('throwsStateError', () { |
91 shouldPass(() { throw new StateError(''); }, | 91 shouldPass(() { |
92 throwsStateError); | 92 throw new StateError(''); |
93 shouldFail(() { throw new Exception(); }, | 93 }, throwsStateError); |
94 throwsStateError, | 94 shouldFail(() { |
95 matches( | 95 throw new Exception(); |
96 r"Expected: throws StateError +" | 96 }, throwsStateError, matches(r"Expected: throws StateError +" |
97 r"Actual: <Closure(: \(\) => dynamic)?> +" | 97 r"Actual: <Closure(: \(\) => dynamic)?> +" |
98 r"Which: threw \?:<Exception>")); | 98 r"Which: threw \?:<Exception>")); |
99 }); | 99 }); |
100 }); | 100 }); |
101 | 101 |
102 group('Iterable Matchers', () { | 102 group('Iterable Matchers', () { |
103 test('isEmpty', () { | 103 test('isEmpty', () { |
104 var d = new SimpleIterable(0); | 104 var d = new SimpleIterable(0); |
105 var e = new SimpleIterable(1); | 105 var e = new SimpleIterable(1); |
106 shouldPass(d, isEmpty); | 106 shouldPass(d, isEmpty); |
107 shouldFail(e, isEmpty, "Expected: empty " | 107 shouldFail(e, isEmpty, "Expected: empty " |
108 "Actual: SimpleIterable:[1]"); | 108 "Actual: SimpleIterable:[1]"); |
109 }); | 109 }); |
110 | 110 |
111 test('isNotEmpty', () { | 111 test('isNotEmpty', () { |
112 var d = new SimpleIterable(0); | 112 var d = new SimpleIterable(0); |
113 var e = new SimpleIterable(1); | 113 var e = new SimpleIterable(1); |
114 shouldPass(e, isNotEmpty); | 114 shouldPass(e, isNotEmpty); |
115 shouldFail(d, isNotEmpty, "Expected: non-empty " | 115 shouldFail(d, isNotEmpty, "Expected: non-empty " |
116 "Actual: SimpleIterable:[]"); | 116 "Actual: SimpleIterable:[]"); |
117 }); | 117 }); |
118 | 118 |
119 | |
120 test('contains', () { | 119 test('contains', () { |
121 var d = new SimpleIterable(3); | 120 var d = new SimpleIterable(3); |
122 shouldPass(d, contains(2)); | 121 shouldPass(d, contains(2)); |
123 shouldFail(d, contains(5), | 122 shouldFail(d, contains(5), "Expected: contains <5> " |
124 "Expected: contains <5> " | |
125 "Actual: SimpleIterable:[3, 2, 1]"); | 123 "Actual: SimpleIterable:[3, 2, 1]"); |
126 }); | 124 }); |
127 }); | 125 }); |
128 | 126 |
129 group('Feature Matchers', () { | 127 group('Feature Matchers', () { |
130 test("Feature Matcher", () { | 128 test("Feature Matcher", () { |
131 var w = new Widget(); | 129 var w = new Widget(); |
132 w.price = 10; | 130 w.price = 10; |
133 shouldPass(w, new HasPrice(10)); | 131 shouldPass(w, new HasPrice(10)); |
134 shouldPass(w, new HasPrice(greaterThan(0))); | 132 shouldPass(w, new HasPrice(greaterThan(0))); |
135 shouldFail(w, new HasPrice(greaterThan(10)), | 133 shouldFail(w, new HasPrice(greaterThan(10)), |
136 "Expected: Widget with a price that is a value greater than <10> " | 134 "Expected: Widget with a price that is a value greater than <10> " |
137 "Actual: <Instance of 'Widget'> " | 135 "Actual: <Instance of 'Widget'> " |
138 "Which: has price with value <10> which is not " | 136 "Which: has price with value <10> which is not " |
139 "a value greater than <10>"); | 137 "a value greater than <10>"); |
140 }); | 138 }); |
141 }); | 139 }); |
142 } | 140 } |
OLD | NEW |