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

Side by Side Diff: tests/lib/unittest/mock_test.dart

Issue 10832058: Improved the way we generate mismatch descriptions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 #library('unittestTest');
6 #import('../../../lib/unittest/unittest.dart');
7
8 class MockList extends Mock implements List {
9 }
10
11 class Foo {
12 sum(a, b, c) => a + b + c;
13 }
14
15 class FooSpy extends Mock implements Foo {
16 Foo real;
17 FooSpy() {
18 real = new Foo();
19 this.when(callsTo('sum')).alwaysCall(real.sum);
20 }
21 }
22
23 makeTestLogEntry(String methodName, List args, int time,
24 [String mockName]) {
25 LogEntry e = new LogEntry(mockName, methodName, args, Action.IGNORE);
26 e.time = new Date.fromMillisecondsSinceEpoch(time, true);
27 return e;
28 }
29
30 makeTestLog() {
31 LogEntryList logList = new LogEntryList('test');
32 List args = new List();
33 logList.add(makeTestLogEntry('a', args, 1000));
34 logList.add(makeTestLogEntry('b', args, 2000));
35 logList.add(makeTestLogEntry('c', args, 3000));
36 return logList;
37 }
38
39 main() {
40 test('Mocking: Basics', () {
41 var m = new Mock();
42 print(m.length);
43 m.getLogs(callsTo('get length')).verify(happenedOnce);
44
45 m.when(callsTo('foo', 1, 2)).thenReturn('A').thenReturn('B');
46 m.when(callsTo('foo', 1, 1)).thenReturn('C');
47 m.when(callsTo('foo', 9, anything)).thenReturn('D');
48 m.when(callsTo('bar', anything, anything)).thenReturn('E');
49 m.when(callsTo('foobar')).thenReturn('F');
50
51 var s = '${m.foo(1,2)}${m.foo(1,1)}${m.foo(9,10)}'
52 '${m.bar(1,1)}${m.foo(1,2)}';
53 m.getLogs(callsTo('foo', anything, anything)).
54 verify(happenedExactly(4));
55 m.getLogs(callsTo('foo', 1, anything)).verify(happenedExactly(3));
56 m.getLogs(callsTo('foo', 9, anything)).verify(happenedOnce);
57 m.getLogs(callsTo('foo', anything, 2)).verify(happenedExactly(2));
58 m.getLogs(callsTo('foobar')).verify(neverHappened);
59 m.getLogs(callsTo('foo', 10, anything)).verify(neverHappened);
60 m.getLogs(callsTo('foo'), returning(anyOf('A', 'C'))).
61 verify(happenedExactly(2));
62 expect(s, 'ACDEB');
63 });
64
65 test('Mocking: Mock List', () {
66 var l = new MockList();
67 l.when(callsTo('get length')).thenReturn(1);
68 l.when(callsTo('add', anything)).alwaysReturn(0);
69 l.add('foo');
70 expect(l.length, 1);
71
72 var m = new MockList();
73 m.when(callsTo('add', anything)).alwaysReturn(0);
74
75 m.add('foo');
76 m.add('bar');
77
78 m.getLogs(callsTo('add')).verify(happenedExactly(2));
79 m.getLogs(callsTo('add', 'foo')).verify(happenedOnce);
80 });
81
82 test('Mocking: Spy', () {
83 var p = new FooSpy();
84 p.sum(1, 2, 3);
85 p.getLogs(callsTo('sum')).verify(happenedOnce);
86 p.sum(2, 2, 2);
87 p.getLogs(callsTo('sum')).verify(happenedExactly(2));
88 p.getLogs(callsTo('sum')).verify(sometimeReturned(6));
89 p.getLogs(callsTo('sum')).verify(alwaysReturned(6));
90 p.getLogs(callsTo('sum')).verify(neverReturned(5));
91 p.sum(2, 2, 1);
92 p.getLogs(callsTo('sum')).verify(sometimeReturned(5));
93 });
94
95 test('Mocking: Excess Calls', () {
96 var m = new Mock();
97 m.when(callsTo('foo')).alwaysReturn(null);
98 expect(() { m.foo(); }, returnsNormally);
99 expect(() { m.foo(); }, returnsNormally);
100 expect(
101 () {
102 m.getLogs(callsTo('foo')).verify(happenedOnce);
103 },
104 throwsA(
105 (e) =>
106 collapseWhitespace(e.toString()) ==
107 "Expected foo() to be called 1 times but:"
108 " was called 2 times.")
109 );
110 });
111
112 test('Mocking: No action', () {
113 var m = new Mock();
114 m.when(callsTo('foo')).thenReturn(null);
115 expect(
116 () {
117 m.foo();
Siggi Cherem (dart-lang) 2012/07/31 17:16:40 I prefer the line breaks you had in the previous t
118 },
119 returnsNormally);
120 expect(
121 () {
122 m.foo();
123 },
124 throwsA(
125 (e) =>
126 e.toString() ==
127 'Exception: No more actions for method foo.')
128 );
129 });
130
131 test('Mocking: No matching return', () {
132 var p = new FooSpy();
133 p.sum(1, 2, 3);
134 expect(
135 () {
136 p.getLogs(callsTo('sum')).verify(sometimeReturned(0));
137 },
138 throwsA(
139 (e) =>
140 collapseWhitespace(e.toString()) ==
141 "Expected sum() to sometimes return <0> but: never did.")
142 );
143 });
144
145 test('Mocking: No behavior', () {
146 var m = new Mock.custom(throwIfNoBehavior:true);
147 m.when(callsTo('foo')).thenReturn(null);
148 expect(
149 () {
150 m.foo();
151 },
152 returnsNormally);
153 expect(
154 () {
155 m.bar();
156 },
157 throwsA(
158 (e) =>
159 e.toString() ==
160 'Exception: No behavior specified for method bar.')
161 );
162 });
163
164 test('Mocking: Shared logList', () {
165 var logList = new LogEntryList();
166 var m1 = new Mock.custom(name:'m1', log:logList);
167 var m2 = new Mock.custom(name:'m2', log:logList);
168 m1.foo();
169 m2.foo();
170 m1.bar();
171 m2.bar();
172 expect(logList.logs.length, 4);
173 logList.getMatches(anything, callsTo('foo')).verify(happenedExactly(2));
174 logList.getMatches('m1', callsTo('foo')).verify(happenedOnce);
175 logList.getMatches('m1', callsTo('bar')).verify(happenedOnce);
176 m2.getLogs(callsTo('foo')).verify(happenedOnce);
177 m2.getLogs(callsTo('bar')).verify(happenedOnce);
178 });
179
180 test('Mocking: Null CallMatcher', () {
181 var m = new Mock();
182 m.when(callsTo(null, 1)).alwaysReturn(2);
183 m.when(callsTo(null, 2)).alwaysReturn(4);
184 expect(m.foo(1), 2);
185 expect(m.foo(2), 4);
186 expect(m.bar(1), 2);
187 expect(m.bar(2), 4);
188 m.getLogs(callsTo()).verify(happenedExactly(4));
189 m.getLogs(callsTo(null, 1)).verify(happenedExactly(2));
190 m.getLogs(callsTo(null, 2)).verify(happenedExactly(2));
191 m.getLogs(null, returning(1)).verify(neverHappened);
192 m.getLogs(null, returning(2)).verify(happenedExactly(2));
193 m.getLogs(null, returning(4)).verify(happenedExactly(2));
194 });
195
196 test('Mocking: No logging', () {
197 var m = new Mock.custom(enableLogging:false);
198 m.Test();
199 expect(() { m.getLogs(callsTo('Test')); },
200 throwsA((e) => e.toString() ==
201 "Exception: Can't retrieve logs when logging was never enabled."));
202 });
203
204 test('Mocking: Find logList entry', () {
205 LogEntryList logList = makeTestLog();
206 // Basic behavior, with call matcher.
207 expect(logList.findLogEntry(callsTo('a')), 0);
208 expect(logList.findLogEntry(callsTo('b')), 1);
209 expect(logList.findLogEntry(callsTo('c')), 2);
210 expect(logList.findLogEntry(callsTo('d')), -1);
211 // Find using predicate.
212 expect(logList.findLogEntry((le) => le.methodName == 'a'), 0);
213 expect(logList.findLogEntry((le) => le.methodName == 'b'), 1);
214 expect(logList.findLogEntry((le) => le.methodName == 'c'), 2);
215 // Test explicit return value.
216 expect(logList.findLogEntry((le) => le.methodName == 'd', 0, 3), 3);
217 // Find from start of logList.
218 expect(logList.findLogEntry(callsTo('a'), 0), 0);
219 expect(logList.findLogEntry(callsTo('b'), 0), 1);
220 expect(logList.findLogEntry(callsTo('c'), 0), 2);
221 // Find from second entry in logList.
222 expect(logList.findLogEntry(callsTo('a'), 1), -1);
223 expect(logList.findLogEntry(callsTo('b'), 1), 1);
224 expect(logList.findLogEntry(callsTo('c'), 1), 2);
225 // Find from last entry in logList.
226 expect(logList.findLogEntry(callsTo('a'), 2), -1);
227 expect(logList.findLogEntry(callsTo('b'), 2), -1);
228 expect(logList.findLogEntry(callsTo('c'), 2), 2);
229 // Find from start position passed end of logList.
230 expect(logList.findLogEntry(callsTo('a'), 3), -1);
231 expect(logList.findLogEntry(callsTo('b'), 3), -1);
232 expect(logList.findLogEntry(callsTo('c'), 3), -1);
233 // No restriction on entry.
234 expect(logList.findLogEntry(null, 0), 0);
235 expect(logList.findLogEntry(null, 1), 1);
236 expect(logList.findLogEntry(null, 2), 2);
237 expect(logList.findLogEntry(null, 3), -1);
238 });
239
240 test('Mocking: from,after,before,until', () {
241 LogEntryList logList = makeTestLog();
242 LogEntryList log2;
243 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true);
244 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true);
245 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true);
246 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true);
247 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true);
248
249 log2 = logList.before(t0);
250 expect(log2.logs, hasLength(0));
251 expect(log2.filter, 'test before 1970-01-01 00:00:00.000Z');
252 log2 = logList.until(t0);
253 expect(log2.logs, hasLength(0));
254 expect(log2.filter, 'test until 1970-01-01 00:00:00.000Z');
255 log2 = logList.from(t0);
256 expect(log2.logs, hasLength(3));
257 expect(log2.first.methodName, 'a');
258 expect(log2.last.methodName, 'c');
259 expect(log2.filter, 'test from 1970-01-01 00:00:00.000Z');
260 log2 = logList.after(t0);
261 expect(log2.logs, hasLength(3));
262 expect(log2.first.methodName, 'a');
263 expect(log2.last.methodName, 'c');
264 expect(log2.filter, 'test after 1970-01-01 00:00:00.000Z');
265
266 log2 = logList.before(t1000);
267 expect(log2.logs, hasLength(0));
268 log2 = logList.until(t1000);
269 expect(log2.logs, hasLength(1));
270 expect(log2.first.methodName, 'a');
271 expect(log2.last.methodName, 'a');
272 log2 = logList.from(t1000);
273 expect(log2.logs, hasLength(3));
274 expect(log2.first.methodName, 'a');
275 expect(log2.last.methodName, 'c');
276 log2 = logList.after(t1000);
277 expect(log2.logs, hasLength(2));
278 expect(log2.first.methodName, 'b');
279 expect(log2.last.methodName, 'c');
280
281 log2 = logList.before(t2000);
282 expect(log2.logs, hasLength(1));
283 expect(log2.first.methodName, 'a');
284 expect(log2.last.methodName, 'a');
285 log2 = logList.until(t2000);
286 expect(log2.logs, hasLength(2));
287 expect(log2.first.methodName, 'a');
288 expect(log2.last.methodName, 'b');
289 log2 = logList.from(t2000);
290 expect(log2.logs, hasLength(2));
291 expect(log2.first.methodName, 'b');
292 expect(log2.last.methodName, 'c');
293 log2 = logList.after(t2000);
294 expect(log2.logs, hasLength(1));
295 expect(log2.first.methodName, 'c');
296 expect(log2.last.methodName, 'c');
297
298 log2 = logList.before(t3000);
299 expect(log2.logs, hasLength(2));
300 expect(log2.first.methodName, 'a');
301 expect(log2.last.methodName, 'b');
302 log2 = logList.until(t3000);
303 expect(log2.logs, hasLength(3));
304 expect(log2.first.methodName, 'a');
305 expect(log2.last.methodName, 'c');
306
307 log2 = logList.from(t3000);
308 expect(log2.logs, hasLength(1));
309 expect(log2.first.methodName, 'c');
310 expect(log2.last.methodName, 'c');
311 log2 = logList.after(t3000);
312 expect(log2.logs, hasLength(0));
313
314 log2 = logList.before(t4000);
315 expect(log2.logs, hasLength(3));
316 expect(log2.first.methodName, 'a');
317 expect(log2.last.methodName, 'c');
318 log2 = logList.until(t4000);
319 expect(log2.logs, hasLength(3));
320 expect(log2.first.methodName, 'a');
321 expect(log2.last.methodName, 'c');
322 log2 = logList.from(t4000);
323 expect(log2.logs, hasLength(0));
324 log2 = logList.after(t4000);
325 expect(log2.logs, hasLength(0));
326 });
327
328 test('Mocking: inplace from,after,before,until', () {
329 Date t0 = new Date.fromMillisecondsSinceEpoch(0, true);
330 Date t1000 = new Date.fromMillisecondsSinceEpoch(1000, true);
331 Date t2000 = new Date.fromMillisecondsSinceEpoch(2000, true);
332 Date t3000 = new Date.fromMillisecondsSinceEpoch(3000, true);
333 Date t4000 = new Date.fromMillisecondsSinceEpoch(4000, true);
334
335 LogEntryList logList = makeTestLog().before(t0, true);
336 expect(logList.logs, hasLength(0));
337 expect(logList.filter, 'test before 1970-01-01 00:00:00.000Z');
338 logList = makeTestLog().until(t0, true);
339 expect(logList.logs, hasLength(0));
340 expect(logList.filter, 'test until 1970-01-01 00:00:00.000Z');
341 logList = makeTestLog().from(t0, true);
342 expect(logList.logs, hasLength(3));
343 expect(logList.first.methodName, 'a');
344 expect(logList.last.methodName, 'c');
345 expect(logList.filter, 'test from 1970-01-01 00:00:00.000Z');
346 logList = makeTestLog().after(t0, true);
347 expect(logList.logs, hasLength(3));
348 expect(logList.first.methodName, 'a');
349 expect(logList.last.methodName, 'c');
350 expect(logList.filter, 'test after 1970-01-01 00:00:00.000Z');
351
352 logList = makeTestLog().before(t1000, true);
353 expect(logList.logs, hasLength(0));
354 logList = makeTestLog().until(t1000, true);
355 expect(logList.logs, hasLength(1));
356 expect(logList.first.methodName, 'a');
357 expect(logList.last.methodName, 'a');
358 logList = makeTestLog().from(t1000, true);
359 expect(logList.logs, hasLength(3));
360 expect(logList.first.methodName, 'a');
361 expect(logList.last.methodName, 'c');
362 logList = makeTestLog().after(t1000, true);
363 expect(logList.logs, hasLength(2));
364 expect(logList.first.methodName, 'b');
365 expect(logList.last.methodName, 'c');
366
367 logList = makeTestLog().before(t2000, true);
368 expect(logList.logs, hasLength(1));
369 expect(logList.first.methodName, 'a');
370 expect(logList.last.methodName, 'a');
371 logList = makeTestLog().until(t2000, true);
372 expect(logList.logs, hasLength(2));
373 expect(logList.first.methodName, 'a');
374 expect(logList.last.methodName, 'b');
375 logList = makeTestLog().from(t2000, true);
376 expect(logList.logs, hasLength(2));
377 expect(logList.first.methodName, 'b');
378 expect(logList.last.methodName, 'c');
379 logList = makeTestLog().after(t2000, true);
380 expect(logList.logs, hasLength(1));
381 expect(logList.first.methodName, 'c');
382 expect(logList.last.methodName, 'c');
383
384 logList = makeTestLog().before(t3000, true);
385 expect(logList.logs, hasLength(2));
386 expect(logList.first.methodName, 'a');
387 expect(logList.last.methodName, 'b');
388 logList = makeTestLog().until(t3000, true);
389 expect(logList.logs, hasLength(3));
390 expect(logList.first.methodName, 'a');
391 expect(logList.last.methodName, 'c');
392 logList = makeTestLog().from(t3000, true);
393 expect(logList.logs, hasLength(1));
394 expect(logList.first.methodName, 'c');
395 expect(logList.last.methodName, 'c');
396 logList = makeTestLog().after(t3000);
397 expect(logList.logs, hasLength(0));
398
399 logList = makeTestLog().before(t4000, true);
400 expect(logList.logs, hasLength(3));
401 expect(logList.first.methodName, 'a');
402 expect(logList.last.methodName, 'c');
403 logList = makeTestLog().until(t4000, true);
404 expect(logList.logs, hasLength(3));
405 expect(logList.first.methodName, 'a');
406 expect(logList.last.methodName, 'c');
407 logList = makeTestLog().from(t4000, true);
408 expect(logList.logs, hasLength(0));
409 logList = makeTestLog().after(t4000, true);
410 expect(logList.logs, hasLength(0));
411 });
412
413 test('Mocking: Neighbors', () {
414 LogEntryList logList = new LogEntryList('test');
415 List args0 = new List();
416 List args1 = new List();
417 args1.add('test');
418 LogEntry e0 = makeTestLogEntry('foo', args0, 1000);
419 logList.add(e0);
420 LogEntry e1 = makeTestLogEntry('bar1', args0, 2000, 'a');
421 logList.add(e1);
422 LogEntry e2 = makeTestLogEntry('bar1', args1, 3000, 'b');
423 logList.add(e2);
424 LogEntry e3 = makeTestLogEntry('foo', args0, 4000);
425 logList.add(e3);
426 LogEntry e4 = makeTestLogEntry('hello', args0, 4500);
427 logList.add(e4);
428 LogEntry e5 = makeTestLogEntry('bar2', args0, 5000, 'a');
429 logList.add(e5);
430 LogEntry e6 = makeTestLogEntry('bar2', args1, 6000, 'b');
431 logList.add(e6);
432 LogEntry e7 = makeTestLogEntry('foo', args0, 7000);
433 logList.add(e7);
434 LogEntry e8 = makeTestLogEntry('bar3', args0, 8000, 'a');
435 logList.add(e8);
436 LogEntry e9 = makeTestLogEntry('bar3', args1, 9000, 'b');
437 logList.add(e9);
438 LogEntry e10 = makeTestLogEntry('foo', args0, 10000);
439 logList.add(e10);
440
441 LogEntryList keyList = new LogEntryList('keys');
442
443 // Test with empty key list.
444
445 LogEntryList result;
446 result = logList.preceding(keyList);
447 expect(result.logs, hasLength(0));
448
449 result = logList.preceding(keyList, includeKeys:true);
450 expect(result.logs, hasLength(0));
451
452 // Single key, distance 1, no restrictions.
453
454 keyList.add(e3);
455 result = logList.preceding(keyList);
456 expect(result.logs, orderedEquals([e2]));
457
458 result = logList.following(keyList);
459 expect(result.logs, orderedEquals([e4]));
460
461 // Single key, distance 2, no restrictions.
462
463 result = logList.preceding(keyList, distance:2);
464 expect(result.logs, orderedEquals([e1, e2]));
465
466 result = logList.following(keyList, distance:2);
467 expect(result.logs, orderedEquals([e4, e5]));
468
469 // Single key, distance 3, no restrictions.
470
471 result = logList.preceding(keyList, distance:3);
472 expect(result.logs, orderedEquals([e0, e1, e2]));
473
474 result = logList.following(keyList, distance:3);
475 expect(result.logs, orderedEquals([e4, e5, e6]));
476
477 // Include keys in result
478
479 result = logList.preceding(keyList, distance:3, includeKeys:true);
480 expect(result.logs, orderedEquals([e0, e1, e2, e3]));
481
482 result = logList.following(keyList, distance:3, includeKeys:true);
483 expect(result.logs, orderedEquals([e3, e4, e5, e6]));
484
485 // Restrict the matches
486
487 result = logList.preceding(keyList, logFilter:callsTo(startsWith('bar')),
488 distance:3);
489 expect(result.logs, orderedEquals([e1, e2]));
490
491 result = logList.preceding(keyList, logFilter:callsTo(startsWith('bar')),
492 distance:3, includeKeys:true);
493 expect(result.logs, orderedEquals([e1, e2, e3]));
494
495 result = logList.preceding(keyList, equals('a'), callsTo(startsWith('bar')),
496 distance:3);
497 expect(result.logs, orderedEquals([e1]));
498
499 result = logList.preceding(keyList, equals('a'), callsTo(startsWith('bar')),
500 distance:3, includeKeys:true);
501 expect(result.logs, orderedEquals([e1, e3]));
502
503 keyList.logs.clear();
504 keyList.add(e0);
505 keyList.add(e3);
506 keyList.add(e7);
507
508 result = logList.preceding(keyList);
509 expect(result.logs, orderedEquals([e2, e6]));
510
511 result = logList.following(keyList);
512 expect(result.logs, orderedEquals([e1, e4, e8]));
513
514 result = logList.preceding(keyList, includeKeys:true);
515 expect(result.logs, orderedEquals([e0, e2, e3, e6, e7]));
516
517 result = logList.following(keyList, includeKeys:true);
518 expect(result.logs, orderedEquals([e0, e1, e3, e4, e7, e8]));
519
520 keyList.logs.clear();
521 keyList.add(e3);
522 keyList.add(e7);
523 keyList.add(e10);
524
525 result = logList.preceding(keyList);
526 expect(result.logs, orderedEquals([e2, e6, e9]));
527
528 result = logList.following(keyList);
529 expect(result.logs, orderedEquals([e4, e8]));
530
531 result = logList.preceding(keyList, includeKeys:true);
532 expect(result.logs, orderedEquals([e2, e3, e6, e7, e9, e10]));
533
534 result = logList.following(keyList, includeKeys:true);
535 expect(result.logs, orderedEquals([e3, e4, e7, e8, e10]));
536
537 keyList.logs.clear();
538 keyList.add(e0);
539 keyList.add(e3);
540 keyList.add(e7);
541 keyList.add(e10);
542
543 result = logList.preceding(keyList);
544 expect(result.logs, orderedEquals([e2, e6, e9]));
545
546 result = logList.following(keyList);
547 expect(result.logs, orderedEquals([e1, e4, e8]));
548
549 result = logList.preceding(keyList, includeKeys:true);
550 expect(result.logs, orderedEquals([e0, e2, e3, e6, e7, e9, e10]));
551
552 result = logList.following(keyList, includeKeys:true);
553 expect(result.logs, orderedEquals([e0, e1, e3, e4, e7, e8, e10]));
554
555 keyList.logs.clear();
556 keyList.add(e0);
557 keyList.add(e3);
558 keyList.add(e7);
559
560 result = logList.preceding(keyList, distance:3);
561 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6]));
562
563 result = logList.following(keyList, distance:3);
564 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9, e10]));
565
566 result = logList.preceding(keyList, distance:3, includeKeys:true);
567 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6, e7]));
568
569 result = logList.following(keyList, distance:3, includeKeys:true);
570 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
571 e7, e8, e9, e10]));
572
573 keyList.logs.clear();
574 keyList.add(e3);
575 keyList.add(e7);
576 keyList.add(e10);
577
578 result = logList.preceding(keyList, distance:3);
579 expect(result.logs, orderedEquals([e0, e1, e2, e4, e5, e6, e8, e9]));
580
581 result = logList.following(keyList, distance:3);
582 expect(result.logs, orderedEquals([e4, e5, e6, e8, e9]));
583
584 result = logList.preceding(keyList, distance:3, includeKeys:true);
585 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
586 e7, e8, e9, e10]));
587
588 result = logList.following(keyList, distance:3, includeKeys:true);
589 expect(result.logs, orderedEquals([e3, e4, e5, e6, e7, e8, e9, e10]));
590
591 keyList.logs.clear();
592 keyList.add(e0);
593 keyList.add(e3);
594 keyList.add(e7);
595 keyList.add(e10);
596
597 result = logList.preceding(keyList, distance:3);
598 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9]));
599
600 result = logList.following(keyList, distance:3);
601 expect(result.logs, orderedEquals([e1, e2, e4, e5, e6, e8, e9]));
602
603 result = logList.preceding(keyList, distance:3, includeKeys:true);
604 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
605 e7, e8, e9, e10]));
606
607 result = logList.following(keyList, distance:3, includeKeys:true);
608 expect(result.logs, orderedEquals([e0, e1, e2, e3, e4, e5, e6,
609 e7, e8, e9, e10]));
610 });
611 }
612
Siggi Cherem (dart-lang) 2012/07/31 17:16:40 remove empty lines...
613
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698