| Index: packages/matcher/test/core_matchers_test.dart
|
| diff --git a/packages/matcher/test/core_matchers_test.dart b/packages/matcher/test/core_matchers_test.dart
|
| index 32e30f0519f813d301e446ec29f7bcc9c11d706c..04cc111c1abfd099514ae4aac9baab032a831f59 100644
|
| --- a/packages/matcher/test/core_matchers_test.dart
|
| +++ b/packages/matcher/test/core_matchers_test.dart
|
| @@ -2,13 +2,16 @@
|
| // 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.core_matchers_test;
|
| -
|
| import 'package:matcher/matcher.dart';
|
| import 'package:test/test.dart' show test, group;
|
|
|
| import 'test_utils.dart';
|
|
|
| +class BadCustomMatcher extends CustomMatcher {
|
| + BadCustomMatcher() : super("feature", "description", {1: "a"});
|
| + featureValueOf(actual) => throw new Exception("bang");
|
| +}
|
| +
|
| void main() {
|
| test('isTrue', () {
|
| shouldPass(true, isTrue);
|
| @@ -63,34 +66,18 @@ void main() {
|
|
|
| shouldPass(set2, equals(set1));
|
| shouldPass(numbers, equals(set1));
|
| - shouldFail([
|
| - 1,
|
| - 2,
|
| - 3,
|
| - 4,
|
| - 5,
|
| - 6,
|
| - 7,
|
| - 8,
|
| - 9
|
| - ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
|
| - r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9\]"
|
| - r" Which: does not contain 10"));
|
| - shouldFail([
|
| - 1,
|
| - 2,
|
| - 3,
|
| - 4,
|
| - 5,
|
| - 6,
|
| - 7,
|
| - 8,
|
| - 9,
|
| - 10,
|
| - 11
|
| - ], equals(set1), matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
|
| - r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\]"
|
| - r" Which: larger than expected"));
|
| + shouldFail(
|
| + [1, 2, 3, 4, 5, 6, 7, 8, 9],
|
| + equals(set1),
|
| + matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
|
| + r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9\]"
|
| + r" Which: does not contain 10"));
|
| + shouldFail(
|
| + [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
|
| + equals(set1),
|
| + matches(r"Expected: .*:\[1, 2, 3, 4, 5, 6, 7, 8, 9, 10\]"
|
| + r" Actual: \[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11\]"
|
| + r" Which: larger than expected"));
|
| });
|
|
|
| test('anything', () {
|
| @@ -103,10 +90,12 @@ void main() {
|
|
|
| test('returnsNormally', () {
|
| shouldPass(doesNotThrow, returnsNormally);
|
| - shouldFail(doesThrow, returnsNormally, matches(r"Expected: return normally"
|
| - r" Actual: <Closure(: \(\) => dynamic "
|
| - r"from Function 'doesThrow': static\.)?>"
|
| - r" Which: threw 'X'"));
|
| + shouldFail(
|
| + doesThrow,
|
| + returnsNormally,
|
| + matches(r"Expected: return normally"
|
| + r" Actual: <Closure.*>"
|
| + r" Which: threw 'X'"));
|
| });
|
|
|
| test('hasLength', () {
|
| @@ -115,56 +104,107 @@ void main() {
|
| shouldPass(a, hasLength(0));
|
| shouldPass(b, hasLength(0));
|
| shouldPass('a', hasLength(1));
|
| - shouldFail(0, hasLength(0),
|
| + shouldFail(
|
| + 0,
|
| + hasLength(0),
|
| "Expected: an object with length of <0> "
|
| "Actual: <0> "
|
| "Which: has no length property");
|
|
|
| b.add(0);
|
| shouldPass(b, hasLength(1));
|
| - shouldFail(b, hasLength(2), "Expected: an object with length of <2> "
|
| + shouldFail(
|
| + b,
|
| + hasLength(2),
|
| + "Expected: an object with length of <2> "
|
| "Actual: [0] "
|
| "Which: has length of <1>");
|
|
|
| b.add(0);
|
| - shouldFail(b, hasLength(1), "Expected: an object with length of <1> "
|
| + shouldFail(
|
| + b,
|
| + hasLength(1),
|
| + "Expected: an object with length of <1> "
|
| "Actual: [0, 0] "
|
| "Which: has length of <2>");
|
| shouldPass(b, hasLength(2));
|
| });
|
|
|
| test('scalar type mismatch', () {
|
| - shouldFail('error', equals(5.1), "Expected: <5.1> "
|
| + shouldFail(
|
| + 'error',
|
| + equals(5.1),
|
| + "Expected: <5.1> "
|
| "Actual: 'error'");
|
| });
|
|
|
| test('nested type mismatch', () {
|
| - shouldFail(['error'], equals([5.1]), "Expected: [5.1] "
|
| + shouldFail(
|
| + ['error'],
|
| + equals([5.1]),
|
| + "Expected: [5.1] "
|
| "Actual: ['error'] "
|
| "Which: was 'error' instead of <5.1> at location [0]");
|
| });
|
|
|
| test('doubly-nested type mismatch', () {
|
| - shouldFail([['error']], equals([[5.1]]), "Expected: [[5.1]] "
|
| + shouldFail(
|
| + [
|
| + ['error']
|
| + ],
|
| + equals([
|
| + [5.1]
|
| + ]),
|
| + "Expected: [[5.1]] "
|
| "Actual: [['error']] "
|
| "Which: was 'error' instead of <5.1> at location [0][0]");
|
| });
|
|
|
| test('doubly nested inequality', () {
|
| - var actual1 = [['foo', 'bar'], ['foo'], 3, []];
|
| - var expected1 = [['foo', 'bar'], ['foo'], 4, []];
|
| + var actual1 = [
|
| + ['foo', 'bar'],
|
| + ['foo'],
|
| + 3,
|
| + []
|
| + ];
|
| + var expected1 = [
|
| + ['foo', 'bar'],
|
| + ['foo'],
|
| + 4,
|
| + []
|
| + ];
|
| var reason1 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
|
| "Actual: [['foo', 'bar'], ['foo'], 3, []] "
|
| "Which: was <3> instead of <4> at location [2]";
|
|
|
| - var actual2 = [['foo', 'barry'], ['foo'], 4, []];
|
| - var expected2 = [['foo', 'bar'], ['foo'], 4, []];
|
| + var actual2 = [
|
| + ['foo', 'barry'],
|
| + ['foo'],
|
| + 4,
|
| + []
|
| + ];
|
| + var expected2 = [
|
| + ['foo', 'bar'],
|
| + ['foo'],
|
| + 4,
|
| + []
|
| + ];
|
| var reason2 = "Expected: [['foo', 'bar'], ['foo'], 4, []] "
|
| "Actual: [['foo', 'barry'], ['foo'], 4, []] "
|
| "Which: was 'barry' instead of 'bar' at location [0][1]";
|
|
|
| - var actual3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}];
|
| - var expected3 = [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}];
|
| + var actual3 = [
|
| + ['foo', 'bar'],
|
| + ['foo'],
|
| + 4,
|
| + {'foo': 'bar'}
|
| + ];
|
| + var expected3 = [
|
| + ['foo', 'bar'],
|
| + ['foo'],
|
| + 4,
|
| + {'foo': 'barry'}
|
| + ];
|
| var reason3 = "Expected: [['foo', 'bar'], ['foo'], 4, {'foo': 'barry'}] "
|
| "Actual: [['foo', 'bar'], ['foo'], 4, {'foo': 'bar'}] "
|
| "Which: was 'bar' instead of 'barry' at location [3]['foo']";
|
| @@ -193,10 +233,25 @@ void main() {
|
| w.price = 10;
|
| shouldPass(w, new HasPrice(10));
|
| shouldPass(w, new HasPrice(greaterThan(0)));
|
| - shouldFail(w, new HasPrice(greaterThan(10)),
|
| + shouldFail(
|
| + w,
|
| + new HasPrice(greaterThan(10)),
|
| "Expected: Widget with a price that is a value greater than <10> "
|
| "Actual: <Instance of 'Widget'> "
|
| "Which: has price with value <10> which is not "
|
| "a value greater than <10>");
|
| });
|
| +
|
| + test("Custom Matcher Exception", () {
|
| + shouldFail(
|
| + "a",
|
| + new BadCustomMatcher(),
|
| + allOf([
|
| + contains("Expected: feature {1: 'a'} "),
|
| + contains("Actual: 'a' "),
|
| + contains("Which: threw 'Exception: bang' "),
|
| + contains("test/core_matchers_test.dart "),
|
| + contains("package:test ")
|
| + ]));
|
| + });
|
| }
|
|
|