Index: packages/matcher/test/iterable_matchers_test.dart |
diff --git a/packages/matcher/test/iterable_matchers_test.dart b/packages/matcher/test/iterable_matchers_test.dart |
index 54bc2c959b226c2e88a51cfb25d3a7aa14f50b90..604a1b6a8dc7794f827a57f2af2a5afb6782886c 100644 |
--- a/packages/matcher/test/iterable_matchers_test.dart |
+++ b/packages/matcher/test/iterable_matchers_test.dart |
@@ -2,10 +2,8 @@ |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library matcher.iterable_matchers_test; |
- |
import 'package:matcher/matcher.dart'; |
-import 'package:test/test.dart' show test, group; |
+import 'package:test/test.dart'; |
import 'test_utils.dart'; |
@@ -23,14 +21,19 @@ void main() { |
test('contains', () { |
var d = [1, 2]; |
shouldPass(d, contains(1)); |
- shouldFail(d, contains(0), "Expected: contains <0> " |
+ shouldFail( |
+ d, |
+ contains(0), |
+ "Expected: contains <0> " |
"Actual: [1, 2]"); |
}); |
test('equals with matcher element', () { |
var d = ['foo', 'bar']; |
shouldPass(d, equals(['foo', startsWith('ba')])); |
- shouldFail(d, equals(['foo', endsWith('ba')]), |
+ shouldFail( |
+ d, |
+ equals(['foo', endsWith('ba')]), |
"Expected: ['foo', <a string ending with 'ba'>] " |
"Actual: ['foo', 'bar'] " |
"Which: does not match a string ending with 'ba' at location [1]"); |
@@ -45,36 +48,53 @@ void main() { |
test('everyElement', () { |
var d = [1, 2]; |
var e = [1, 1, 1]; |
- shouldFail(d, everyElement(1), "Expected: every element(<1>) " |
+ shouldFail( |
+ d, |
+ everyElement(1), |
+ "Expected: every element(<1>) " |
"Actual: [1, 2] " |
"Which: has value <2> which doesn't match <1> at index 1"); |
shouldPass(e, everyElement(1)); |
}); |
test('nested everyElement', () { |
- var d = [['foo', 'bar'], ['foo'], []]; |
- var e = [['foo', 'bar'], ['foo'], 3, []]; |
+ var d = [ |
+ ['foo', 'bar'], |
+ ['foo'], |
+ [] |
+ ]; |
+ var e = [ |
+ ['foo', 'bar'], |
+ ['foo'], |
+ 3, |
+ [] |
+ ]; |
shouldPass(d, everyElement(anyOf(isEmpty, contains('foo')))); |
- shouldFail(d, everyElement(everyElement(equals('foo'))), |
+ shouldFail( |
+ d, |
+ everyElement(everyElement(equals('foo'))), |
"Expected: every element(every element('foo')) " |
"Actual: [['foo', 'bar'], ['foo'], []] " |
"Which: has value ['foo', 'bar'] which has value 'bar' " |
"which is different. Expected: foo Actual: bar ^ " |
"Differ at offset 0 at index 1 at index 0"); |
- shouldFail(d, |
+ shouldFail( |
+ d, |
everyElement(allOf(hasLength(greaterThan(0)), contains('foo'))), |
"Expected: every element((an object with length of a value " |
"greater than <0> and contains 'foo')) " |
"Actual: [['foo', 'bar'], ['foo'], []] " |
"Which: has value [] which has length of <0> at index 2"); |
- shouldFail(d, |
+ shouldFail( |
+ d, |
everyElement(allOf(contains('foo'), hasLength(greaterThan(0)))), |
"Expected: every element((contains 'foo' and " |
"an object with length of a value greater than <0>)) " |
"Actual: [['foo', 'bar'], ['foo'], []] " |
"Which: has value [] which doesn't match (contains 'foo' and " |
"an object with length of a value greater than <0>) at index 2"); |
- shouldFail(e, |
+ shouldFail( |
+ e, |
everyElement(allOf(contains('foo'), hasLength(greaterThan(0)))), |
"Expected: every element((contains 'foo' and an object with " |
"length of a value greater than <0>)) " |
@@ -95,7 +115,10 @@ void main() { |
shouldPass([null], orderedEquals([null])); |
var d = [1, 2]; |
shouldPass(d, orderedEquals([1, 2])); |
- shouldFail(d, orderedEquals([2, 1]), "Expected: equals [2, 1] ordered " |
+ shouldFail( |
+ d, |
+ orderedEquals([2, 1]), |
+ "Expected: equals [2, 1] ordered " |
"Actual: [1, 2] " |
"Which: was <1> instead of <2> at location [0]"); |
}); |
@@ -103,14 +126,22 @@ void main() { |
test('unorderedEquals', () { |
var d = [1, 2]; |
shouldPass(d, unorderedEquals([2, 1])); |
- shouldFail(d, unorderedEquals([1]), "Expected: equals [1] unordered " |
+ shouldFail( |
+ d, |
+ unorderedEquals([1]), |
+ "Expected: equals [1] unordered " |
"Actual: [1, 2] " |
"Which: has too many elements (2 > 1)"); |
- shouldFail(d, unorderedEquals([3, 2, 1]), |
+ shouldFail( |
+ d, |
+ unorderedEquals([3, 2, 1]), |
"Expected: equals [3, 2, 1] unordered " |
"Actual: [1, 2] " |
"Which: has too few elements (2 < 3)"); |
- shouldFail(d, unorderedEquals([3, 1]), "Expected: equals [3, 1] unordered " |
+ shouldFail( |
+ d, |
+ unorderedEquals([3, 1]), |
+ "Expected: equals [3, 1] unordered " |
"Actual: [1, 2] " |
"Which: has no match for <3> at index 0"); |
}); |
@@ -119,44 +150,94 @@ void main() { |
var d = [1, 2]; |
shouldPass(d, unorderedMatches([2, 1])); |
shouldPass(d, unorderedMatches([greaterThan(1), greaterThan(0)])); |
- shouldFail(d, unorderedMatches([greaterThan(0)]), |
+ shouldFail( |
+ d, |
+ unorderedMatches([greaterThan(0)]), |
"Expected: matches [a value greater than <0>] unordered " |
"Actual: [1, 2] " |
"Which: has too many elements (2 > 1)"); |
- shouldFail(d, unorderedMatches([3, 2, 1]), |
+ shouldFail( |
+ d, |
+ unorderedMatches([3, 2, 1]), |
"Expected: matches [<3>, <2>, <1>] unordered " |
"Actual: [1, 2] " |
"Which: has too few elements (2 < 3)"); |
- shouldFail(d, unorderedMatches([3, 1]), |
+ shouldFail( |
+ d, |
+ unorderedMatches([3, 1]), |
"Expected: matches [<3>, <1>] unordered " |
"Actual: [1, 2] " |
"Which: has no match for <3> at index 0"); |
- shouldFail(d, unorderedMatches([greaterThan(3), greaterThan(0)]), |
+ shouldFail( |
+ d, |
+ unorderedMatches([greaterThan(3), greaterThan(0)]), |
"Expected: matches [a value greater than <3>, a value greater than " |
"<0>] unordered " |
"Actual: [1, 2] " |
"Which: has no match for a value greater than <3> at index 0"); |
}); |
+ test('containsAllInOrder', () { |
+ var d = [0, 1, 0, 2]; |
+ shouldPass(d, containsAllInOrder([1, 2])); |
+ shouldPass(d, containsAllInOrder([greaterThan(0), greaterThan(1)])); |
+ shouldFail( |
+ d, |
+ containsAllInOrder([2, 1]), |
+ "Expected: contains in order([2, 1]) " |
+ "Actual: [0, 1, 0, 2] " |
+ "Which: did not find a value matching <1> following expected prior " |
+ "values"); |
+ shouldFail( |
+ d, |
+ containsAllInOrder([greaterThan(1), greaterThan(0)]), |
+ "Expected: contains in order([<a value greater than <1>>, " |
+ "<a value greater than <0>>]) " |
+ "Actual: [0, 1, 0, 2] " |
+ "Which: did not find a value matching a value greater than <0> " |
+ "following expected prior values"); |
+ shouldFail( |
+ d, |
+ containsAllInOrder([1, 2, 3]), |
+ "Expected: contains in order([1, 2, 3]) " |
+ "Actual: [0, 1, 0, 2] " |
+ "Which: did not find a value matching <3> following expected prior " |
+ "values"); |
+ shouldFail( |
+ 1, |
+ containsAllInOrder([1]), |
+ "Expected: contains in order([1]) " |
+ "Actual: <1> " |
+ "Which: not an iterable"); |
+ }); |
+ |
test('pairwise compare', () { |
var c = [1, 2]; |
var d = [1, 2, 3]; |
var e = [1, 4, 9]; |
- shouldFail('x', pairwiseCompare(e, (e, a) => a <= e, "less than or equal"), |
+ shouldFail( |
+ 'x', |
+ pairwiseCompare(e, (e, a) => a <= e, "less than or equal"), |
"Expected: pairwise less than or equal [1, 4, 9] " |
"Actual: 'x' " |
"Which: is not an Iterable"); |
- shouldFail(c, pairwiseCompare(e, (e, a) => a <= e, "less than or equal"), |
+ shouldFail( |
+ c, |
+ pairwiseCompare(e, (e, a) => a <= e, "less than or equal"), |
"Expected: pairwise less than or equal [1, 4, 9] " |
"Actual: [1, 2] " |
"Which: has length 2 instead of 3"); |
shouldPass(d, pairwiseCompare(e, (e, a) => a <= e, "less than or equal")); |
- shouldFail(d, pairwiseCompare(e, (e, a) => a < e, "less than"), |
+ shouldFail( |
+ d, |
+ pairwiseCompare(e, (e, a) => a < e, "less than"), |
"Expected: pairwise less than [1, 4, 9] " |
"Actual: [1, 2, 3] " |
"Which: has <1> which is not less than <1> at index 0"); |
shouldPass(d, pairwiseCompare(e, (e, a) => a * a == e, "square root of")); |
- shouldFail(d, pairwiseCompare(e, (e, a) => a + a == e, "double"), |
+ shouldFail( |
+ d, |
+ pairwiseCompare(e, (e, a) => a + a == e, "double"), |
"Expected: pairwise double [1, 4, 9] " |
"Actual: [1, 2, 3] " |
"Which: has <1> which is not double <1> at index 0"); |
@@ -166,7 +247,10 @@ void main() { |
var d = new SimpleIterable(0); |
var e = new SimpleIterable(1); |
shouldPass(d, isEmpty); |
- shouldFail(e, isEmpty, "Expected: empty " |
+ shouldFail( |
+ e, |
+ isEmpty, |
+ "Expected: empty " |
"Actual: SimpleIterable:[1]"); |
}); |
@@ -174,14 +258,20 @@ void main() { |
var d = new SimpleIterable(0); |
var e = new SimpleIterable(1); |
shouldPass(e, isNotEmpty); |
- shouldFail(d, isNotEmpty, "Expected: non-empty " |
+ shouldFail( |
+ d, |
+ isNotEmpty, |
+ "Expected: non-empty " |
"Actual: SimpleIterable:[]"); |
}); |
test('contains', () { |
var d = new SimpleIterable(3); |
shouldPass(d, contains(2)); |
- shouldFail(d, contains(5), "Expected: contains <5> " |
+ shouldFail( |
+ d, |
+ contains(5), |
+ "Expected: contains <5> " |
"Actual: SimpleIterable:[3, 2, 1]"); |
}); |
} |