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

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

Issue 199793010: pkg/matcher: test cleanup (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fixed skipped test Created 6 years, 9 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 library matcher.test;
6
5 import 'dart:async'; 7 import 'dart:async';
6 import 'dart:collection'; 8 import 'dart:collection';
7 9
8 import 'package:matcher/matcher.dart'; 10 import 'package:matcher/matcher.dart';
9 import 'package:unittest/unittest.dart' as ut; 11 import 'package:unittest/unittest.dart' show test, group;
10 12
11 import 'test_utils.dart'; 13 import 'test_utils.dart';
12 14
13 void main() { 15 void main() {
14 16
15 initUtils(); 17 initUtils();
16 18
17 // Core matchers 19 // Core matchers
18 20
19 ut.group('Core matchers', () { 21 group('Core matchers', () {
20 22
21 ut.test('isTrue', () { 23 test('isTrue', () {
22 shouldPass(true, isTrue); 24 shouldPass(true, isTrue);
23 shouldFail(false, isTrue, "Expected: true Actual: <false>"); 25 shouldFail(false, isTrue, "Expected: true Actual: <false>");
24 }); 26 });
25 27
26 ut.test('isFalse', () { 28 test('isFalse', () {
27 shouldPass(false, isFalse); 29 shouldPass(false, isFalse);
28 shouldFail(10, isFalse, "Expected: false Actual: <10>"); 30 shouldFail(10, isFalse, "Expected: false Actual: <10>");
29 shouldFail(true, isFalse, "Expected: false Actual: <true>"); 31 shouldFail(true, isFalse, "Expected: false Actual: <true>");
30 }); 32 });
31 33
32 ut.test('isNull', () { 34 test('isNull', () {
33 shouldPass(null, isNull); 35 shouldPass(null, isNull);
34 shouldFail(false, isNull, "Expected: null Actual: <false>"); 36 shouldFail(false, isNull, "Expected: null Actual: <false>");
35 }); 37 });
36 38
37 ut.test('isNotNull', () { 39 test('isNotNull', () {
38 shouldPass(false, isNotNull); 40 shouldPass(false, isNotNull);
39 shouldFail(null, isNotNull, "Expected: not null Actual: <null>"); 41 shouldFail(null, isNotNull, "Expected: not null Actual: <null>");
40 }); 42 });
41 43
42 ut.test('same', () { 44 test('same', () {
43 var a = new Map(); 45 var a = new Map();
44 var b = new Map(); 46 var b = new Map();
45 shouldPass(a, same(a)); 47 shouldPass(a, same(a));
46 shouldFail(b, same(a), "Expected: same instance as {} Actual: {}"); 48 shouldFail(b, same(a), "Expected: same instance as {} Actual: {}");
47 }); 49 });
48 50
49 ut.test('equals', () { 51 test('equals', () {
50 var a = new Map(); 52 var a = new Map();
51 var b = new Map(); 53 var b = new Map();
52 shouldPass(a, equals(a)); 54 shouldPass(a, equals(a));
53 shouldPass(a, equals(b)); 55 shouldPass(a, equals(b));
54 }); 56 });
55 57
56 ut.test('anything', () { 58 test('anything', () {
57 var a = new Map(); 59 var a = new Map();
58 shouldPass(0, anything); 60 shouldPass(0, anything);
59 shouldPass(null, anything); 61 shouldPass(null, anything);
60 shouldPass(a, anything); 62 shouldPass(a, anything);
61 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}"); 63 shouldFail(a, isNot(anything), "Expected: not anything Actual: {}");
62 }); 64 });
63 65
64 ut.test('throws', () { 66 test('throws', () {
65 shouldFail(doesNotThrow, throws, 67 shouldFail(doesNotThrow, throws,
66 matches( 68 matches(
67 r"Expected: throws" 69 r"Expected: throws"
68 r" Actual: <Closure(: \(\) => dynamic " 70 r" Actual: <Closure(: \(\) => dynamic "
69 r"from Function 'doesNotThrow': static\.)?>" 71 r"from Function 'doesNotThrow': static\.)?>"
70 r" Which: did not throw")); 72 r" Which: did not throw"));
71 shouldPass(doesThrow, throws); 73 shouldPass(doesThrow, throws);
72 shouldFail(true, throws, 74 shouldFail(true, throws,
73 "Expected: throws" 75 "Expected: throws"
74 " Actual: <true>" 76 " Actual: <true>"
75 " Which: is not a Function or Future"); 77 " Which: is not a Function or Future");
76 }); 78 });
77 79
78 ut.test('throwsA', () { 80 test('throwsA', () {
79 shouldPass(doesThrow, throwsA(equals('X'))); 81 shouldPass(doesThrow, throwsA(equals('X')));
80 shouldFail(doesThrow, throwsA(equals('Y')), 82 shouldFail(doesThrow, throwsA(equals('Y')),
81 matches( 83 matches(
82 r"Expected: throws 'Y'" 84 r"Expected: throws 'Y'"
83 r" Actual: <Closure(: \(\) => dynamic " 85 r" Actual: <Closure(: \(\) => dynamic "
84 r"from Function 'doesThrow': static\.)?>" 86 r"from Function 'doesThrow': static\.)?>"
85 r" Which: threw 'X'")); 87 r" Which: threw 'X'"));
86 }); 88 });
87 89
88 ut.test('returnsNormally', () { 90 test('returnsNormally', () {
89 shouldPass(doesNotThrow, returnsNormally); 91 shouldPass(doesNotThrow, returnsNormally);
90 shouldFail(doesThrow, returnsNormally, 92 shouldFail(doesThrow, returnsNormally,
91 matches( 93 matches(
92 r"Expected: return normally" 94 r"Expected: return normally"
93 r" Actual: <Closure(: \(\) => dynamic " 95 r" Actual: <Closure(: \(\) => dynamic "
94 r"from Function 'doesThrow': static\.)?>" 96 r"from Function 'doesThrow': static\.)?>"
95 r" Which: threw 'X'")); 97 r" Which: threw 'X'"));
96 }); 98 });
97 99
98 100
99 ut.test('hasLength', () { 101 test('hasLength', () {
100 var a = new Map(); 102 var a = new Map();
101 var b = new List(); 103 var b = new List();
102 shouldPass(a, hasLength(0)); 104 shouldPass(a, hasLength(0));
103 shouldPass(b, hasLength(0)); 105 shouldPass(b, hasLength(0));
104 shouldPass('a', hasLength(1)); 106 shouldPass('a', hasLength(1));
105 shouldFail(0, hasLength(0), new PrefixMatcher( 107 shouldFail(0, hasLength(0), new PrefixMatcher(
106 "Expected: an object with length of <0> " 108 "Expected: an object with length of <0> "
107 "Actual: <0> " 109 "Actual: <0> "
108 "Which: has no length property")); 110 "Which: has no length property"));
109 111
110 b.add(0); 112 b.add(0);
111 shouldPass(b, hasLength(1)); 113 shouldPass(b, hasLength(1));
112 shouldFail(b, hasLength(2), 114 shouldFail(b, hasLength(2),
113 "Expected: an object with length of <2> " 115 "Expected: an object with length of <2> "
114 "Actual: [0] " 116 "Actual: [0] "
115 "Which: has length of <1>"); 117 "Which: has length of <1>");
116 118
117 b.add(0); 119 b.add(0);
118 shouldFail(b, hasLength(1), 120 shouldFail(b, hasLength(1),
119 "Expected: an object with length of <1> " 121 "Expected: an object with length of <1> "
120 "Actual: [0, 0] " 122 "Actual: [0, 0] "
121 "Which: has length of <2>"); 123 "Which: has length of <2>");
122 shouldPass(b, hasLength(2)); 124 shouldPass(b, hasLength(2));
123 }); 125 });
124 126
125 ut.test('scalar type mismatch', () { 127 test('scalar type mismatch', () {
126 shouldFail('error', equals(5.1), 128 shouldFail('error', equals(5.1),
127 "Expected: <5.1> " 129 "Expected: <5.1> "
128 "Actual: 'error'"); 130 "Actual: 'error'");
129 }); 131 });
130 132
131 ut.test('nested type mismatch', () { 133 test('nested type mismatch', () {
132 shouldFail(['error'], equals([5.1]), 134 shouldFail(['error'], equals([5.1]),
133 "Expected: [5.1] " 135 "Expected: [5.1] "
134 "Actual: ['error'] " 136 "Actual: ['error'] "
135 "Which: was 'error' instead of <5.1> at location [0]"); 137 "Which: was 'error' instead of <5.1> at location [0]");
136 }); 138 });
137 139
138 ut.test('doubly-nested type mismatch', () { 140 test('doubly-nested type mismatch', () {
139 shouldFail([['error']], equals([[5.1]]), 141 shouldFail([['error']], equals([[5.1]]),
140 "Expected: [[5.1]] " 142 "Expected: [[5.1]] "
141 "Actual: [['error']] " 143 "Actual: [['error']] "
142 "Which: was 'error' instead of <5.1> at location [0][0]"); 144 "Which: was 'error' instead of <5.1> at location [0][0]");
143 }); 145 });
144 146
145 ut.test('doubly nested inequality', () { 147 test('doubly nested inequality', () {
146 var actual1 = [['foo', 'bar'], ['foo'], 3, []]; 148 var actual1 = [['foo', 'bar'], ['foo'], 3, []];
147 var expected1 = [['foo', 'bar'], ['foo'], 4, []]; 149 var expected1 = [['foo', 'bar'], ['foo'], 4, []];
148 var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " 150 var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
149 "Actual: [['foo', 'bar'], ['foo'], 3, []] " 151 "Actual: [['foo', 'bar'], ['foo'], 3, []] "
150 "Which: was <3> instead of <4> at location [2]"; 152 "Which: was <3> instead of <4> at location [2]";
151 153
152 var actual2 = [['foo', 'barry'], ['foo'], 4, []]; 154 var actual2 = [['foo', 'barry'], ['foo'], 4, []];
153 var expected2 = [['foo', 'bar'], ['foo'], 4, []]; 155 var expected2 = [['foo', 'bar'], ['foo'], 4, []];
154 var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] " 156 var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
155 "Actual: [['foo', 'barry'], ['foo'], 4, []] " 157 "Actual: [['foo', 'barry'], ['foo'], 4, []] "
156 "Which: was 'barry' instead of 'bar' at location [0][1]"; 158 "Which: was 'barry' instead of 'bar' at location [0][1]";
157 159
158 var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo':'bar'}]; 160 var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo':'bar'}];
159 var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo':'barry'}]; 161 var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo':'barry'}];
160 var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] " 162 var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] "
161 "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] " 163 "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] "
162 "Which: was 'bar' instead of 'barry' at location [3]['foo']"; 164 "Which: was 'bar' instead of 'barry' at location [3]['foo']";
163 165
164 shouldFail(actual1, equals(expected1), reason1); 166 shouldFail(actual1, equals(expected1), reason1);
165 shouldFail(actual2, equals(expected2), reason2); 167 shouldFail(actual2, equals(expected2), reason2);
166 shouldFail(actual3, equals(expected3), reason3); 168 shouldFail(actual3, equals(expected3), reason3);
167 }); 169 });
168 }); 170 });
169 171
170 ut.group('Numeric Matchers', () { 172 group('Numeric Matchers', () {
171 173
172 ut.test('greaterThan', () { 174 test('greaterThan', () {
173 shouldPass(10, greaterThan(9)); 175 shouldPass(10, greaterThan(9));
174 shouldFail(9, greaterThan(10), 176 shouldFail(9, greaterThan(10),
175 "Expected: a value greater than <10> " 177 "Expected: a value greater than <10> "
176 "Actual: <9> " 178 "Actual: <9> "
177 "Which: is not a value greater than <10>"); 179 "Which: is not a value greater than <10>");
178 }); 180 });
179 181
180 ut.test('greaterThanOrEqualTo', () { 182 test('greaterThanOrEqualTo', () {
181 shouldPass(10, greaterThanOrEqualTo(10)); 183 shouldPass(10, greaterThanOrEqualTo(10));
182 shouldFail(9, greaterThanOrEqualTo(10), 184 shouldFail(9, greaterThanOrEqualTo(10),
183 "Expected: a value greater than or equal to <10> " 185 "Expected: a value greater than or equal to <10> "
184 "Actual: <9> " 186 "Actual: <9> "
185 "Which: is not a value greater than or equal to <10>"); 187 "Which: is not a value greater than or equal to <10>");
186 }); 188 });
187 189
188 ut.test('lessThan', () { 190 test('lessThan', () {
189 shouldFail(10, lessThan(9), 191 shouldFail(10, lessThan(9),
190 "Expected: a value less than <9> " 192 "Expected: a value less than <9> "
191 "Actual: <10> " 193 "Actual: <10> "
192 "Which: is not a value less than <9>"); 194 "Which: is not a value less than <9>");
193 shouldPass(9, lessThan(10)); 195 shouldPass(9, lessThan(10));
194 }); 196 });
195 197
196 ut.test('lessThanOrEqualTo', () { 198 test('lessThanOrEqualTo', () {
197 shouldPass(10, lessThanOrEqualTo(10)); 199 shouldPass(10, lessThanOrEqualTo(10));
198 shouldFail(11, lessThanOrEqualTo(10), 200 shouldFail(11, lessThanOrEqualTo(10),
199 "Expected: a value less than or equal to <10> " 201 "Expected: a value less than or equal to <10> "
200 "Actual: <11> " 202 "Actual: <11> "
201 "Which: is not a value less than or equal to <10>"); 203 "Which: is not a value less than or equal to <10>");
202 }); 204 });
203 205
204 ut.test('isZero', () { 206 test('isZero', () {
205 shouldPass(0, isZero); 207 shouldPass(0, isZero);
206 shouldFail(1, isZero, 208 shouldFail(1, isZero,
207 "Expected: a value equal to <0> " 209 "Expected: a value equal to <0> "
208 "Actual: <1> " 210 "Actual: <1> "
209 "Which: is not a value equal to <0>"); 211 "Which: is not a value equal to <0>");
210 }); 212 });
211 213
212 ut.test('isNonZero', () { 214 test('isNonZero', () {
213 shouldFail(0, isNonZero, 215 shouldFail(0, isNonZero,
214 "Expected: a value not equal to <0> " 216 "Expected: a value not equal to <0> "
215 "Actual: <0> " 217 "Actual: <0> "
216 "Which: is not a value not equal to <0>"); 218 "Which: is not a value not equal to <0>");
217 shouldPass(1, isNonZero); 219 shouldPass(1, isNonZero);
218 }); 220 });
219 221
220 ut.test('isPositive', () { 222 test('isPositive', () {
221 shouldFail(-1, isPositive, 223 shouldFail(-1, isPositive,
222 "Expected: a positive value " 224 "Expected: a positive value "
223 "Actual: <-1> " 225 "Actual: <-1> "
224 "Which: is not a positive value"); 226 "Which: is not a positive value");
225 shouldFail(0, isPositive, 227 shouldFail(0, isPositive,
226 "Expected: a positive value " 228 "Expected: a positive value "
227 "Actual: <0> " 229 "Actual: <0> "
228 "Which: is not a positive value"); 230 "Which: is not a positive value");
229 shouldPass(1, isPositive); 231 shouldPass(1, isPositive);
230 }); 232 });
231 233
232 ut.test('isNegative', () { 234 test('isNegative', () {
233 shouldPass(-1, isNegative); 235 shouldPass(-1, isNegative);
234 shouldFail(0, isNegative, 236 shouldFail(0, isNegative,
235 "Expected: a negative value " 237 "Expected: a negative value "
236 "Actual: <0> " 238 "Actual: <0> "
237 "Which: is not a negative value"); 239 "Which: is not a negative value");
238 }); 240 });
239 241
240 ut.test('isNonPositive', () { 242 test('isNonPositive', () {
241 shouldPass(-1, isNonPositive); 243 shouldPass(-1, isNonPositive);
242 shouldPass(0, isNonPositive); 244 shouldPass(0, isNonPositive);
243 shouldFail(1, isNonPositive, 245 shouldFail(1, isNonPositive,
244 "Expected: a non-positive value " 246 "Expected: a non-positive value "
245 "Actual: <1> " 247 "Actual: <1> "
246 "Which: is not a non-positive value"); 248 "Which: is not a non-positive value");
247 }); 249 });
248 250
249 ut.test('isNonNegative', () { 251 test('isNonNegative', () {
250 shouldPass(1, isNonNegative); 252 shouldPass(1, isNonNegative);
251 shouldPass(0, isNonNegative); 253 shouldPass(0, isNonNegative);
252 shouldFail(-1, isNonNegative, 254 shouldFail(-1, isNonNegative,
253 "Expected: a non-negative value " 255 "Expected: a non-negative value "
254 "Actual: <-1> " 256 "Actual: <-1> "
255 "Which: is not a non-negative value"); 257 "Which: is not a non-negative value");
256 }); 258 });
257 259
258 ut.test('closeTo', () { 260 test('closeTo', () {
259 shouldPass(0, closeTo(0, 1)); 261 shouldPass(0, closeTo(0, 1));
260 shouldPass(-1, closeTo(0, 1)); 262 shouldPass(-1, closeTo(0, 1));
261 shouldPass(1, closeTo(0, 1)); 263 shouldPass(1, closeTo(0, 1));
262 shouldFail(1.001, closeTo(0, 1), 264 shouldFail(1.001, closeTo(0, 1),
263 "Expected: a numeric value within <1> of <0> " 265 "Expected: a numeric value within <1> of <0> "
264 "Actual: <1.001> " 266 "Actual: <1.001> "
265 "Which: differs by <1.001>"); 267 "Which: differs by <1.001>");
266 shouldFail(-1.001, closeTo(0, 1), 268 shouldFail(-1.001, closeTo(0, 1),
267 "Expected: a numeric value within <1> of <0> " 269 "Expected: a numeric value within <1> of <0> "
268 "Actual: <-1.001> " 270 "Actual: <-1.001> "
269 "Which: differs by <1.001>"); 271 "Which: differs by <1.001>");
270 }); 272 });
271 273
272 ut.test('inInclusiveRange', () { 274 test('inInclusiveRange', () {
273 shouldFail(-1, inInclusiveRange(0,2), 275 shouldFail(-1, inInclusiveRange(0,2),
274 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " 276 "Expected: be in range from 0 (inclusive) to 2 (inclusive) "
275 "Actual: <-1>"); 277 "Actual: <-1>");
276 shouldPass(0, inInclusiveRange(0,2)); 278 shouldPass(0, inInclusiveRange(0,2));
277 shouldPass(1, inInclusiveRange(0,2)); 279 shouldPass(1, inInclusiveRange(0,2));
278 shouldPass(2, inInclusiveRange(0,2)); 280 shouldPass(2, inInclusiveRange(0,2));
279 shouldFail(3, inInclusiveRange(0,2), 281 shouldFail(3, inInclusiveRange(0,2),
280 "Expected: be in range from 0 (inclusive) to 2 (inclusive) " 282 "Expected: be in range from 0 (inclusive) to 2 (inclusive) "
281 "Actual: <3>"); 283 "Actual: <3>");
282 }); 284 });
283 285
284 ut.test('inExclusiveRange', () { 286 test('inExclusiveRange', () {
285 shouldFail(0, inExclusiveRange(0,2), 287 shouldFail(0, inExclusiveRange(0,2),
286 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " 288 "Expected: be in range from 0 (exclusive) to 2 (exclusive) "
287 "Actual: <0>"); 289 "Actual: <0>");
288 shouldPass(1, inExclusiveRange(0,2)); 290 shouldPass(1, inExclusiveRange(0,2));
289 shouldFail(2, inExclusiveRange(0,2), 291 shouldFail(2, inExclusiveRange(0,2),
290 "Expected: be in range from 0 (exclusive) to 2 (exclusive) " 292 "Expected: be in range from 0 (exclusive) to 2 (exclusive) "
291 "Actual: <2>"); 293 "Actual: <2>");
292 }); 294 });
293 295
294 ut.test('inOpenClosedRange', () { 296 test('inOpenClosedRange', () {
295 shouldFail(0, inOpenClosedRange(0,2), 297 shouldFail(0, inOpenClosedRange(0,2),
296 "Expected: be in range from 0 (exclusive) to 2 (inclusive) " 298 "Expected: be in range from 0 (exclusive) to 2 (inclusive) "
297 "Actual: <0>"); 299 "Actual: <0>");
298 shouldPass(1, inOpenClosedRange(0,2)); 300 shouldPass(1, inOpenClosedRange(0,2));
299 shouldPass(2, inOpenClosedRange(0,2)); 301 shouldPass(2, inOpenClosedRange(0,2));
300 }); 302 });
301 303
302 ut.test('inClosedOpenRange', () { 304 test('inClosedOpenRange', () {
303 shouldPass(0, inClosedOpenRange(0,2)); 305 shouldPass(0, inClosedOpenRange(0,2));
304 shouldPass(1, inClosedOpenRange(0,2)); 306 shouldPass(1, inClosedOpenRange(0,2));
305 shouldFail(2, inClosedOpenRange(0,2), 307 shouldFail(2, inClosedOpenRange(0,2),
306 "Expected: be in range from 0 (inclusive) to 2 (exclusive) " 308 "Expected: be in range from 0 (inclusive) to 2 (exclusive) "
307 "Actual: <2>"); 309 "Actual: <2>");
308 }); 310 });
309 }); 311 });
310 312
311 ut.group('String Matchers', () { 313 group('String Matchers', () {
312 314
313 ut.test('isEmpty', () { 315 test('isEmpty', () {
314 shouldPass('', isEmpty); 316 shouldPass('', isEmpty);
315 shouldFail(null, isEmpty, 317 shouldFail(null, isEmpty,
316 "Expected: empty Actual: <null>"); 318 "Expected: empty Actual: <null>");
317 shouldFail(0, isEmpty, 319 shouldFail(0, isEmpty,
318 "Expected: empty Actual: <0>"); 320 "Expected: empty Actual: <0>");
319 shouldFail('a', isEmpty, "Expected: empty Actual: 'a'"); 321 shouldFail('a', isEmpty, "Expected: empty Actual: 'a'");
320 }); 322 });
321 323
322 ut.test('equalsIgnoringCase', () { 324 test('equalsIgnoringCase', () {
323 shouldPass('hello', equalsIgnoringCase('HELLO')); 325 shouldPass('hello', equalsIgnoringCase('HELLO'));
324 shouldFail('hi', equalsIgnoringCase('HELLO'), 326 shouldFail('hi', equalsIgnoringCase('HELLO'),
325 "Expected: 'HELLO' ignoring case Actual: 'hi'"); 327 "Expected: 'HELLO' ignoring case Actual: 'hi'");
326 }); 328 });
327 329
328 ut.test('equalsIgnoringWhitespace', () { 330 test('equalsIgnoringWhitespace', () {
329 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world')); 331 shouldPass(' hello world ', equalsIgnoringWhitespace('hello world'));
330 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'), 332 shouldFail(' helloworld ', equalsIgnoringWhitespace('hello world'),
331 "Expected: 'hello world' ignoring whitespace " 333 "Expected: 'hello world' ignoring whitespace "
332 "Actual: ' helloworld ' " 334 "Actual: ' helloworld ' "
333 "Which: is 'helloworld' with whitespace compressed"); 335 "Which: is 'helloworld' with whitespace compressed");
334 }); 336 });
335 337
336 ut.test('startsWith', () { 338 test('startsWith', () {
337 shouldPass('hello', startsWith('')); 339 shouldPass('hello', startsWith(''));
338 shouldPass('hello', startsWith('hell')); 340 shouldPass('hello', startsWith('hell'));
339 shouldPass('hello', startsWith('hello')); 341 shouldPass('hello', startsWith('hello'));
340 shouldFail('hello', startsWith('hello '), 342 shouldFail('hello', startsWith('hello '),
341 "Expected: a string starting with 'hello ' " 343 "Expected: a string starting with 'hello ' "
342 "Actual: 'hello'"); 344 "Actual: 'hello'");
343 }); 345 });
344 346
345 ut.test('endsWith', () { 347 test('endsWith', () {
346 shouldPass('hello', endsWith('')); 348 shouldPass('hello', endsWith(''));
347 shouldPass('hello', endsWith('lo')); 349 shouldPass('hello', endsWith('lo'));
348 shouldPass('hello', endsWith('hello')); 350 shouldPass('hello', endsWith('hello'));
349 shouldFail('hello', endsWith(' hello'), 351 shouldFail('hello', endsWith(' hello'),
350 "Expected: a string ending with ' hello' " 352 "Expected: a string ending with ' hello' "
351 "Actual: 'hello'"); 353 "Actual: 'hello'");
352 }); 354 });
353 355
354 ut.test('contains', () { 356 test('contains', () {
355 shouldPass('hello', contains('')); 357 shouldPass('hello', contains(''));
356 shouldPass('hello', contains('h')); 358 shouldPass('hello', contains('h'));
357 shouldPass('hello', contains('o')); 359 shouldPass('hello', contains('o'));
358 shouldPass('hello', contains('hell')); 360 shouldPass('hello', contains('hell'));
359 shouldPass('hello', contains('hello')); 361 shouldPass('hello', contains('hello'));
360 shouldFail('hello', contains(' '), 362 shouldFail('hello', contains(' '),
361 "Expected: contains ' ' Actual: 'hello'"); 363 "Expected: contains ' ' Actual: 'hello'");
362 }); 364 });
363 365
364 ut.test('stringContainsInOrder', () { 366 test('stringContainsInOrder', () {
365 shouldPass('goodbye cruel world', stringContainsInOrder([''])); 367 shouldPass('goodbye cruel world', stringContainsInOrder(['']));
366 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye'])); 368 shouldPass('goodbye cruel world', stringContainsInOrder(['goodbye']));
367 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel'])); 369 shouldPass('goodbye cruel world', stringContainsInOrder(['cruel']));
368 shouldPass('goodbye cruel world', stringContainsInOrder(['world'])); 370 shouldPass('goodbye cruel world', stringContainsInOrder(['world']));
369 shouldPass('goodbye cruel world', 371 shouldPass('goodbye cruel world',
370 stringContainsInOrder(['good', 'bye', 'world'])); 372 stringContainsInOrder(['good', 'bye', 'world']));
371 shouldPass('goodbye cruel world', 373 shouldPass('goodbye cruel world',
372 stringContainsInOrder(['goodbye', 'cruel'])); 374 stringContainsInOrder(['goodbye', 'cruel']));
373 shouldPass('goodbye cruel world', 375 shouldPass('goodbye cruel world',
374 stringContainsInOrder(['cruel', 'world'])); 376 stringContainsInOrder(['cruel', 'world']));
375 shouldPass('goodbye cruel world', 377 shouldPass('goodbye cruel world',
376 stringContainsInOrder(['goodbye', 'cruel', 'world'])); 378 stringContainsInOrder(['goodbye', 'cruel', 'world']));
377 shouldFail('goodbye cruel world', 379 shouldFail('goodbye cruel world',
378 stringContainsInOrder(['goo', 'cruel', 'bye']), 380 stringContainsInOrder(['goo', 'cruel', 'bye']),
379 "Expected: a string containing 'goo', 'cruel', 'bye' in order " 381 "Expected: a string containing 'goo', 'cruel', 'bye' in order "
380 "Actual: 'goodbye cruel world'"); 382 "Actual: 'goodbye cruel world'");
381 }); 383 });
382 384
383 ut.test('matches', () { 385 test('matches', () {
384 shouldPass('c0d', matches('[a-z][0-9][a-z]')); 386 shouldPass('c0d', matches('[a-z][0-9][a-z]'));
385 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]'))); 387 shouldPass('c0d', matches(new RegExp('[a-z][0-9][a-z]')));
386 shouldFail('cOd', matches('[a-z][0-9][a-z]'), 388 shouldFail('cOd', matches('[a-z][0-9][a-z]'),
387 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'"); 389 "Expected: match '[a-z][0-9][a-z]' Actual: 'cOd'");
388 }); 390 });
389 }); 391 });
390 392
391 ut.group('Iterable Matchers', () { 393 group('Iterable Matchers', () {
392 394
393 ut.test('isEmpty', () { 395 test('isEmpty', () {
394 shouldPass([], isEmpty); 396 shouldPass([], isEmpty);
395 shouldFail([1], isEmpty, "Expected: empty Actual: [1]"); 397 shouldFail([1], isEmpty, "Expected: empty Actual: [1]");
396 }); 398 });
397 399
398 ut.test('contains', () { 400 test('contains', () {
399 var d = [1, 2]; 401 var d = [1, 2];
400 shouldPass(d, contains(1)); 402 shouldPass(d, contains(1));
401 shouldFail(d, contains(0), "Expected: contains <0> " 403 shouldFail(d, contains(0), "Expected: contains <0> "
402 "Actual: [1, 2]"); 404 "Actual: [1, 2]");
403 }); 405 });
404 406
405 ut.test('equals with matcher element', () { 407 test('equals with matcher element', () {
406 var d = ['foo', 'bar']; 408 var d = ['foo', 'bar'];
407 shouldPass(d, equals(['foo', startsWith('ba')])); 409 shouldPass(d, equals(['foo', startsWith('ba')]));
408 shouldFail(d, equals(['foo', endsWith('ba')]), 410 shouldFail(d, equals(['foo', endsWith('ba')]),
409 "Expected: ['foo', <a string ending with 'ba'>] " 411 "Expected: ['foo', <a string ending with 'ba'>] "
410 "Actual: ['foo', 'bar'] " 412 "Actual: ['foo', 'bar'] "
411 "Which: does not match a string ending with 'ba' at location [1]"); 413 "Which: does not match a string ending with 'ba' at location [1]");
412 }); 414 });
413 415
414 ut.test('isIn', () { 416 test('isIn', () {
415 var d = [1, 2]; 417 var d = [1, 2];
416 shouldPass(1, isIn(d)); 418 shouldPass(1, isIn(d));
417 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>"); 419 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>");
418 }); 420 });
419 421
420 ut.test('everyElement', () { 422 test('everyElement', () {
421 var d = [1, 2]; 423 var d = [1, 2];
422 var e = [1, 1, 1]; 424 var e = [1, 1, 1];
423 shouldFail(d, everyElement(1), 425 shouldFail(d, everyElement(1),
424 "Expected: every element(<1>) " 426 "Expected: every element(<1>) "
425 "Actual: [1, 2] " 427 "Actual: [1, 2] "
426 "Which: has value <2> which doesn't match <1> at index 1"); 428 "Which: has value <2> which doesn't match <1> at index 1");
427 shouldPass(e, everyElement(1)); 429 shouldPass(e, everyElement(1));
428 }); 430 });
429 431
430 ut.test('nested everyElement', () { 432 test('nested everyElement', () {
431 var d = [['foo', 'bar'], ['foo'], []]; 433 var d = [['foo', 'bar'], ['foo'], []];
432 var e = [['foo', 'bar'], ['foo'], 3, []]; 434 var e = [['foo', 'bar'], ['foo'], 3, []];
433 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo')))); 435 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo'))));
434 shouldFail(d, everyElement(everyElement(equals('foo'))), 436 shouldFail(d, everyElement(everyElement(equals('foo'))),
435 "Expected: every element(every element('foo')) " 437 "Expected: every element(every element('foo')) "
436 "Actual: [['foo', 'bar'], ['foo'], []] " 438 "Actual: [['foo', 'bar'], ['foo'], []] "
437 "Which: has value ['foo', 'bar'] which has value 'bar' " 439 "Which: has value ['foo', 'bar'] which has value 'bar' "
438 "which is different. Expected: foo Actual: bar ^ " 440 "which is different. Expected: foo Actual: bar ^ "
439 "Differ at offset 0 at index 1 at index 0"); 441 "Differ at offset 0 at index 1 at index 0");
440 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)), 442 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)),
(...skipping 11 matching lines...) Expand all
452 "an object with length of a value greater than <0>) at index 2"); 454 "an object with length of a value greater than <0>) at index 2");
453 shouldFail(e, everyElement(allOf(contains('foo'), 455 shouldFail(e, everyElement(allOf(contains('foo'),
454 hasLength(greaterThan(0)))), 456 hasLength(greaterThan(0)))),
455 "Expected: every element((contains 'foo' and an object with " 457 "Expected: every element((contains 'foo' and an object with "
456 "length of a value greater than <0>)) " 458 "length of a value greater than <0>)) "
457 "Actual: [['foo', 'bar'], ['foo'], 3, []] " 459 "Actual: [['foo', 'bar'], ['foo'], 3, []] "
458 "Which: has value <3> which is not a string, map or iterable " 460 "Which: has value <3> which is not a string, map or iterable "
459 "at index 2"); 461 "at index 2");
460 }); 462 });
461 463
462 ut.test('anyElement', () { 464 test('anyElement', () {
463 var d = [1, 2]; 465 var d = [1, 2];
464 var e = [1, 1, 1]; 466 var e = [1, 1, 1];
465 shouldPass(d, anyElement(2)); 467 shouldPass(d, anyElement(2));
466 shouldFail(e, anyElement(2), 468 shouldFail(e, anyElement(2),
467 "Expected: some element <2> Actual: [1, 1, 1]"); 469 "Expected: some element <2> Actual: [1, 1, 1]");
468 }); 470 });
469 471
470 ut.test('orderedEquals', () { 472 test('orderedEquals', () {
471 shouldPass([null], orderedEquals([null])); 473 shouldPass([null], orderedEquals([null]));
472 var d = [1, 2]; 474 var d = [1, 2];
473 shouldPass(d, orderedEquals([1, 2])); 475 shouldPass(d, orderedEquals([1, 2]));
474 shouldFail(d, orderedEquals([2, 1]), 476 shouldFail(d, orderedEquals([2, 1]),
475 "Expected: equals [2, 1] ordered " 477 "Expected: equals [2, 1] ordered "
476 "Actual: [1, 2] " 478 "Actual: [1, 2] "
477 "Which: was <1> instead of <2> at location [0]"); 479 "Which: was <1> instead of <2> at location [0]");
478 }); 480 });
479 481
480 ut.test('unorderedEquals', () { 482 test('unorderedEquals', () {
481 var d = [1, 2]; 483 var d = [1, 2];
482 shouldPass(d, unorderedEquals([2, 1])); 484 shouldPass(d, unorderedEquals([2, 1]));
483 shouldFail(d, unorderedEquals([1]), 485 shouldFail(d, unorderedEquals([1]),
484 "Expected: equals [1] unordered " 486 "Expected: equals [1] unordered "
485 "Actual: [1, 2] " 487 "Actual: [1, 2] "
486 "Which: has too many elements (2 > 1)"); 488 "Which: has too many elements (2 > 1)");
487 shouldFail(d, unorderedEquals([3, 2, 1]), 489 shouldFail(d, unorderedEquals([3, 2, 1]),
488 "Expected: equals [3, 2, 1] unordered " 490 "Expected: equals [3, 2, 1] unordered "
489 "Actual: [1, 2] " 491 "Actual: [1, 2] "
490 "Which: has too few elements (2 < 3)"); 492 "Which: has too few elements (2 < 3)");
491 shouldFail(d, unorderedEquals([3, 1]), 493 shouldFail(d, unorderedEquals([3, 1]),
492 "Expected: equals [3, 1] unordered " 494 "Expected: equals [3, 1] unordered "
493 "Actual: [1, 2] " 495 "Actual: [1, 2] "
494 "Which: has no match for <3> at index 0"); 496 "Which: has no match for <3> at index 0");
495 }); 497 });
496 498
497 ut.test('unorderedMatchess', () { 499 test('unorderedMatchess', () {
498 var d = [1, 2]; 500 var d = [1, 2];
499 shouldPass(d, unorderedMatches([2, 1])); 501 shouldPass(d, unorderedMatches([2, 1]));
500 shouldPass(d, unorderedMatches([greaterThan(1), greaterThan(0)])); 502 shouldPass(d, unorderedMatches([greaterThan(1), greaterThan(0)]));
501 shouldFail(d, unorderedMatches([greaterThan(0)]), 503 shouldFail(d, unorderedMatches([greaterThan(0)]),
502 "Expected: matches [a value greater than <0>] unordered " 504 "Expected: matches [a value greater than <0>] unordered "
503 "Actual: [1, 2] " 505 "Actual: [1, 2] "
504 "Which: has too many elements (2 > 1)"); 506 "Which: has too many elements (2 > 1)");
505 shouldFail(d, unorderedMatches([3, 2, 1]), 507 shouldFail(d, unorderedMatches([3, 2, 1]),
506 "Expected: matches [<3>, <2>, <1>] unordered " 508 "Expected: matches [<3>, <2>, <1>] unordered "
507 "Actual: [1, 2] " 509 "Actual: [1, 2] "
508 "Which: has too few elements (2 < 3)"); 510 "Which: has too few elements (2 < 3)");
509 shouldFail(d, unorderedMatches([3, 1]), 511 shouldFail(d, unorderedMatches([3, 1]),
510 "Expected: matches [<3>, <1>] unordered " 512 "Expected: matches [<3>, <1>] unordered "
511 "Actual: [1, 2] " 513 "Actual: [1, 2] "
512 "Which: has no match for <3> at index 0"); 514 "Which: has no match for <3> at index 0");
513 shouldFail(d, unorderedMatches([greaterThan(3), greaterThan(0)]), 515 shouldFail(d, unorderedMatches([greaterThan(3), greaterThan(0)]),
514 "Expected: matches [a value greater than <3>, a value greater than " 516 "Expected: matches [a value greater than <3>, a value greater than "
515 "<0>] unordered " 517 "<0>] unordered "
516 "Actual: [1, 2] " 518 "Actual: [1, 2] "
517 "Which: has no match for a value greater than <3> at index 0"); 519 "Which: has no match for a value greater than <3> at index 0");
518 }); 520 });
519 521
520 ut.test('pairwise compare', () { 522 test('pairwise compare', () {
521 var c = [1, 2]; 523 var c = [1, 2];
522 var d = [1, 2, 3]; 524 var d = [1, 2, 3];
523 var e = [1, 4, 9]; 525 var e = [1, 4, 9];
524 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e, 526 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e,
525 "less than or equal"), 527 "less than or equal"),
526 "Expected: pairwise less than or equal [1, 4, 9] " 528 "Expected: pairwise less than or equal [1, 4, 9] "
527 "Actual: 'x' " 529 "Actual: 'x' "
528 "Which: is not an Iterable"); 530 "Which: is not an Iterable");
529 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"), 531 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"),
530 "Expected: pairwise less than or equal [1, 4, 9] " 532 "Expected: pairwise less than or equal [1, 4, 9] "
531 "Actual: [1, 2] " 533 "Actual: [1, 2] "
532 "Which: has length 2 instead of 3"); 534 "Which: has length 2 instead of 3");
533 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal")); 535 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"));
534 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"), 536 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"),
535 "Expected: pairwise less than [1, 4, 9] " 537 "Expected: pairwise less than [1, 4, 9] "
536 "Actual: [1, 2, 3] " 538 "Actual: [1, 2, 3] "
537 "Which: has <1> which is not less than <1> at index 0"); 539 "Which: has <1> which is not less than <1> at index 0");
538 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of")); 540 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of"));
539 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"), 541 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"),
540 "Expected: pairwise double [1, 4, 9] " 542 "Expected: pairwise double [1, 4, 9] "
541 "Actual: [1, 2, 3] " 543 "Actual: [1, 2, 3] "
542 "Which: has <1> which is not double <1> at index 0"); 544 "Which: has <1> which is not double <1> at index 0");
543 }); 545 });
544 }); 546 });
545 547
546 ut.group('Map Matchers', () { 548 group('Map Matchers', () {
547 549
548 ut.test('isEmpty', () { 550 test('isEmpty', () {
549 var a = new Map(); 551 var a = new Map();
550 shouldPass({}, isEmpty); 552 shouldPass({}, isEmpty);
551 shouldPass(a, isEmpty); 553 shouldPass(a, isEmpty);
552 a['foo'] = 'bar'; 554 a['foo'] = 'bar';
553 shouldFail(a, isEmpty, "Expected: empty " 555 shouldFail(a, isEmpty, "Expected: empty "
554 "Actual: {'foo': 'bar'}"); 556 "Actual: {'foo': 'bar'}");
555 }); 557 });
556 558
557 ut.test('equals', () { 559 test('equals', () {
558 var a = new Map(); 560 var a = new Map();
559 a['foo'] = 'bar'; 561 a['foo'] = 'bar';
560 var b = new Map(); 562 var b = new Map();
561 b['foo'] = 'bar'; 563 b['foo'] = 'bar';
562 var c = new Map(); 564 var c = new Map();
563 c['bar'] = 'foo'; 565 c['bar'] = 'foo';
564 shouldPass(a, equals(b)); 566 shouldPass(a, equals(b));
565 shouldFail(b, equals(c), 567 shouldFail(b, equals(c),
566 "Expected: {'bar': 'foo'} " 568 "Expected: {'bar': 'foo'} "
567 "Actual: {'foo': 'bar'} " 569 "Actual: {'foo': 'bar'} "
568 "Which: is missing map key 'bar'"); 570 "Which: is missing map key 'bar'");
569 }); 571 });
570 572
571 ut.test('equals with different lengths', () { 573 test('equals with different lengths', () {
572 var a = new LinkedHashMap(); 574 var a = new LinkedHashMap();
573 a['foo'] = 'bar'; 575 a['foo'] = 'bar';
574 var b = new LinkedHashMap(); 576 var b = new LinkedHashMap();
575 b['foo'] = 'bar'; 577 b['foo'] = 'bar';
576 b['bar'] = 'foo'; 578 b['bar'] = 'foo';
577 var c = new LinkedHashMap(); 579 var c = new LinkedHashMap();
578 c['bar'] = 'foo'; 580 c['bar'] = 'foo';
579 c['barrista'] = 'caffeine'; 581 c['barrista'] = 'caffeine';
580 shouldFail(a, equals(b), 582 shouldFail(a, equals(b),
581 "Expected: {'foo': 'bar', 'bar': 'foo'} " 583 "Expected: {'foo': 'bar', 'bar': 'foo'} "
(...skipping 14 matching lines...) Expand all
596 shouldFail(a, equals(c), 598 shouldFail(a, equals(c),
597 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} " 599 "Expected: {'bar': 'foo', 'barrista': 'caffeine'} "
598 "Actual: {'foo': 'bar'} " 600 "Actual: {'foo': 'bar'} "
599 "Which: has different length and is missing map key 'bar'"); 601 "Which: has different length and is missing map key 'bar'");
600 shouldFail(c, equals(a), 602 shouldFail(c, equals(a),
601 "Expected: {'foo': 'bar'} " 603 "Expected: {'foo': 'bar'} "
602 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} " 604 "Actual: {'bar': 'foo', 'barrista': 'caffeine'} "
603 "Which: has different length and is missing map key 'foo'"); 605 "Which: has different length and is missing map key 'foo'");
604 }); 606 });
605 607
606 ut.test('equals with matcher value', () { 608 test('equals with matcher value', () {
607 var a = new Map(); 609 var a = new Map();
608 a['foo'] = 'bar'; 610 a['foo'] = 'bar';
609 shouldPass(a, equals({'foo': startsWith('ba')})); 611 shouldPass(a, equals({'foo': startsWith('ba')}));
610 shouldFail(a, equals({'foo': endsWith('ba')}), 612 shouldFail(a, equals({'foo': endsWith('ba')}),
611 "Expected: {'foo': <a string ending with 'ba'>} " 613 "Expected: {'foo': <a string ending with 'ba'>} "
612 "Actual: {'foo': 'bar'} " 614 "Actual: {'foo': 'bar'} "
613 "Which: does not match a string ending with 'ba' " 615 "Which: does not match a string ending with 'ba' "
614 "at location ['foo']"); 616 "at location ['foo']");
615 }); 617 });
616 618
617 ut.test('contains', () { 619 test('contains', () {
618 var a = new Map(); 620 var a = new Map();
619 a['foo'] = 'bar'; 621 a['foo'] = 'bar';
620 var b = new Map(); 622 var b = new Map();
621 shouldPass(a, contains('foo')); 623 shouldPass(a, contains('foo'));
622 shouldFail(b, contains('foo'), 624 shouldFail(b, contains('foo'),
623 "Expected: contains 'foo' Actual: {}"); 625 "Expected: contains 'foo' Actual: {}");
624 shouldFail(10, contains('foo'), 626 shouldFail(10, contains('foo'),
625 "Expected: contains 'foo' Actual: <10> " 627 "Expected: contains 'foo' Actual: <10> "
626 "Which: is not a string, map or iterable"); 628 "Which: is not a string, map or iterable");
627 }); 629 });
628 630
629 ut.test('containsValue', () { 631 test('containsValue', () {
630 var a = new Map(); 632 var a = new Map();
631 a['foo'] = 'bar'; 633 a['foo'] = 'bar';
632 shouldPass(a, containsValue('bar')); 634 shouldPass(a, containsValue('bar'));
633 shouldFail(a, containsValue('ba'), 635 shouldFail(a, containsValue('ba'),
634 "Expected: contains value 'ba' " 636 "Expected: contains value 'ba' "
635 "Actual: {'foo': 'bar'}"); 637 "Actual: {'foo': 'bar'}");
636 }); 638 });
637 639
638 ut.test('containsPair', () { 640 test('containsPair', () {
639 var a = new Map(); 641 var a = new Map();
640 a['foo'] = 'bar'; 642 a['foo'] = 'bar';
641 shouldPass(a, containsPair('foo', 'bar')); 643 shouldPass(a, containsPair('foo', 'bar'));
642 shouldFail(a, containsPair('foo', 'ba'), 644 shouldFail(a, containsPair('foo', 'ba'),
643 "Expected: contains pair 'foo' => 'ba' " 645 "Expected: contains pair 'foo' => 'ba' "
644 "Actual: {'foo': 'bar'} " 646 "Actual: {'foo': 'bar'} "
645 "Which: is different. Both strings start the same, but " 647 "Which: is different. Both strings start the same, but "
646 "the given value also has the following trailing characters: r"); 648 "the given value also has the following trailing characters: r");
647 shouldFail(a, containsPair('fo', 'bar'), 649 shouldFail(a, containsPair('fo', 'bar'),
648 "Expected: contains pair 'fo' => 'bar' " 650 "Expected: contains pair 'fo' => 'bar' "
649 "Actual: {'foo': 'bar'} " 651 "Actual: {'foo': 'bar'} "
650 "Which: doesn't contain key 'fo'"); 652 "Which: doesn't contain key 'fo'");
651 }); 653 });
652 654
653 ut.test('hasLength', () { 655 test('hasLength', () {
654 var a = new Map(); 656 var a = new Map();
655 a['foo'] = 'bar'; 657 a['foo'] = 'bar';
656 var b = new Map(); 658 var b = new Map();
657 shouldPass(a, hasLength(1)); 659 shouldPass(a, hasLength(1));
658 shouldFail(b, hasLength(1), 660 shouldFail(b, hasLength(1),
659 "Expected: an object with length of <1> " 661 "Expected: an object with length of <1> "
660 "Actual: {} " 662 "Actual: {} "
661 "Which: has length of <0>"); 663 "Which: has length of <0>");
662 }); 664 });
663 }); 665 });
664 666
665 ut.group('Operator Matchers', () { 667 group('Operator Matchers', () {
666 668
667 ut.test('anyOf', () { 669 test('anyOf', () {
668 shouldFail(0, anyOf([equals(1), equals(2)]), 670 shouldFail(0, anyOf([equals(1), equals(2)]),
669 "Expected: (<1> or <2>) Actual: <0>"); 671 "Expected: (<1> or <2>) Actual: <0>");
670 shouldPass(1, anyOf([equals(1), equals(2)])); 672 shouldPass(1, anyOf([equals(1), equals(2)]));
671 }); 673 });
672 674
673 ut.test('allOf', () { 675 test('allOf', () {
674 shouldPass(1, allOf([lessThan(10), greaterThan(0)])); 676 shouldPass(1, allOf([lessThan(10), greaterThan(0)]));
675 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]), 677 shouldFail(-1, allOf([lessThan(10), greaterThan(0)]),
676 "Expected: (a value less than <10> and a value greater than <0>) " 678 "Expected: (a value less than <10> and a value greater than <0>) "
677 "Actual: <-1> " 679 "Actual: <-1> "
678 "Which: is not a value greater than <0>"); 680 "Which: is not a value greater than <0>");
679 }); 681 });
680 }); 682 });
681 683
682 ut.group('Future Matchers', () { 684 group('Future Matchers', () {
683 685
684 ut.test('completes - unexpected error', () { 686 test('completes - unexpected error', () {
685 var completer = new Completer(); 687 var completer = new Completer();
686 completer.completeError('X'); 688 completer.completeError('X');
687 shouldFail(completer.future, completes, 689 shouldFail(completer.future, completes,
688 contains('Expected future to complete successfully, ' 690 contains('Expected future to complete successfully, '
689 'but it failed with X'), 691 'but it failed with X'),
690 isAsync: true); 692 isAsync: true);
691 }); 693 });
692 694
693 ut.test('completes - successfully', () { 695 test('completes - successfully', () {
694 var completer = new Completer(); 696 var completer = new Completer();
695 completer.complete('1'); 697 completer.complete('1');
696 shouldPass(completer.future, completes, isAsync: true); 698 shouldPass(completer.future, completes, isAsync: true);
697 }); 699 });
698 700
699 ut.test('throws - unexpected to see normal completion', () { 701 test('throws - unexpected to see normal completion', () {
700 var completer = new Completer(); 702 var completer = new Completer();
701 completer.complete('1'); 703 completer.complete('1');
702 shouldFail(completer.future, throws, 704 shouldFail(completer.future, throws,
703 contains("Expected future to fail, but succeeded with '1'"), 705 contains("Expected future to fail, but succeeded with '1'"),
704 isAsync: true); 706 isAsync: true);
705 }); 707 });
706 708
707 ut.test('throws - expected to see exception', () { 709 test('throws - expected to see exception', () {
708 var completer = new Completer(); 710 var completer = new Completer();
709 completer.completeError('X'); 711 completer.completeError('X');
710 shouldPass(completer.future, throws, isAsync: true); 712 shouldPass(completer.future, throws, isAsync: true);
711 }); 713 });
712 714
713 ut.test('throws - expected to see exception thrown later on', () { 715 test('throws - expected to see exception thrown later on', () {
714 var completer = new Completer(); 716 var completer = new Completer();
715 var chained = completer.future.then((_) { throw 'X'; }); 717 var chained = completer.future.then((_) { throw 'X'; });
716 shouldPass(chained, throws, isAsync: true); 718 shouldPass(chained, throws, isAsync: true);
717 completer.complete('1'); 719 completer.complete('1');
718 }); 720 });
719 721
720 ut.test('throwsA - unexpected normal completion', () { 722 test('throwsA - unexpected normal completion', () {
721 var completer = new Completer(); 723 var completer = new Completer();
722 completer.complete('1'); 724 completer.complete('1');
723 shouldFail(completer.future, throwsA(equals('X')), 725 shouldFail(completer.future, throwsA(equals('X')),
724 contains("Expected future to fail, but succeeded with '1'"), 726 contains("Expected future to fail, but succeeded with '1'"),
725 isAsync: true); 727 isAsync: true);
726 }); 728 });
727 729
728 ut.test('throwsA - correct error', () { 730 test('throwsA - correct error', () {
729 var completer = new Completer(); 731 var completer = new Completer();
730 completer.completeError('X'); 732 completer.completeError('X');
731 shouldPass(completer.future, throwsA(equals('X')), isAsync: true); 733 shouldPass(completer.future, throwsA(equals('X')), isAsync: true);
732 }); 734 });
733 735
734 ut.test('throwsA - wrong error', () { 736 test('throwsA - wrong error', () {
735 var completer = new Completer(); 737 var completer = new Completer();
736 completer.completeError('X'); 738 completer.completeError('X');
737 shouldFail(completer.future, throwsA(equals('Y')), 739 shouldFail(completer.future, throwsA(equals('Y')),
738 "Expected: 'Y' Actual: 'X' " 740 "Expected: 'Y' Actual: 'X' "
739 "Which: is different. " 741 "Which: is different. "
740 "Expected: Y Actual: X ^ Differ at offset 0", 742 "Expected: Y Actual: X ^ Differ at offset 0",
741 isAsync: true); 743 isAsync: true);
742 }); 744 });
743 }); 745 });
744 746
745 ut.group('Predicate Matchers', () { 747 group('Predicate Matchers', () {
746 ut.test('isInstanceOf', () { 748 test('isInstanceOf', () {
747 shouldFail(0, predicate((x) => x is String, "an instance of String"), 749 shouldFail(0, predicate((x) => x is String, "an instance of String"),
748 "Expected: an instance of String Actual: <0>"); 750 "Expected: an instance of String Actual: <0>");
749 shouldPass('cow', predicate((x) => x is String, "an instance of String")); 751 shouldPass('cow', predicate((x) => x is String, "an instance of String"));
750 }); 752 });
751 }); 753 });
752 754
753 ut.group('exception/error matchers', () { 755 group('exception/error matchers', () {
754 // TODO(gram): extend this to more types; for now this is just 756 // TODO(gram): extend this to more types; for now this is just
755 // the types being added in this CL. 757 // the types being added in this CL.
756 758
757 // TODO: enable this test when it works. 759 test('throwsCyclicInitializationError', () {
758 // See issue 12052. 760 expect(() => _Bicycle.foo, throwsCyclicInitializationError);
759 ut.skip_test('throwsCyclicInitializationError', () {
760 expect(() => new Bicycle(), throwsCyclicInitializationError);
761 }); 761 });
762 762
763 ut.test('throwsAbstractClassInstantiationError', () { 763 test('throwsAbstractClassInstantiationError', () {
764 expect(() => new Abstraction(), throwsAbstractClassInstantiationError); 764 expect(() => new _AbstractClass(), throwsAbstractClassInstantiationError);
765 }); 765 });
766 766
767 ut.test('throwsConcurrentModificationError', () { 767 test('throwsConcurrentModificationError', () {
768 expect(() { 768 expect(() {
769 var a = { 'foo': 'bar' }; 769 var a = { 'foo': 'bar' };
770 for (var k in a.keys) { 770 for (var k in a.keys) {
771 a.remove(k); 771 a.remove(k);
772 } 772 }
773 }, throwsConcurrentModificationError); 773 }, throwsConcurrentModificationError);
774 }); 774 });
775 775
776 ut.test('throwsNullThrownError', () { 776 test('throwsNullThrownError', () {
777 expect(() => throw null, throwsNullThrownError); 777 expect(() => throw null, throwsNullThrownError);
778 }); 778 });
779 779
780 ut.test('throwsFallThroughError', () { 780 test('throwsFallThroughError', () {
781 expect(() { 781 expect(() {
782 var a = 0; 782 var a = 0;
783 switch (a) { 783 switch (a) {
784 case 0: 784 case 0:
785 a += 1; 785 a += 1;
786 case 1: 786 case 1:
787 return; 787 return;
788 } 788 }
789 }, throwsFallThroughError); 789 }, throwsFallThroughError);
790 }); 790 });
791 }); 791 });
792 } 792 }
793 793
794 class Bicycle { 794 class _Bicycle {
blois 2014/03/24 22:55:21 Not really critical to make classes in tests priva
kevmoo 2014/03/25 00:12:46 Force of habit. :-)
795 static var foo = bar(); 795 static final foo = bar();
796 796
797 static bar() { 797 static bar() {
798 return foo + 1; 798 return foo + 1;
799 } 799 }
800
801 X() {
802 print(foo);
803 }
804 } 800 }
805 801
806 abstract class Abstraction { 802 abstract class _AbstractClass {
807 void norealization();
808 } 803 }
809
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698