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('matcherTest'); | 5 #library('matcherTest'); |
6 #import('../../../lib/unittest/unittest.dart'); | 6 #import('../../../lib/unittest/unittest.dart'); |
7 #source('test_utils.dart'); | 7 #source('test_utils.dart'); |
8 | 8 |
9 doesNotThrow() {} | 9 doesNotThrow() {} |
10 doesThrow() { throw 'X'; } | 10 doesThrow() { throw 'X'; } |
(...skipping 15 matching lines...) Expand all Loading... |
26 void main() { | 26 void main() { |
27 | 27 |
28 initUtils(); | 28 initUtils(); |
29 | 29 |
30 // Core matchers | 30 // Core matchers |
31 | 31 |
32 group('Core matchers', () { | 32 group('Core matchers', () { |
33 | 33 |
34 test('isTrue', () { | 34 test('isTrue', () { |
35 shouldPass(true, isTrue); | 35 shouldPass(true, isTrue); |
36 shouldFail(false, isTrue, "Expected: true but: was <false>"); | 36 shouldFail(false, isTrue, "Expected: true but: was <false>."); |
37 }); | 37 }); |
38 | 38 |
39 test('isFalse', () { | 39 test('isFalse', () { |
40 shouldPass(false, isFalse); | 40 shouldPass(false, isFalse); |
41 shouldFail(true, isFalse, "Expected: false but: was <true>"); | 41 shouldFail(true, isFalse, "Expected: false but: was <true>."); |
42 }); | 42 }); |
43 | 43 |
44 test('isNull', () { | 44 test('isNull', () { |
45 shouldPass(null, isNull); | 45 shouldPass(null, isNull); |
46 shouldFail(false, isNull, "Expected: null but: was <false>"); | 46 shouldFail(false, isNull, "Expected: null but: was <false>."); |
47 }); | 47 }); |
48 | 48 |
49 test('isNotNull', () { | 49 test('isNotNull', () { |
50 shouldPass(false, isNotNull); | 50 shouldPass(false, isNotNull); |
51 shouldFail(null, isNotNull, "Expected: not null but: was <null>"); | 51 shouldFail(null, isNotNull, "Expected: not null but: was <null>."); |
52 }); | 52 }); |
53 | 53 |
54 test('same', () { | 54 test('same', () { |
55 var a = new Map(); | 55 var a = new Map(); |
56 var b = new Map(); | 56 var b = new Map(); |
57 shouldPass(a, same(a)); | 57 shouldPass(a, same(a)); |
58 shouldFail(b, same(a), "Expected: same instance as <{}> but: was <{}>"); | 58 shouldFail(b, same(a), "Expected: same instance as <{}> but: was <{}>."); |
59 }); | 59 }); |
60 | 60 |
61 test('equals', () { | 61 test('equals', () { |
62 var a = new Map(); | 62 var a = new Map(); |
63 var b = new Map(); | 63 var b = new Map(); |
64 shouldPass(a, equals(a)); | 64 shouldPass(a, equals(a)); |
65 shouldPass(a, equals(b)); | 65 shouldPass(a, equals(b)); |
66 }); | 66 }); |
67 | 67 |
68 test('anything', () { | 68 test('anything', () { |
69 var a = new Map(); | 69 var a = new Map(); |
70 shouldPass(0, anything); | 70 shouldPass(0, anything); |
71 shouldPass(null, anything); | 71 shouldPass(null, anything); |
72 shouldPass(a, anything); | 72 shouldPass(a, anything); |
73 shouldFail(a, isNot(anything), "Expected: not anything but: was <{}>"); | 73 shouldFail(a, isNot(anything), "Expected: not anything but: was <{}>."); |
74 }); | 74 }); |
75 | 75 |
76 test('throws', () { | 76 test('throws', () { |
77 shouldFail(doesNotThrow, throws, | 77 shouldFail(doesNotThrow, throws, |
78 "Expected: throws an exception but: no exception"); | 78 "Expected: throws an exception but: no exception."); |
79 shouldPass(doesThrow, throws); | 79 shouldPass(doesThrow, throws); |
80 }); | 80 }); |
81 | 81 |
82 test('throwsA', () { | 82 test('throwsA', () { |
83 shouldPass(doesThrow, throwsA(equals('X'))); | 83 shouldPass(doesThrow, throwsA(equals('X'))); |
84 shouldFail(doesThrow, throwsA(equals('Y')), | 84 shouldFail(doesThrow, throwsA(equals('Y')), |
85 "Expected: throws an exception which matches 'Y' " | 85 "Expected: throws an exception which matches 'Y' " |
86 "but: no exception or exception does not match 'Y'"); | 86 "but: no exception or exception does not match 'Y'."); |
87 }); | 87 }); |
88 | 88 |
89 test('throwsBadNumberFormatException', () { | 89 test('throwsBadNumberFormatException', () { |
90 shouldPass(() { throw new BadNumberFormatException(''); }, | 90 shouldPass(() { throw new BadNumberFormatException(''); }, |
91 throwsBadNumberFormatException); | 91 throwsBadNumberFormatException); |
92 shouldFail(() { throw new Exception(); }, | 92 shouldFail(() { throw new Exception(); }, |
93 throwsBadNumberFormatException, | 93 throwsBadNumberFormatException, |
94 "Expected: throws an exception which matches BadNumberFormatException " | 94 "Expected: throws an exception which matches BadNumberFormatException " |
95 "but: no exception or exception does not match " | 95 "but: no exception or exception does not match " |
96 "BadNumberFormatException"); | 96 "BadNumberFormatException."); |
97 }); | 97 }); |
98 | 98 |
99 test('throwsIllegalArgumentException', () { | 99 test('throwsIllegalArgumentException', () { |
100 shouldPass(() { throw new IllegalArgumentException(''); }, | 100 shouldPass(() { throw new IllegalArgumentException(''); }, |
101 throwsIllegalArgumentException); | 101 throwsIllegalArgumentException); |
102 shouldFail(() { throw new Exception(); }, | 102 shouldFail(() { throw new Exception(); }, |
103 throwsIllegalArgumentException, | 103 throwsIllegalArgumentException, |
104 "Expected: throws an exception which matches IllegalArgumentException " | 104 "Expected: throws an exception which matches IllegalArgumentException " |
105 "but: no exception or exception does not match " | 105 "but: no exception or exception does not match " |
106 "IllegalArgumentException"); | 106 "IllegalArgumentException."); |
107 }); | 107 }); |
108 | 108 |
109 test('throwsIllegalJSRegExpException', () { | 109 test('throwsIllegalJSRegExpException', () { |
110 shouldPass(() { throw new IllegalJSRegExpException('',''); }, | 110 shouldPass(() { throw new IllegalJSRegExpException('',''); }, |
111 throwsIllegalJSRegExpException); | 111 throwsIllegalJSRegExpException); |
112 shouldFail(() { throw new Exception(); }, | 112 shouldFail(() { throw new Exception(); }, |
113 throwsIllegalJSRegExpException, | 113 throwsIllegalJSRegExpException, |
114 "Expected: throws an exception which matches IllegalJSRegExpException " | 114 "Expected: throws an exception which matches IllegalJSRegExpException " |
115 "but: no exception or exception does not match " | 115 "but: no exception or exception does not match " |
116 "IllegalJSRegExpException"); | 116 "IllegalJSRegExpException."); |
117 }); | 117 }); |
118 | 118 |
119 test('throwsIndexOutOfRangeException', () { | 119 test('throwsIndexOutOfRangeException', () { |
120 shouldPass(() { throw new IndexOutOfRangeException(0); }, | 120 shouldPass(() { throw new IndexOutOfRangeException(0); }, |
121 throwsIndexOutOfRangeException); | 121 throwsIndexOutOfRangeException); |
122 shouldFail(() { throw new Exception(); }, | 122 shouldFail(() { throw new Exception(); }, |
123 throwsIndexOutOfRangeException, | 123 throwsIndexOutOfRangeException, |
124 "Expected: throws an exception which matches IndexOutOfRangeException " | 124 "Expected: throws an exception which matches IndexOutOfRangeException " |
125 "but: no exception or exception does not match " | 125 "but: no exception or exception does not match " |
126 "IndexOutOfRangeException"); | 126 "IndexOutOfRangeException."); |
127 }); | 127 }); |
128 | 128 |
129 test('throwsNoSuchMethodException', () { | 129 test('throwsNoSuchMethodException', () { |
130 shouldPass(() { throw new NoSuchMethodException(null, '', null); }, | 130 shouldPass(() { throw new NoSuchMethodException(null, '', null); }, |
131 throwsNoSuchMethodException); | 131 throwsNoSuchMethodException); |
132 shouldFail(() { throw new Exception(); }, | 132 shouldFail(() { throw new Exception(); }, |
133 throwsNoSuchMethodException, | 133 throwsNoSuchMethodException, |
134 "Expected: throws an exception which matches NoSuchMethodException " | 134 "Expected: throws an exception which matches NoSuchMethodException " |
135 "but: no exception or exception does not match " | 135 "but: no exception or exception does not match " |
136 "NoSuchMethodException"); | 136 "NoSuchMethodException."); |
137 }); | 137 }); |
138 | 138 |
139 test('throwsNotImplementedException', () { | 139 test('throwsNotImplementedException', () { |
140 shouldPass(() { throw new NotImplementedException(''); }, | 140 shouldPass(() { throw new NotImplementedException(''); }, |
141 throwsNotImplementedException); | 141 throwsNotImplementedException); |
142 shouldFail(() { throw new Exception(); }, | 142 shouldFail(() { throw new Exception(); }, |
143 throwsNotImplementedException, | 143 throwsNotImplementedException, |
144 "Expected: throws an exception which matches NotImplementedException " | 144 "Expected: throws an exception which matches NotImplementedException " |
145 "but: no exception or exception does not match " | 145 "but: no exception or exception does not match " |
146 "NotImplementedException"); | 146 "NotImplementedException."); |
147 }); | 147 }); |
148 | 148 |
149 test('throwsNullPointerException', () { | 149 test('throwsNullPointerException', () { |
150 shouldPass(() { throw new NullPointerException(''); }, | 150 shouldPass(() { throw new NullPointerException(''); }, |
151 throwsNullPointerException); | 151 throwsNullPointerException); |
152 shouldFail(() { throw new Exception(); }, | 152 shouldFail(() { throw new Exception(); }, |
153 throwsNullPointerException, | 153 throwsNullPointerException, |
154 "Expected: throws an exception which matches NullPointerException " | 154 "Expected: throws an exception which matches NullPointerException " |
155 "but: no exception or exception does not match " | 155 "but: no exception or exception does not match " |
156 "NullPointerException"); | 156 "NullPointerException."); |
157 }); | 157 }); |
158 | 158 |
159 test('throwsUnsupportedOperationException', () { | 159 test('throwsUnsupportedOperationException', () { |
160 shouldPass(() { throw new UnsupportedOperationException(''); }, | 160 shouldPass(() { throw new UnsupportedOperationException(''); }, |
161 throwsUnsupportedOperationException); | 161 throwsUnsupportedOperationException); |
162 shouldFail(() { throw new Exception(); }, | 162 shouldFail(() { throw new Exception(); }, |
163 throwsUnsupportedOperationException, | 163 throwsUnsupportedOperationException, |
164 "Expected: throws an exception which matches " | 164 "Expected: throws an exception which matches " |
165 "UnsupportedOperationException " | 165 "UnsupportedOperationException " |
166 "but: no exception or exception does not match " | 166 "but: no exception or exception does not match " |
167 "UnsupportedOperationException"); | 167 "UnsupportedOperationException."); |
168 }); | 168 }); |
169 | 169 |
170 test('returnsNormally', () { | 170 test('returnsNormally', () { |
171 shouldPass(doesNotThrow, returnsNormally); | 171 shouldPass(doesNotThrow, returnsNormally); |
172 shouldFail(doesThrow, returnsNormally, | 172 shouldFail(doesThrow, returnsNormally, |
173 "Expected: return normally but: threw exception"); | 173 "Expected: return normally but: threw exception."); |
174 }); | 174 }); |
175 | 175 |
176 test('hasLength', () { | 176 test('hasLength', () { |
177 var a = new Map(); | 177 var a = new Map(); |
178 var b = new List(); | 178 var b = new List(); |
179 shouldPass(a, hasLength(0)); | 179 shouldPass(a, hasLength(0)); |
180 shouldPass(b, hasLength(0)); | 180 shouldPass(b, hasLength(0)); |
181 shouldPass('a', hasLength(1)); | 181 shouldPass('a', hasLength(1)); |
182 shouldFail(0, hasLength(0), new PrefixMatcher( | 182 shouldFail(0, hasLength(0), new PrefixMatcher( |
183 "Expected: an object with length of <0> " | 183 "Expected: an object with length of <0> " |
184 "but: was <0> has no length property")); | 184 "but: was <0> has no length property.")); |
185 | 185 |
186 b.add(0); | 186 b.add(0); |
187 shouldPass(b, hasLength(1)); | 187 shouldPass(b, hasLength(1)); |
188 shouldFail(b, hasLength(2), | 188 shouldFail(b, hasLength(2), |
189 "Expected: an object with length of <2> " | 189 "Expected: an object with length of <2> " |
190 "but: was <[0]> with length of <1>"); | 190 "but: was <[0]> with length of <1>."); |
191 | 191 |
192 b.add(0); | 192 b.add(0); |
193 shouldFail(b, hasLength(1), | 193 shouldFail(b, hasLength(1), |
194 "Expected: an object with length of <1> " | 194 "Expected: an object with length of <1> " |
195 "but: was <[0, 0]> with length of <2>"); | 195 "but: was <[0, 0]> with length of <2>."); |
196 shouldPass(b, hasLength(2)); | 196 shouldPass(b, hasLength(2)); |
197 }); | 197 }); |
198 }); | 198 }); |
199 | 199 |
200 group('Numeric Matchers', () { | 200 group('Numeric Matchers', () { |
201 | 201 |
202 test('greaterThan', () { | 202 test('greaterThan', () { |
203 shouldPass(10, greaterThan(9)); | 203 shouldPass(10, greaterThan(9)); |
204 shouldFail(9, greaterThan(10), | 204 shouldFail(9, greaterThan(10), |
205 "Expected: a value greater than <10> but: was <9>"); | 205 "Expected: a value greater than <10> but: was <9>."); |
206 }); | 206 }); |
207 | 207 |
208 test('greaterThanOrEqualTo', () { | 208 test('greaterThanOrEqualTo', () { |
209 shouldPass(10, greaterThanOrEqualTo(10)); | 209 shouldPass(10, greaterThanOrEqualTo(10)); |
210 shouldFail(9, greaterThanOrEqualTo(10), | 210 shouldFail(9, greaterThanOrEqualTo(10), |
211 "Expected: a value greater than or equal to <10> but: was <9>"); | 211 "Expected: a value greater than or equal to <10> but: was <9>."); |
212 }); | 212 }); |
213 | 213 |
214 test('lessThan', () { | 214 test('lessThan', () { |
215 shouldFail(10, lessThan(9), "Expected: a value less than <9> " | 215 shouldFail(10, lessThan(9), "Expected: a value less than <9> " |
216 "but: was <10>"); | 216 "but: was <10>."); |
217 shouldPass(9, lessThan(10)); | 217 shouldPass(9, lessThan(10)); |
218 }); | 218 }); |
219 | 219 |
220 test('lessThanOrEqualTo', () { | 220 test('lessThanOrEqualTo', () { |
221 shouldPass(10, lessThanOrEqualTo(10)); | 221 shouldPass(10, lessThanOrEqualTo(10)); |
222 shouldFail(11, lessThanOrEqualTo(10), | 222 shouldFail(11, lessThanOrEqualTo(10), |
223 "Expected: a value less than or equal to <10> but: was <11>"); | 223 "Expected: a value less than or equal to <10> but: was <11>."); |
224 }); | 224 }); |
225 | 225 |
226 test('isZero', () { | 226 test('isZero', () { |
227 shouldPass(0, isZero); | 227 shouldPass(0, isZero); |
228 shouldFail(1, isZero, "Expected: a value equal to <0> but: was <1>"); | 228 shouldFail(1, isZero, "Expected: a value equal to <0> but: was <1>."); |
229 }); | 229 }); |
230 | 230 |
231 test('isNonZero', () { | 231 test('isNonZero', () { |
232 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " | 232 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " |
233 "but: was <0>"); | 233 "but: was <0>."); |
234 shouldPass(1, isNonZero); | 234 shouldPass(1, isNonZero); |
235 }); | 235 }); |
236 | 236 |
237 test('isPositive', () { | 237 test('isPositive', () { |
238 shouldFail(-1, isPositive, "Expected: a positive value " | 238 shouldFail(-1, isPositive, "Expected: a positive value " |
239 "but: was <-1>"); | 239 "but: was <-1>."); |
240 shouldFail(0, isPositive, "Expected: a positive value " | 240 shouldFail(0, isPositive, "Expected: a positive value " |
241 "but: was <0>"); | 241 "but: was <0>."); |
242 shouldPass(1, isPositive); | 242 shouldPass(1, isPositive); |
243 }); | 243 }); |
244 | 244 |
245 test('isNegative', () { | 245 test('isNegative', () { |
246 shouldPass(-1, isNegative); | 246 shouldPass(-1, isNegative); |
247 shouldFail(0, isNegative, | 247 shouldFail(0, isNegative, |
248 "Expected: a negative value but: was <0>"); | 248 "Expected: a negative value but: was <0>."); |
249 }); | 249 }); |
250 | 250 |
251 test('isNonPositive', () { | 251 test('isNonPositive', () { |
252 shouldPass(-1, isNonPositive); | 252 shouldPass(-1, isNonPositive); |
253 shouldPass(0, isNonPositive); | 253 shouldPass(0, isNonPositive); |
254 shouldFail(1, isNonPositive, | 254 shouldFail(1, isNonPositive, |
255 "Expected: a non-positive value but: was <1>"); | 255 "Expected: a non-positive value but: was <1>."); |
256 }); | 256 }); |
257 | 257 |
258 test('isNonNegative', () { | 258 test('isNonNegative', () { |
259 shouldPass(1, isNonNegative); | 259 shouldPass(1, isNonNegative); |
260 shouldPass(0, isNonNegative); | 260 shouldPass(0, isNonNegative); |
261 shouldFail(-1, isNonNegative, | 261 shouldFail(-1, isNonNegative, |
262 "Expected: a non-negative value but: was <-1>"); | 262 "Expected: a non-negative value but: was <-1>."); |
263 }); | 263 }); |
264 | 264 |
265 test('closeTo', () { | 265 test('closeTo', () { |
266 shouldPass(0, closeTo(0, 1)); | 266 shouldPass(0, closeTo(0, 1)); |
267 shouldPass(-1, closeTo(0, 1)); | 267 shouldPass(-1, closeTo(0, 1)); |
268 shouldPass(1, closeTo(0, 1)); | 268 shouldPass(1, closeTo(0, 1)); |
269 shouldFail(1.001, closeTo(0, 1), | 269 shouldFail(1.001, closeTo(0, 1), |
270 "Expected: a numeric value within <1> of <0> " | 270 "Expected: a numeric value within <1> of <0> " |
271 "but: <1.001> differed by <1.001>"); | 271 "but: <1.001> differed by <1.001>."); |
272 shouldFail(-1.001, closeTo(0, 1), | 272 shouldFail(-1.001, closeTo(0, 1), |
273 "Expected: a numeric value within <1> of <0> " | 273 "Expected: a numeric value within <1> of <0> " |
274 "but: <-1.001> differed by <1.001>"); | 274 "but: <-1.001> differed by <1.001>."); |
275 }); | 275 }); |
276 | 276 |
277 test('inInclusiveRange', () { | 277 test('inInclusiveRange', () { |
278 shouldFail(-1, inInclusiveRange(0,2), | 278 shouldFail(-1, inInclusiveRange(0,2), |
279 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 279 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
280 "but: was <-1>"); | 280 "but: was <-1>."); |
281 shouldPass(0, inInclusiveRange(0,2)); | 281 shouldPass(0, inInclusiveRange(0,2)); |
282 shouldPass(1, inInclusiveRange(0,2)); | 282 shouldPass(1, inInclusiveRange(0,2)); |
283 shouldPass(2, inInclusiveRange(0,2)); | 283 shouldPass(2, inInclusiveRange(0,2)); |
284 shouldFail(3, inInclusiveRange(0,2), | 284 shouldFail(3, inInclusiveRange(0,2), |
285 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " | 285 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " |
286 "but: was <3>"); | 286 "but: was <3>."); |
287 }); | 287 }); |
288 | 288 |
289 test('inExclusiveRange', () { | 289 test('inExclusiveRange', () { |
290 shouldFail(0, inExclusiveRange(0,2), | 290 shouldFail(0, inExclusiveRange(0,2), |
291 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 291 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
292 "but: was <0>"); | 292 "but: was <0>."); |
293 shouldPass(1, inExclusiveRange(0,2)); | 293 shouldPass(1, inExclusiveRange(0,2)); |
294 shouldFail(2, inExclusiveRange(0,2), | 294 shouldFail(2, inExclusiveRange(0,2), |
295 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " | 295 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " |
296 "but: was <2>"); | 296 "but: was <2>."); |
297 }); | 297 }); |
298 | 298 |
299 test('inOpenClosedRange', () { | 299 test('inOpenClosedRange', () { |
300 shouldFail(0, inOpenClosedRange(0,2), | 300 shouldFail(0, inOpenClosedRange(0,2), |
301 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " | 301 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " |
302 "but: was <0>"); | 302 "but: was <0>."); |
303 shouldPass(1, inOpenClosedRange(0,2)); | 303 shouldPass(1, inOpenClosedRange(0,2)); |
304 shouldPass(2, inOpenClosedRange(0,2)); | 304 shouldPass(2, inOpenClosedRange(0,2)); |
305 }); | 305 }); |
306 | 306 |
307 test('inClosedOpenRange', () { | 307 test('inClosedOpenRange', () { |
308 shouldPass(0, inClosedOpenRange(0,2)); | 308 shouldPass(0, inClosedOpenRange(0,2)); |
309 shouldPass(1, inClosedOpenRange(0,2)); | 309 shouldPass(1, inClosedOpenRange(0,2)); |
310 shouldFail(2, inClosedOpenRange(0,2), | 310 shouldFail(2, inClosedOpenRange(0,2), |
311 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " | 311 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " |
312 "but: was <2>"); | 312 "but: was <2>."); |
313 }); | 313 }); |
314 }); | 314 }); |
315 | 315 |
316 group('String Matchers', () { | 316 group('String Matchers', () { |
317 | 317 |
318 test('isEmpty', () { | 318 test('isEmpty', () { |
319 shouldPass('', isEmpty); | 319 shouldPass('', isEmpty); |
320 shouldFail(null, isEmpty, | 320 shouldFail(null, isEmpty, |
321 "Expected: empty but: was <null>"); | 321 "Expected: empty but: was <null>."); |
322 shouldFail(0, isEmpty, | 322 shouldFail(0, isEmpty, |
323 "Expected: empty but: was <0>"); | 323 "Expected: empty but: was <0>."); |
324 shouldFail('a', isEmpty, "Expected: empty but: was 'a'"); | 324 shouldFail('a', isEmpty, "Expected: empty but: was 'a'."); |
325 }); | 325 }); |
326 | 326 |
327 test('equalsIgnoringCase', () { | 327 test('equalsIgnoringCase', () { |
328 shouldPass('hello', equalsIgnoringCase('HELLO')); | 328 shouldPass('hello', equalsIgnoringCase('HELLO')); |
329 shouldFail('hi', equalsIgnoringCase('HELLO'), | 329 shouldFail('hi', equalsIgnoringCase('HELLO'), |
330 "Expected: 'HELLO' ignoring case but: was 'hi'"); | 330 "Expected: 'HELLO' ignoring case but: was 'hi'."); |
331 }); | 331 }); |
332 | 332 |
333 test('equalsIgnoringWhitespace', () { | 333 test('equalsIgnoringWhitespace', () { |
334 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); | 334 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); |
335 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), | 335 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), |
336 "Expected: 'hello world' ignoring whitespace but: was 'helloworld'"); | 336 "Expected: 'hello world' ignoring whitespace but: was 'helloworld'."); |
337 }); | 337 }); |
338 | 338 |
339 test('startsWith', () { | 339 test('startsWith', () { |
340 shouldPass('hello', startsWith('')); | 340 shouldPass('hello', startsWith('')); |
341 shouldPass('hello', startsWith('hell')); | 341 shouldPass('hello', startsWith('hell')); |
342 shouldPass('hello', startsWith('hello')); | 342 shouldPass('hello', startsWith('hello')); |
343 shouldFail('hello', startsWith('hello '), | 343 shouldFail('hello', startsWith('hello '), |
344 "Expected: a string starting with 'hello ' but: was 'hello'"); | 344 "Expected: a string starting with 'hello ' but: was 'hello'."); |
345 }); | 345 }); |
346 | 346 |
347 test('endsWith', () { | 347 test('endsWith', () { |
348 shouldPass('hello', endsWith('')); | 348 shouldPass('hello', endsWith('')); |
349 shouldPass('hello', endsWith('lo')); | 349 shouldPass('hello', endsWith('lo')); |
350 shouldPass('hello', endsWith('hello')); | 350 shouldPass('hello', endsWith('hello')); |
351 shouldFail('hello', endsWith(' hello'), | 351 shouldFail('hello', endsWith(' hello'), |
352 "Expected: a string ending with ' hello' but: was 'hello'"); | 352 "Expected: a string ending with ' hello' but: was 'hello'."); |
353 }); | 353 }); |
354 | 354 |
355 test('contains', () { | 355 test('contains', () { |
356 shouldPass('hello', contains('')); | 356 shouldPass('hello', contains('')); |
357 shouldPass('hello', contains('h')); | 357 shouldPass('hello', contains('h')); |
358 shouldPass('hello', contains('o')); | 358 shouldPass('hello', contains('o')); |
359 shouldPass('hello', contains('hell')); | 359 shouldPass('hello', contains('hell')); |
360 shouldPass('hello', contains('hello')); | 360 shouldPass('hello', contains('hello')); |
361 shouldFail('hello', contains(' '), | 361 shouldFail('hello', contains(' '), |
362 "Expected: contains ' ' but: was 'hello'"); | 362 "Expected: contains ' ' but: was 'hello'."); |
363 }); | 363 }); |
364 | 364 |
365 test('stringContainsInOrder', () { | 365 test('stringContainsInOrder', () { |
366 shouldPass('goodbye cruel world', stringContainsInOrder([''])); | 366 shouldPass('goodbye cruel world', stringContainsInOrder([''])); |
367 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); | 367 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); |
368 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); | 368 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); |
369 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); | 369 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); |
370 shouldPass('goodbye cruel world', | 370 shouldPass('goodbye cruel world', |
371 stringContainsInOrder(['good', 'bye', 'world'])); | 371 stringContainsInOrder(['good', 'bye', 'world'])); |
372 shouldPass('goodbye cruel world', | 372 shouldPass('goodbye cruel world', |
373 stringContainsInOrder(['goodbye', 'cruel'])); | 373 stringContainsInOrder(['goodbye', 'cruel'])); |
374 shouldPass('goodbye cruel world', | 374 shouldPass('goodbye cruel world', |
375 stringContainsInOrder(['cruel', 'world'])); | 375 stringContainsInOrder(['cruel', 'world'])); |
376 shouldPass('goodbye cruel world', | 376 shouldPass('goodbye cruel world', |
377 stringContainsInOrder(['goodbye', 'cruel', 'world'])); | 377 stringContainsInOrder(['goodbye', 'cruel', 'world'])); |
378 shouldFail('goodbye cruel world', | 378 shouldFail('goodbye cruel world', |
379 stringContainsInOrder(['goo', 'cruel', 'bye']), | 379 stringContainsInOrder(['goo', 'cruel', 'bye']), |
380 "Expected: a string containing 'goo', 'cruel', 'bye' in order " | 380 "Expected: a string containing 'goo', 'cruel', 'bye' in order " |
381 "but: was 'goodbye cruel world'"); | 381 "but: was 'goodbye cruel world'."); |
382 }); | 382 }); |
383 | 383 |
384 test('matches', () { | 384 test('matches', () { |
385 shouldPass('c0d', matches('[a-z][0-9][a-z]')); | 385 shouldPass('c0d', matches('[a-z][0-9][a-z]')); |
386 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); | 386 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); |
387 shouldFail('cOd', matches('[a-z][0-9][a-z]'), | 387 shouldFail('cOd', matches('[a-z][0-9][a-z]'), |
388 "Expected: match '[a-z][0-9][a-z]' but: was 'cOd'"); | 388 "Expected: match '[a-z][0-9][a-z]' but: was 'cOd'."); |
389 }); | 389 }); |
390 }); | 390 }); |
391 | 391 |
392 group('Collection Matchers', () { | 392 group('Collection Matchers', () { |
393 | 393 |
394 test('isEmpty', () { | 394 test('isEmpty', () { |
395 shouldPass([], isEmpty); | 395 shouldPass([], isEmpty); |
396 shouldFail([1], isEmpty, "Expected: empty but: was <[1]>"); | 396 shouldFail([1], isEmpty, "Expected: empty but: was <[1]>."); |
397 }); | 397 }); |
398 | 398 |
399 test('contains', () { | 399 test('contains', () { |
400 var d = [1, 2]; | 400 var d = [1, 2]; |
401 shouldPass(d, contains(1)); | 401 shouldPass(d, contains(1)); |
402 shouldFail(d, contains(0), "Expected: contains <0> but: was <[1, 2]>"); | 402 shouldFail(d, contains(0), "Expected: contains <0> but: was <[1, 2]>."); |
403 }); | 403 }); |
404 | 404 |
405 test('isIn', () { | 405 test('isIn', () { |
406 var d = [1, 2]; | 406 var d = [1, 2]; |
407 shouldPass(1, isIn(d)); | 407 shouldPass(1, isIn(d)); |
408 shouldFail(0, isIn(d), "Expected: is in <[1, 2]> but: was <0>"); | 408 shouldFail(0, isIn(d), "Expected: is in <[1, 2]> but: was <0>."); |
409 }); | 409 }); |
410 | 410 |
411 test('everyElement', () { | 411 test('everyElement', () { |
412 var d = [1, 2]; | 412 var d = [1, 2]; |
413 var e = [1, 1, 1]; | 413 var e = [1, 1, 1]; |
414 shouldFail(d, everyElement(1), | 414 shouldFail(d, everyElement(1), |
415 "Expected: every element <1> but: was <[1, 2]>"); | 415 "Expected: every element <1> but: was <[1, 2]>."); |
416 shouldPass(e, everyElement(1)); | 416 shouldPass(e, everyElement(1)); |
417 }); | 417 }); |
418 | 418 |
419 test('someElement', () { | 419 test('someElement', () { |
420 var d = [1, 2]; | 420 var d = [1, 2]; |
421 var e = [1, 1, 1]; | 421 var e = [1, 1, 1]; |
422 shouldPass(d, someElement(2)); | 422 shouldPass(d, someElement(2)); |
423 shouldFail(e, someElement(2), | 423 shouldFail(e, someElement(2), |
424 "Expected: some element <2> but: was <[1, 1, 1]>"); | 424 "Expected: some element <2> but: was <[1, 1, 1]>."); |
425 }); | 425 }); |
426 | 426 |
427 test('orderedEquals', () { | 427 test('orderedEquals', () { |
428 shouldPass([null], orderedEquals([null])); | 428 shouldPass([null], orderedEquals([null])); |
429 var d = [1, 2]; | 429 var d = [1, 2]; |
430 shouldPass(d, orderedEquals([1, 2])); | 430 shouldPass(d, orderedEquals([1, 2])); |
431 shouldFail(d, orderedEquals([2, 1]), | 431 shouldFail(d, orderedEquals([2, 1]), |
432 "Expected: equals <[2, 1]> ordered " | 432 "Expected: equals <[2, 1]> ordered " |
433 "but: was <1> mismatch at position 0"); | 433 "but: was <1> mismatch at position 0."); |
434 }); | 434 }); |
435 | 435 |
436 test('unorderedEquals', () { | 436 test('unorderedEquals', () { |
437 var d = [1, 2]; | 437 var d = [1, 2]; |
438 shouldPass(d, unorderedEquals([2, 1])); | 438 shouldPass(d, unorderedEquals([2, 1])); |
439 shouldFail(d, unorderedEquals([1]), | 439 shouldFail(d, unorderedEquals([1]), |
440 "Expected: equals <[1]> unordered " | 440 "Expected: equals <[1]> unordered " |
441 "but: has too many elements (2 > 1)"); | 441 "but: has too many elements (2 > 1)."); |
442 shouldFail(d, unorderedEquals([3, 2, 1]), | 442 shouldFail(d, unorderedEquals([3, 2, 1]), |
443 "Expected: equals <[3, 2, 1]> unordered " | 443 "Expected: equals <[3, 2, 1]> unordered " |
444 "but: has too few elements (2 < 3)"); | 444 "but: has too few elements (2 < 3)."); |
445 shouldFail(d, unorderedEquals([3, 1]), | 445 shouldFail(d, unorderedEquals([3, 1]), |
446 "Expected: equals <[3, 1]> unordered " | 446 "Expected: equals <[3, 1]> unordered " |
447 "but: has no match for element <3> at position 0"); | 447 "but: has no match for element <3> at position 0."); |
448 }); | 448 }); |
449 }); | 449 }); |
450 | 450 |
451 group('Map Matchers', () { | 451 group('Map Matchers', () { |
452 | 452 |
453 test('isEmpty', () { | 453 test('isEmpty', () { |
454 var a = new Map(); | 454 var a = new Map(); |
455 shouldPass({}, isEmpty); | 455 shouldPass({}, isEmpty); |
456 shouldPass(a, isEmpty); | 456 shouldPass(a, isEmpty); |
457 a['foo'] = 'bar'; | 457 a['foo'] = 'bar'; |
458 shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>"); | 458 shouldFail(a, isEmpty, "Expected: empty but: was <{foo: bar}>."); |
459 }); | 459 }); |
460 | 460 |
461 test('contains', () { | 461 test('contains', () { |
462 var a = new Map(); | 462 var a = new Map(); |
463 a['foo'] = 'bar'; | 463 a['foo'] = 'bar'; |
464 var b = new Map(); | 464 var b = new Map(); |
465 shouldPass(a, contains('foo')); | 465 shouldPass(a, contains('foo')); |
466 shouldFail(b, contains('foo'), | 466 shouldFail(b, contains('foo'), |
467 "Expected: contains 'foo' but: was <{}>"); | 467 "Expected: contains 'foo' but: was <{}>."); |
468 shouldFail(10, contains('foo'), | 468 shouldFail(10, contains('foo'), |
469 "Expected: contains 'foo' but: was <10>"); | 469 "Expected: contains 'foo' but: was <10>."); |
470 }); | 470 }); |
471 | 471 |
472 test('containsValue', () { | 472 test('containsValue', () { |
473 var a = new Map(); | 473 var a = new Map(); |
474 a['foo'] = 'bar'; | 474 a['foo'] = 'bar'; |
475 shouldPass(a, containsValue('bar')); | 475 shouldPass(a, containsValue('bar')); |
476 shouldFail(a, containsValue('ba'), | 476 shouldFail(a, containsValue('ba'), |
477 "Expected: contains value 'ba' but: was <{foo: bar}>"); | 477 "Expected: contains value 'ba' but: was <{foo: bar}>."); |
478 }); | 478 }); |
479 | 479 |
480 test('containsPair', () { | 480 test('containsPair', () { |
481 var a = new Map(); | 481 var a = new Map(); |
482 a['foo'] = 'bar'; | 482 a['foo'] = 'bar'; |
483 shouldPass(a, containsPair('foo', 'bar')); | 483 shouldPass(a, containsPair('foo', 'bar')); |
484 shouldFail(a, containsPair('foo', 'ba'), | 484 shouldFail(a, containsPair('foo', 'ba'), |
485 "Expected: contains pair 'foo' => 'ba' " | 485 "Expected: contains pair 'foo' => 'ba' " |
486 "but: contains key 'foo' but with value was 'bar'"); | 486 "but: contains key 'foo' but with value was 'bar'."); |
487 shouldFail(a, containsPair('fo', 'bar'), | 487 shouldFail(a, containsPair('fo', 'bar'), |
488 "Expected: contains pair 'fo' => 'bar' " | 488 "Expected: contains pair 'fo' => 'bar' " |
489 "but: <{foo: bar}> doesn't contain key 'fo'"); | 489 "but: <{foo: bar}> doesn't contain key 'fo'."); |
490 }); | 490 }); |
491 | 491 |
492 test('hasLength', () { | 492 test('hasLength', () { |
493 var a = new Map(); | 493 var a = new Map(); |
494 a['foo'] = 'bar'; | 494 a['foo'] = 'bar'; |
495 var b = new Map(); | 495 var b = new Map(); |
496 shouldPass(a, hasLength(1)); | 496 shouldPass(a, hasLength(1)); |
497 shouldFail(b, hasLength(1), | 497 shouldFail(b, hasLength(1), |
498 "Expected: an object with length of <1> " | 498 "Expected: an object with length of <1> " |
499 "but: was <{}> with length of <0>"); | 499 "but: was <{}> with length of <0>."); |
500 }); | 500 }); |
501 }); | 501 }); |
502 | 502 |
503 group('Operator Matchers', () { | 503 group('Operator Matchers', () { |
504 | 504 |
505 test('anyOf', () { | 505 test('anyOf', () { |
506 shouldFail(0, anyOf([equals(1), equals(2)]), | 506 shouldFail(0, anyOf([equals(1), equals(2)]), |
507 "Expected: (<1> or <2>) but: was <0>"); | 507 "Expected: (<1> or <2>) but: was <0>."); |
508 shouldPass(1, anyOf([equals(1), equals(2)])); | 508 shouldPass(1, anyOf([equals(1), equals(2)])); |
509 }); | 509 }); |
510 | 510 |
511 test('allOf', () { | 511 test('allOf', () { |
512 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); | 512 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); |
513 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), | 513 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), |
514 "Expected: (a value less than <10> and a value greater than <0>) " | 514 "Expected: (a value less than <10> and a value greater than <0>) " |
515 "but: a value greater than <0> was <-1>"); | 515 "but: a value greater than <0> was <-1>."); |
516 }); | 516 }); |
517 }); | 517 }); |
518 | 518 |
519 group('Predicate Matchers', () { | 519 group('Predicate Matchers', () { |
520 test('isInstanceOf', () { | 520 test('isInstanceOf', () { |
521 shouldFail(0, predicate((x) => x is String, "an instance of String"), | 521 shouldFail(0, predicate((x) => x is String, "an instance of String"), |
522 "Expected: an instance of String but: was <0>"); | 522 "Expected: an instance of String but: was <0>."); |
523 shouldPass('cow', predicate((x) => x is String, "an instance of String")); | 523 shouldPass('cow', predicate((x) => x is String, "an instance of String")); |
524 }); | 524 }); |
525 }); | 525 }); |
526 } | 526 } |
527 | 527 |
OLD | NEW |