Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(130)

Side by Side Diff: pkg/unittest/test/matchers_test.dart

Issue 15755005: Change output of string equality match failures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 import 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 7
8 import 'package:unittest/unittest.dart'; 8 import 'package:unittest/unittest.dart';
9 9
10 import 'test_common.dart'; 10 import 'test_common.dart';
11 import 'test_utils.dart'; 11 import 'test_utils.dart';
12 12
13 void main() { 13 void main() {
14 14
15 initUtils(); 15 initUtils();
16 16
17 // Core matchers 17 // Core matchers
18 18
19 group('Core matchers', () { 19 group('Core matchers', () {
20 20
21 test('isTrue', () { 21 test('isTrue', () {
22 shouldPass(true, isTrue); 22 shouldPass(true, isTrue);
23 shouldFail(false, isTrue, "Expected: true But: was <false>."); 23 shouldFail(false, isTrue, "Expected: true But: was <false>. "
24 "Actual: <false>");
24 }); 25 });
25 26
26 test('isFalse', () { 27 test('isFalse', () {
27 shouldPass(false, isFalse); 28 shouldPass(false, isFalse);
28 shouldFail(10, isFalse, "Expected: false But: was <10>."); 29 shouldFail(10, isFalse, "Expected: false But: was <10>. "
29 shouldFail(true, isFalse, "Expected: false But: was <true>."); 30 "Actual: <10>");
31 shouldFail(true, isFalse, "Expected: false But: was <true>. "
32 "Actual: <true>");
30 }); 33 });
31 34
32 test('isNull', () { 35 test('isNull', () {
33 shouldPass(null, isNull); 36 shouldPass(null, isNull);
34 shouldFail(false, isNull, "Expected: null But: was <false>."); 37 shouldFail(false, isNull, "Expected: null But: was <false>. "
38 "Actual: <false>");
35 }); 39 });
36 40
37 test('isNotNull', () { 41 test('isNotNull', () {
38 shouldPass(false, isNotNull); 42 shouldPass(false, isNotNull);
39 shouldFail(null, isNotNull, "Expected: not null But: was <null>."); 43 shouldFail(null, isNotNull, "Expected: not null But: was <null>. "
44 "Actual: <null>");
40 }); 45 });
41 46
42 test('same', () { 47 test('same', () {
43 var a = new Map(); 48 var a = new Map();
44 var b = new Map(); 49 var b = new Map();
45 shouldPass(a, same(a)); 50 shouldPass(a, same(a));
46 shouldFail(b, same(a), "Expected: same instance as {} But: was {}."); 51 shouldFail(b, same(a), "Expected: same instance as {} But: was {}. "
52 "Actual: {}");
47 }); 53 });
48 54
49 test('equals', () { 55 test('equals', () {
50 var a = new Map(); 56 var a = new Map();
51 var b = new Map(); 57 var b = new Map();
52 shouldPass(a, equals(a)); 58 shouldPass(a, equals(a));
53 shouldPass(a, equals(b)); 59 shouldPass(a, equals(b));
54 }); 60 });
55 61
56 test('anything', () { 62 test('anything', () {
57 var a = new Map(); 63 var a = new Map();
58 shouldPass(0, anything); 64 shouldPass(0, anything);
59 shouldPass(null, anything); 65 shouldPass(null, anything);
60 shouldPass(a, anything); 66 shouldPass(a, anything);
61 shouldFail(a, isNot(anything), "Expected: not anything But: was {}."); 67 shouldFail(a, isNot(anything), "Expected: not anything "
68 "But: was {}. Actual: {}");
62 }); 69 });
63 70
64 test('throws', () { 71 test('throws', () {
65 shouldFail(doesNotThrow, throws, 72 shouldFail(doesNotThrow, throws,
66 matches( 73 matches(
67 r"Expected: throws an exception +But: no exception\." 74 r"Expected: throws an exception +But: no exception\."
68 r"Actual: <Closure(: \(dynamic\) => dynamic " 75 r"Actual: <Closure(: \(dynamic\) => dynamic "
69 r"from Function 'doesNotThrow': static\.)?>")); 76 r"from Function 'doesNotThrow': static\.)?>"));
70 shouldPass(doesThrow, throws); 77 shouldPass(doesThrow, throws);
71 shouldFail(true, throws, 78 shouldFail(true, throws,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 shouldFail(b, hasLength(1), 121 shouldFail(b, hasLength(1),
115 "Expected: an object with length of <1> " 122 "Expected: an object with length of <1> "
116 "But: had length of <2>. " 123 "But: had length of <2>. "
117 "Actual: [0, 0]"); 124 "Actual: [0, 0]");
118 shouldPass(b, hasLength(2)); 125 shouldPass(b, hasLength(2));
119 }); 126 });
120 127
121 test('scalar type mismatch', () { 128 test('scalar type mismatch', () {
122 shouldFail('error', equals(5.1), 129 shouldFail('error', equals(5.1),
123 "Expected: <5.1> " 130 "Expected: <5.1> "
124 "But: was 'error'."); 131 "But: was 'error'. Actual: 'error'");
125 }); 132 });
126 133
127 test('nested type mismatch', () { 134 test('nested type mismatch', () {
128 shouldFail(['error'], equals([5.1]), 135 shouldFail(['error'], equals([5.1]),
129 "Expected: [5.1] " 136 "Expected: [5.1] "
130 "But: expected <5.1> but was 'error' mismatch at position 0. " 137 "But: expected <5.1> but was 'error' mismatch at position 0. "
131 "Actual: ['error']"); 138 "Actual: ['error']");
132 }); 139 });
133 140
134 test('doubly-nested type mismatch', () { 141 test('doubly-nested type mismatch', () {
135 shouldFail([['error']], equals([[5.1]]), 142 shouldFail([['error']], equals([[5.1]]),
136 "Expected: [[5.1]] " 143 "Expected: [[5.1]] "
137 "But: expected <5.1> but was 'error' " 144 "But: expected <5.1> but was 'error' "
138 "mismatch at position 0 mismatch at position 0. " 145 "mismatch at position 0 mismatch at position 0. "
139 "Actual: [['error']]"); 146 "Actual: [['error']]");
140 }); 147 });
141 }); 148 });
142 149
143 group('Numeric Matchers', () { 150 group('Numeric Matchers', () {
144 151
145 test('greaterThan', () { 152 test('greaterThan', () {
146 shouldPass(10, greaterThan(9)); 153 shouldPass(10, greaterThan(9));
147 shouldFail(9, greaterThan(10), 154 shouldFail(9, greaterThan(10),
148 "Expected: a value greater than <10> But: was <9>."); 155 "Expected: a value greater than <10> But: was <9>. Actual: <9>");
149 }); 156 });
150 157
151 test('greaterThanOrEqualTo', () { 158 test('greaterThanOrEqualTo', () {
152 shouldPass(10, greaterThanOrEqualTo(10)); 159 shouldPass(10, greaterThanOrEqualTo(10));
153 shouldFail(9, greaterThanOrEqualTo(10), 160 shouldFail(9, greaterThanOrEqualTo(10),
154 "Expected: a value greater than or equal to <10> But: was <9>."); 161 "Expected: a value greater than or equal to <10> But: was <9>. "
162 "Actual: <9>");
155 }); 163 });
156 164
157 test('lessThan', () { 165 test('lessThan', () {
158 shouldFail(10, lessThan(9), "Expected: a value less than <9> " 166 shouldFail(10, lessThan(9), "Expected: a value less than <9> "
159 "But: was <10>."); 167 "But: was <10>. Actual: <10>");
160 shouldPass(9, lessThan(10)); 168 shouldPass(9, lessThan(10));
161 }); 169 });
162 170
163 test('lessThanOrEqualTo', () { 171 test('lessThanOrEqualTo', () {
164 shouldPass(10, lessThanOrEqualTo(10)); 172 shouldPass(10, lessThanOrEqualTo(10));
165 shouldFail(11, lessThanOrEqualTo(10), 173 shouldFail(11, lessThanOrEqualTo(10),
166 "Expected: a value less than or equal to <10> But: was <11>."); 174 "Expected: a value less than or equal to <10> But: was <11>. "
175 "Actual: <11>");
167 }); 176 });
168 177
169 test('isZero', () { 178 test('isZero', () {
170 shouldPass(0, isZero); 179 shouldPass(0, isZero);
171 shouldFail(1, isZero, "Expected: a value equal to <0> But: was <1>."); 180 shouldFail(1, isZero, "Expected: a value equal to <0> But: was <1>."
181 " Actual: <1>");
172 }); 182 });
173 183
174 test('isNonZero', () { 184 test('isNonZero', () {
175 shouldFail(0, isNonZero, "Expected: a value not equal to <0> " 185 shouldFail(0, isNonZero, "Expected: a value not equal to <0> "
176 "But: was <0>."); 186 "But: was <0>. Actual: <0>");
177 shouldPass(1, isNonZero); 187 shouldPass(1, isNonZero);
178 }); 188 });
179 189
180 test('isPositive', () { 190 test('isPositive', () {
181 shouldFail(-1, isPositive, "Expected: a positive value " 191 shouldFail(-1, isPositive, "Expected: a positive value "
182 "But: was <-1>."); 192 "But: was <-1>. Actual: <-1>");
183 shouldFail(0, isPositive, "Expected: a positive value " 193 shouldFail(0, isPositive, "Expected: a positive value "
184 "But: was <0>."); 194 "But: was <0>. Actual: <0>");
185 shouldPass(1, isPositive); 195 shouldPass(1, isPositive);
186 }); 196 });
187 197
188 test('isNegative', () { 198 test('isNegative', () {
189 shouldPass(-1, isNegative); 199 shouldPass(-1, isNegative);
190 shouldFail(0, isNegative, 200 shouldFail(0, isNegative,
191 "Expected: a negative value But: was <0>."); 201 "Expected: a negative value But: was <0>. Actual: <0>");
192 }); 202 });
193 203
194 test('isNonPositive', () { 204 test('isNonPositive', () {
195 shouldPass(-1, isNonPositive); 205 shouldPass(-1, isNonPositive);
196 shouldPass(0, isNonPositive); 206 shouldPass(0, isNonPositive);
197 shouldFail(1, isNonPositive, 207 shouldFail(1, isNonPositive,
198 "Expected: a non-positive value But: was <1>."); 208 "Expected: a non-positive value But: was <1>. Actual: <1>");
199 }); 209 });
200 210
201 test('isNonNegative', () { 211 test('isNonNegative', () {
202 shouldPass(1, isNonNegative); 212 shouldPass(1, isNonNegative);
203 shouldPass(0, isNonNegative); 213 shouldPass(0, isNonNegative);
204 shouldFail(-1, isNonNegative, 214 shouldFail(-1, isNonNegative,
205 "Expected: a non-negative value But: was <-1>."); 215 "Expected: a non-negative value But: was <-1>. Actual: <-1>");
206 }); 216 });
207 217
208 test('closeTo', () { 218 test('closeTo', () {
209 shouldPass(0, closeTo(0, 1)); 219 shouldPass(0, closeTo(0, 1));
210 shouldPass(-1, closeTo(0, 1)); 220 shouldPass(-1, closeTo(0, 1));
211 shouldPass(1, closeTo(0, 1)); 221 shouldPass(1, closeTo(0, 1));
212 shouldFail(1.001, closeTo(0, 1), 222 shouldFail(1.001, closeTo(0, 1),
213 "Expected: a numeric value within <1> of <0> " 223 "Expected: a numeric value within <1> of <0> "
214 "But: differed by <1.001>. " 224 "But: differed by <1.001>. "
215 "Actual: <1.001>"); 225 "Actual: <1.001>");
216 shouldFail(-1.001, closeTo(0, 1), 226 shouldFail(-1.001, closeTo(0, 1),
217 "Expected: a numeric value within <1> of <0> " 227 "Expected: a numeric value within <1> of <0> "
218 "But: differed by <1.001>. " 228 "But: differed by <1.001>. "
219 "Actual: <-1.001>"); 229 "Actual: <-1.001>");
220 }); 230 });
221 231
222 test('inInclusiveRange', () { 232 test('inInclusiveRange', () {
223 shouldFail(-1, inInclusiveRange(0,2), 233 shouldFail(-1, inInclusiveRange(0,2),
224 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " 234 "Expected: be in range from 0 (inclusive) to 2 (inclusive) "
225 "But: was <-1>."); 235 "But: was <-1>. Actual: <-1>");
226 shouldPass(0, inInclusiveRange(0,2)); 236 shouldPass(0, inInclusiveRange(0,2));
227 shouldPass(1, inInclusiveRange(0,2)); 237 shouldPass(1, inInclusiveRange(0,2));
228 shouldPass(2, inInclusiveRange(0,2)); 238 shouldPass(2, inInclusiveRange(0,2));
229 shouldFail(3, inInclusiveRange(0,2), 239 shouldFail(3, inInclusiveRange(0,2),
230 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " 240 "Expected: be in range from 0 (inclusive) to 2 (inclusive) "
231 "But: was <3>."); 241 "But: was <3>. Actual: <3>");
232 }); 242 });
233 243
234 test('inExclusiveRange', () { 244 test('inExclusiveRange', () {
235 shouldFail(0, inExclusiveRange(0,2), 245 shouldFail(0, inExclusiveRange(0,2),
236 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " 246 "Expected: be in range from 0 (exclusive) to 2 (exclusive) "
237 "But: was <0>."); 247 "But: was <0>. Actual: <0>");
238 shouldPass(1, inExclusiveRange(0,2)); 248 shouldPass(1, inExclusiveRange(0,2));
239 shouldFail(2, inExclusiveRange(0,2), 249 shouldFail(2, inExclusiveRange(0,2),
240 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " 250 "Expected: be in range from 0 (exclusive) to 2 (exclusive) "
241 "But: was <2>."); 251 "But: was <2>. Actual: <2>");
242 }); 252 });
243 253
244 test('inOpenClosedRange', () { 254 test('inOpenClosedRange', () {
245 shouldFail(0, inOpenClosedRange(0,2), 255 shouldFail(0, inOpenClosedRange(0,2),
246 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " 256 "Expected: be in range from 0 (exclusive) to 2 (inclusive) "
247 "But: was <0>."); 257 "But: was <0>. Actual: <0>");
248 shouldPass(1, inOpenClosedRange(0,2)); 258 shouldPass(1, inOpenClosedRange(0,2));
249 shouldPass(2, inOpenClosedRange(0,2)); 259 shouldPass(2, inOpenClosedRange(0,2));
250 }); 260 });
251 261
252 test('inClosedOpenRange', () { 262 test('inClosedOpenRange', () {
253 shouldPass(0, inClosedOpenRange(0,2)); 263 shouldPass(0, inClosedOpenRange(0,2));
254 shouldPass(1, inClosedOpenRange(0,2)); 264 shouldPass(1, inClosedOpenRange(0,2));
255 shouldFail(2, inClosedOpenRange(0,2), 265 shouldFail(2, inClosedOpenRange(0,2),
256 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " 266 "Expected: be in range from 0 (inclusive) to 2 (exclusive) "
257 "But: was <2>."); 267 "But: was <2>. Actual: <2>");
258 }); 268 });
259 }); 269 });
260 270
261 group('String Matchers', () { 271 group('String Matchers', () {
262 272
263 test('isEmpty', () { 273 test('isEmpty', () {
264 shouldPass('', isEmpty); 274 shouldPass('', isEmpty);
265 shouldFail(null, isEmpty, 275 shouldFail(null, isEmpty,
266 "Expected: empty But: was <null>."); 276 "Expected: empty But: was <null>. Actual: <null>");
267 shouldFail(0, isEmpty, 277 shouldFail(0, isEmpty,
268 "Expected: empty But: was <0>."); 278 "Expected: empty But: was <0>. Actual: <0>");
269 shouldFail('a', isEmpty, "Expected: empty But: was 'a'."); 279 shouldFail('a', isEmpty, "Expected: empty But: was 'a'. Actual: 'a'");
270 }); 280 });
271 281
272 test('equalsIgnoringCase', () { 282 test('equalsIgnoringCase', () {
273 shouldPass('hello', equalsIgnoringCase('HELLO')); 283 shouldPass('hello', equalsIgnoringCase('HELLO'));
274 shouldFail('hi', equalsIgnoringCase('HELLO'), 284 shouldFail('hi', equalsIgnoringCase('HELLO'),
275 "Expected: 'HELLO' ignoring case But: was 'hi'."); 285 "Expected: 'HELLO' ignoring case But: was 'hi'. Actual: 'hi'");
276 }); 286 });
277 287
278 test('equalsIgnoringWhitespace', () { 288 test('equalsIgnoringWhitespace', () {
279 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); 289 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world'));
280 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), 290 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'),
281 "Expected: 'hello world' ignoring whitespace But: was 'helloworld'."); 291 "Expected: 'hello world' ignoring whitespace "
292 "But: was 'helloworld'. Actual: ' helloworld '");
282 }); 293 });
283 294
284 test('startsWith', () { 295 test('startsWith', () {
285 shouldPass('hello', startsWith('')); 296 shouldPass('hello', startsWith(''));
286 shouldPass('hello', startsWith('hell')); 297 shouldPass('hello', startsWith('hell'));
287 shouldPass('hello', startsWith('hello')); 298 shouldPass('hello', startsWith('hello'));
288 shouldFail('hello', startsWith('hello '), 299 shouldFail('hello', startsWith('hello '),
289 "Expected: a string starting with 'hello ' But: was 'hello'."); 300 "Expected: a string starting with 'hello ' "
301 "But: was 'hello'. Actual: 'hello'");
290 }); 302 });
291 303
292 test('endsWith', () { 304 test('endsWith', () {
293 shouldPass('hello', endsWith('')); 305 shouldPass('hello', endsWith(''));
294 shouldPass('hello', endsWith('lo')); 306 shouldPass('hello', endsWith('lo'));
295 shouldPass('hello', endsWith('hello')); 307 shouldPass('hello', endsWith('hello'));
296 shouldFail('hello', endsWith(' hello'), 308 shouldFail('hello', endsWith(' hello'),
297 "Expected: a string ending with ' hello' But: was 'hello'."); 309 "Expected: a string ending with ' hello' "
310 "But: was 'hello'. Actual: 'hello'");
298 }); 311 });
299 312
300 test('contains', () { 313 test('contains', () {
301 shouldPass('hello', contains('')); 314 shouldPass('hello', contains(''));
302 shouldPass('hello', contains('h')); 315 shouldPass('hello', contains('h'));
303 shouldPass('hello', contains('o')); 316 shouldPass('hello', contains('o'));
304 shouldPass('hello', contains('hell')); 317 shouldPass('hello', contains('hell'));
305 shouldPass('hello', contains('hello')); 318 shouldPass('hello', contains('hello'));
306 shouldFail('hello', contains(' '), 319 shouldFail('hello', contains(' '),
307 "Expected: contains ' ' But: was 'hello'."); 320 "Expected: contains ' ' But: was 'hello'. Actual: 'hello'");
308 }); 321 });
309 322
310 test('stringContainsInOrder', () { 323 test('stringContainsInOrder', () {
311 shouldPass('goodbye cruel world', stringContainsInOrder([''])); 324 shouldPass('goodbye cruel world', stringContainsInOrder(['']));
312 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); 325 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye']));
313 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); 326 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel']));
314 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); 327 shouldPass('goodbye cruel world', stringContainsInOrder(['world']));
315 shouldPass('goodbye cruel world', 328 shouldPass('goodbye cruel world',
316 stringContainsInOrder(['good', 'bye', 'world'])); 329 stringContainsInOrder(['good', 'bye', 'world']));
317 shouldPass('goodbye cruel world', 330 shouldPass('goodbye cruel world',
318 stringContainsInOrder(['goodbye', 'cruel'])); 331 stringContainsInOrder(['goodbye', 'cruel']));
319 shouldPass('goodbye cruel world', 332 shouldPass('goodbye cruel world',
320 stringContainsInOrder(['cruel', 'world'])); 333 stringContainsInOrder(['cruel', 'world']));
321 shouldPass('goodbye cruel world', 334 shouldPass('goodbye cruel world',
322 stringContainsInOrder(['goodbye', 'cruel', 'world'])); 335 stringContainsInOrder(['goodbye', 'cruel', 'world']));
323 shouldFail('goodbye cruel world', 336 shouldFail('goodbye cruel world',
324 stringContainsInOrder(['goo', 'cruel', 'bye']), 337 stringContainsInOrder(['goo', 'cruel', 'bye']),
325 "Expected: a string containing 'goo', 'cruel', 'bye' in order " 338 "Expected: a string containing 'goo', 'cruel', 'bye' in order "
326 "But: was 'goodbye cruel world'."); 339 "But: was 'goodbye cruel world'. Actual: 'goodbye cruel world'");
327 }); 340 });
328 341
329 test('matches', () { 342 test('matches', () {
330 shouldPass('c0d', matches('[a-z][0-9][a-z]')); 343 shouldPass('c0d', matches('[a-z][0-9][a-z]'));
331 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); 344 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]')));
332 shouldFail('cOd', matches('[a-z][0-9][a-z]'), 345 shouldFail('cOd', matches('[a-z][0-9][a-z]'),
333 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'."); 346 "Expected: match '[a-z][0-9][a-z]' But: was 'cOd'. Actual: 'cOd'");
334 }); 347 });
335 }); 348 });
336 349
337 group('Iterable Matchers', () { 350 group('Iterable Matchers', () {
338 351
339 test('isEmpty', () { 352 test('isEmpty', () {
340 shouldPass([], isEmpty); 353 shouldPass([], isEmpty);
341 shouldFail([1], isEmpty, "Expected: empty But: was [1]."); 354 shouldFail([1], isEmpty, "Expected: empty But: was [1]. Actual: [1]");
342 }); 355 });
343 356
344 test('contains', () { 357 test('contains', () {
345 var d = [1, 2]; 358 var d = [1, 2];
346 shouldPass(d, contains(1)); 359 shouldPass(d, contains(1));
347 shouldFail(d, contains(0), "Expected: contains <0> But: was [1, 2]."); 360 shouldFail(d, contains(0), "Expected: contains <0> "
361 "But: was [1, 2]. Actual: [1, 2]");
348 }); 362 });
349 363
350 test('isIn', () { 364 test('isIn', () {
351 var d = [1, 2]; 365 var d = [1, 2];
352 shouldPass(1, isIn(d)); 366 shouldPass(1, isIn(d));
353 shouldFail(0, isIn(d), "Expected: is in [1, 2] But: was <0>."); 367 shouldFail(0, isIn(d), "Expected: is in [1, 2] But: was <0>. Actual: <0>") ;
354 }); 368 });
355 369
356 test('everyElement', () { 370 test('everyElement', () {
357 var d = [1, 2]; 371 var d = [1, 2];
358 var e = [1, 1, 1]; 372 var e = [1, 1, 1];
359 shouldFail(d, everyElement(1), 373 shouldFail(d, everyElement(1),
360 "Expected: every element <1> But: position 1 was <2>. " 374 "Expected: every element <1> But: position 1 was <2>. "
361 "Actual: [1, 2]"); 375 "Actual: [1, 2]");
362 shouldPass(e, everyElement(1)); 376 shouldPass(e, everyElement(1));
363 }); 377 });
364 378
365 test('someElement', () { 379 test('someElement', () {
366 var d = [1, 2]; 380 var d = [1, 2];
367 var e = [1, 1, 1]; 381 var e = [1, 1, 1];
368 shouldPass(d, someElement(2)); 382 shouldPass(d, someElement(2));
369 shouldFail(e, someElement(2), 383 shouldFail(e, someElement(2),
370 "Expected: some element <2> But: was [1, 1, 1]."); 384 "Expected: some element <2> But: was [1, 1, 1]. Actual: [1, 1, 1]");
371 }); 385 });
372 386
373 test('orderedEquals', () { 387 test('orderedEquals', () {
374 shouldPass([null], orderedEquals([null])); 388 shouldPass([null], orderedEquals([null]));
375 var d = [1, 2]; 389 var d = [1, 2];
376 shouldPass(d, orderedEquals([1, 2])); 390 shouldPass(d, orderedEquals([1, 2]));
377 shouldFail(d, orderedEquals([2, 1]), 391 shouldFail(d, orderedEquals([2, 1]),
378 "Expected: equals [2, 1] ordered " 392 "Expected: equals [2, 1] ordered "
379 "But: expected <2> but was <1> mismatch at position 0. " 393 "But: expected <2> but was <1> mismatch at position 0. "
380 "Actual: [1, 2]"); 394 "Actual: [1, 2]");
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 }); 437 });
424 }); 438 });
425 439
426 group('Map Matchers', () { 440 group('Map Matchers', () {
427 441
428 test('isEmpty', () { 442 test('isEmpty', () {
429 var a = new Map(); 443 var a = new Map();
430 shouldPass({}, isEmpty); 444 shouldPass({}, isEmpty);
431 shouldPass(a, isEmpty); 445 shouldPass(a, isEmpty);
432 a['foo'] = 'bar'; 446 a['foo'] = 'bar';
433 shouldFail(a, isEmpty, "Expected: empty But: was {'foo': 'bar'}."); 447 shouldFail(a, isEmpty, "Expected: empty But: was {'foo': 'bar'}. "
448 "Actual: {'foo': 'bar'}");
434 }); 449 });
435 450
436 test('equals', () { 451 test('equals', () {
437 var a = new Map(); 452 var a = new Map();
438 a['foo'] = 'bar'; 453 a['foo'] = 'bar';
439 var b = new Map(); 454 var b = new Map();
440 b['foo'] = 'bar'; 455 b['foo'] = 'bar';
441 var c = new Map(); 456 var c = new Map();
442 c['bar'] = 'foo'; 457 c['bar'] = 'foo';
443 shouldPass(a, equals(b)); 458 shouldPass(a, equals(b));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 "But: different map lengths; missing map key 'foo'. " 495 "But: different map lengths; missing map key 'foo'. "
481 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}"); 496 "Actual: {'bar': 'foo', 'barrista': 'caffeine'}");
482 }); 497 });
483 498
484 test('contains', () { 499 test('contains', () {
485 var a = new Map(); 500 var a = new Map();
486 a['foo'] = 'bar'; 501 a['foo'] = 'bar';
487 var b = new Map(); 502 var b = new Map();
488 shouldPass(a, contains('foo')); 503 shouldPass(a, contains('foo'));
489 shouldFail(b, contains('foo'), 504 shouldFail(b, contains('foo'),
490 "Expected: contains 'foo' But: was {}."); 505 "Expected: contains 'foo' But: was {}. Actual: {}");
491 shouldFail(10, contains('foo'), 506 shouldFail(10, contains('foo'),
492 "Expected: contains 'foo' But: was <10>."); 507 "Expected: contains 'foo' But: was <10>. Actual: <10>");
493 }); 508 });
494 509
495 test('containsValue', () { 510 test('containsValue', () {
496 var a = new Map(); 511 var a = new Map();
497 a['foo'] = 'bar'; 512 a['foo'] = 'bar';
498 shouldPass(a, containsValue('bar')); 513 shouldPass(a, containsValue('bar'));
499 shouldFail(a, containsValue('ba'), 514 shouldFail(a, containsValue('ba'),
500 "Expected: contains value 'ba' But: was {'foo': 'bar'}."); 515 "Expected: contains value 'ba' But: was {'foo': 'bar'}. "
516 "Actual: {'foo': 'bar'}");
501 }); 517 });
502 518
503 test('containsPair', () { 519 test('containsPair', () {
504 var a = new Map(); 520 var a = new Map();
505 a['foo'] = 'bar'; 521 a['foo'] = 'bar';
506 shouldPass(a, containsPair('foo', 'bar')); 522 shouldPass(a, containsPair('foo', 'bar'));
507 shouldFail(a, containsPair('foo', 'ba'), 523 shouldFail(a, containsPair('foo', 'ba'),
508 "Expected: contains pair 'foo' => 'ba' " 524 "Expected: contains pair 'foo' => 'ba' "
509 "But: contains key 'foo' but with value was 'bar'. " 525 "But: Strings are not equal. Both strings start the same, "
526 "but the given value also has the following trailing characters: r. "
510 "Actual: {'foo': 'bar'}"); 527 "Actual: {'foo': 'bar'}");
511 shouldFail(a, containsPair('fo', 'bar'), 528 shouldFail(a, containsPair('fo', 'bar'),
512 "Expected: contains pair 'fo' => 'bar' " 529 "Expected: contains pair 'fo' => 'bar' "
513 "But: doesn't contain key 'fo'. " 530 "But: doesn't contain key 'fo'. "
514 "Actual: {'foo': 'bar'}"); 531 "Actual: {'foo': 'bar'}");
515 }); 532 });
516 533
517 test('hasLength', () { 534 test('hasLength', () {
518 var a = new Map(); 535 var a = new Map();
519 a['foo'] = 'bar'; 536 a['foo'] = 'bar';
520 var b = new Map(); 537 var b = new Map();
521 shouldPass(a, hasLength(1)); 538 shouldPass(a, hasLength(1));
522 shouldFail(b, hasLength(1), 539 shouldFail(b, hasLength(1),
523 "Expected: an object with length of <1> " 540 "Expected: an object with length of <1> "
524 "But: had length of <0>. " 541 "But: had length of <0>. "
525 "Actual: {}"); 542 "Actual: {}");
526 }); 543 });
527 }); 544 });
528 545
529 group('Operator Matchers', () { 546 group('Operator Matchers', () {
530 547
531 test('anyOf', () { 548 test('anyOf', () {
532 shouldFail(0, anyOf([equals(1), equals(2)]), 549 shouldFail(0, anyOf([equals(1), equals(2)]),
533 "Expected: (<1> or <2>) But: was <0>."); 550 "Expected: (<1> or <2>) But: was <0>. Actual: <0>");
534 shouldPass(1, anyOf([equals(1), equals(2)])); 551 shouldPass(1, anyOf([equals(1), equals(2)]));
535 }); 552 });
536 553
537 test('allOf', () { 554 test('allOf', () {
538 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); 555 shouldPass(1, allOf([lessThan(10), greaterThan(0)]));
539 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), 556 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]),
540 "Expected: (a value less than <10> and a value greater than <0>) " 557 "Expected: (a value less than <10> and a value greater than <0>) "
541 "But: was <-1> (wasn't a value greater than <0>)."); 558 "But: was <-1> (wasn't a value greater than <0>). Actual: <-1>");
542 }); 559 });
543 }); 560 });
544 561
545 group('Future Matchers', () { 562 group('Future Matchers', () {
546 563
547 test('completes - unexpected error', () { 564 test('completes - unexpected error', () {
548 var completer = new Completer(); 565 var completer = new Completer();
549 completer.completeError('X'); 566 completer.completeError('X');
550 shouldFail(completer.future, completes, 567 shouldFail(completer.future, completes,
551 contains('Expected future to complete successfully, ' 568 contains('Expected future to complete successfully, '
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
591 test('throwsA - correct error', () { 608 test('throwsA - correct error', () {
592 var completer = new Completer(); 609 var completer = new Completer();
593 completer.completeError('X'); 610 completer.completeError('X');
594 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); 611 shouldPass(completer.future, throwsA(equals('X')), isAsync: true);
595 }); 612 });
596 613
597 test('throwsA - wrong error', () { 614 test('throwsA - wrong error', () {
598 var completer = new Completer(); 615 var completer = new Completer();
599 completer.completeError('X'); 616 completer.completeError('X');
600 shouldFail(completer.future, throwsA(equals('Y')), 617 shouldFail(completer.future, throwsA(equals('Y')),
601 "Expected: 'Y' But: was 'X'.", 618 "Expected: 'Y' But: Strings are not equal. "
619 "Expected: Y Actual: X ^ Differ at position 0. Actual: 'X'",
602 isAsync: true); 620 isAsync: true);
603 }); 621 });
604 }); 622 });
605 623
606 group('Predicate Matchers', () { 624 group('Predicate Matchers', () {
607 test('isInstanceOf', () { 625 test('isInstanceOf', () {
608 shouldFail(0, predicate((x) => x is String, "an instance of String"), 626 shouldFail(0, predicate((x) => x is String, "an instance of String"),
609 "Expected: an instance of String But: was <0>."); 627 "Expected: an instance of String But: was <0>. Actual: <0>");
610 shouldPass('cow', predicate((x) => x is String, "an instance of String")); 628 shouldPass('cow', predicate((x) => x is String, "an instance of String"));
611 }); 629 });
612 }); 630 });
613 } 631 }
614 632
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698