Skip to content

Commit df3d483

Browse files
committed
0.5.0 added shouldContainAllInOrder
1 parent 003f2d9 commit df3d483

File tree

2 files changed

+100
-0
lines changed

2 files changed

+100
-0
lines changed

lib/src/iterable/iterable_assertions.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ extension IterableAssertions<T> on Iterable<T> {
2727
void shouldContainAll(Iterable<T> expected) {
2828
expect(this, containsAll(expected));
2929
}
30+
31+
/// Asserts that [Iterable] contains an element matching every value in
32+
/// [expected] in the same order, but may contain additional values
33+
/// interleaved throughout.
34+
void shouldContainAllInOrder(Iterable<T> expected) {
35+
expect(this, containsAllInOrder(expected));
36+
}
3037
}
3138

3239
extension IterableStringAssertions on Iterable<String> {

test/src/iterable/iterable_assertions_test.dart

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,37 @@ void main() {
188188
);
189189
});
190190
});
191+
192+
group('should contain all in order', () {
193+
test('should return normally when contains all in order', () {
194+
expect(
195+
() => capitals.shouldContainAllInOrder(['Berlin']),
196+
returnsNormally,
197+
);
198+
expect(
199+
() => capitals.shouldContainAllInOrder(['Berlin', 'Warsaw']),
200+
returnsNormally,
201+
);
202+
});
203+
204+
test('should fail when contains all not in order', () {
205+
expect(
206+
() => capitals.shouldContainAllInOrder(['Warsaw', 'Berlin']),
207+
failsTest,
208+
);
209+
});
210+
211+
test('should fail when not contain all', () {
212+
expect(
213+
() => capitals.shouldContainAllInOrder(['Barcelona']),
214+
failsTest,
215+
);
216+
expect(
217+
() => capitals.shouldContainAllInOrder(['Berlin, Barcelona']),
218+
failsTest,
219+
);
220+
});
221+
});
191222
});
192223

193224
group('numbers', () {
@@ -279,6 +310,37 @@ void main() {
279310
);
280311
});
281312
});
313+
314+
group('should contain all in order', () {
315+
test('should return normally when contains all in order', () {
316+
expect(
317+
() => primes.shouldContainAllInOrder([2]),
318+
returnsNormally,
319+
);
320+
expect(
321+
() => primes.shouldContainAllInOrder([2, 3]),
322+
returnsNormally,
323+
);
324+
});
325+
326+
test('should fail when contains all not in order', () {
327+
expect(
328+
() => primes.shouldContainAllInOrder([5, 2, 7]),
329+
failsTest,
330+
);
331+
});
332+
333+
test('should fail when not contain all', () {
334+
expect(
335+
() => primes.shouldContainAllInOrder([1]),
336+
failsTest,
337+
);
338+
expect(
339+
() => primes.shouldContainAllInOrder([3, 2, 1]),
340+
failsTest,
341+
);
342+
});
343+
});
282344
});
283345

284346
group('objects', () {
@@ -386,5 +448,36 @@ void main() {
386448
);
387449
});
388450
});
451+
452+
group('should contain all', () {
453+
test('should return normally when contains all in order', () {
454+
expect(
455+
() => [alice, bob].shouldContainAllInOrder([alice]),
456+
returnsNormally,
457+
);
458+
expect(
459+
() => [alice, bob].shouldContainAllInOrder([alice, bob]),
460+
returnsNormally,
461+
);
462+
});
463+
464+
test('should fail when contains all not in order', () {
465+
expect(
466+
() => [alice, bob].shouldContainAllInOrder([bob, alice]),
467+
failsTest,
468+
);
469+
});
470+
471+
test('should fail when not contain all', () {
472+
expect(
473+
() => [alice, bob].shouldContainAllInOrder([jimmy]),
474+
failsTest,
475+
);
476+
expect(
477+
() => [alice, bob].shouldContainAllInOrder([alice, bob, jimmy]),
478+
failsTest,
479+
);
480+
});
481+
});
389482
});
390483
}

0 commit comments

Comments
 (0)