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

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

Issue 306283002: pkg/matcher: cleanup, updates, deprecations, fixes (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 matcher.iterable_matchers_test;
6
7 import 'package:matcher/matcher.dart';
8 import 'package:unittest/unittest.dart' show test, group;
9
10 import 'test_utils.dart';
11
12 void main() {
13 initUtils();
14
15 test('isEmpty', () {
16 shouldPass([], isEmpty);
17 shouldFail([1], isEmpty, "Expected: empty Actual: [1]");
18 });
19
20 test('contains', () {
21 var d = [1, 2];
22 shouldPass(d, contains(1));
23 shouldFail(d, contains(0), "Expected: contains <0> "
24 "Actual: [1, 2]");
25 });
26
27 test('equals with matcher element', () {
28 var d = ['foo', 'bar'];
29 shouldPass(d, equals(['foo', startsWith('ba')]));
30 shouldFail(d, equals(['foo', endsWith('ba')]),
31 "Expected: ['foo', <a string ending with 'ba'>] "
32 "Actual: ['foo', 'bar'] "
33 "Which: does not match a string ending with 'ba' at location [1]");
34 });
35
36 test('isIn', () {
37 var d = [1, 2];
38 shouldPass(1, isIn(d));
39 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>");
40 });
41
42 test('everyElement', () {
43 var d = [1, 2];
44 var e = [1, 1, 1];
45 shouldFail(d, everyElement(1),
46 "Expected: every element(<1>) "
47 "Actual: [1, 2] "
48 "Which: has value <2> which doesn't match <1> at index 1");
49 shouldPass(e, everyElement(1));
50 });
51
52 test('nested everyElement', () {
53 var d = [['foo', 'bar'], ['foo'], []];
54 var e = [['foo', 'bar'], ['foo'], 3, []];
55 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo'))));
56 shouldFail(d, everyElement(everyElement(equals('foo'))),
57 "Expected: every element(every element('foo')) "
58 "Actual: [['foo', 'bar'], ['foo'], []] "
59 "Which: has value ['foo', 'bar'] which has value 'bar' "
60 "which is different. Expected: foo Actual: bar ^ "
61 "Differ at offset 0 at index 1 at index 0");
62 shouldFail(d, everyElement(allOf(hasLength(greaterThan(0)),
63 contains('foo'))),
64 "Expected: every element((an object with length of a value "
65 "greater than <0> and contains 'foo')) "
66 "Actual: [['foo', 'bar'], ['foo'], []] "
67 "Which: has value [] which has length of <0> at index 2");
68 shouldFail(d, everyElement(allOf(contains('foo'),
69 hasLength(greaterThan(0)))),
70 "Expected: every element((contains 'foo' and "
71 "an object with length of a value greater than <0>)) "
72 "Actual: [['foo', 'bar'], ['foo'], []] "
73 "Which: has value [] which doesn't match (contains 'foo' and "
74 "an object with length of a value greater than <0>) at index 2");
75 shouldFail(e, everyElement(allOf(contains('foo'),
76 hasLength(greaterThan(0)))),
77 "Expected: every element((contains 'foo' and an object with "
78 "length of a value greater than <0>)) "
79 "Actual: [['foo', 'bar'], ['foo'], 3, []] "
80 "Which: has value <3> which is not a string, map or iterable "
81 "at index 2");
82 });
83
84 test('anyElement', () {
85 var d = [1, 2];
86 var e = [1, 1, 1];
87 shouldPass(d, anyElement(2));
88 shouldFail(e, anyElement(2),
89 "Expected: some element <2> Actual: [1, 1, 1]");
90 });
91
92 test('orderedEquals', () {
93 shouldPass([null], orderedEquals([null]));
94 var d = [1, 2];
95 shouldPass(d, orderedEquals([1, 2]));
96 shouldFail(d, orderedEquals([2, 1]),
97 "Expected: equals [2, 1] ordered "
98 "Actual: [1, 2] "
99 "Which: was <1> instead of <2> at location [0]");
100 });
101
102 test('unorderedEquals', () {
103 var d = [1, 2];
104 shouldPass(d, unorderedEquals([2, 1]));
105 shouldFail(d, unorderedEquals([1]),
106 "Expected: equals [1] unordered "
107 "Actual: [1, 2] "
108 "Which: has too many elements (2 > 1)");
109 shouldFail(d, unorderedEquals([3, 2, 1]),
110 "Expected: equals [3, 2, 1] unordered "
111 "Actual: [1, 2] "
112 "Which: has too few elements (2 < 3)");
113 shouldFail(d, unorderedEquals([3, 1]),
114 "Expected: equals [3, 1] unordered "
115 "Actual: [1, 2] "
116 "Which: has no match for <3> at index 0");
117 });
118
119 test('unorderedMatchess', () {
120 var d = [1, 2];
121 shouldPass(d, unorderedMatches([2, 1]));
122 shouldPass(d, unorderedMatches([greaterThan(1), greaterThan(0)]));
123 shouldFail(d, unorderedMatches([greaterThan(0)]),
124 "Expected: matches [a value greater than <0>] unordered "
125 "Actual: [1, 2] "
126 "Which: has too many elements (2 > 1)");
127 shouldFail(d, unorderedMatches([3, 2, 1]),
128 "Expected: matches [<3>, <2>, <1>] unordered "
129 "Actual: [1, 2] "
130 "Which: has too few elements (2 < 3)");
131 shouldFail(d, unorderedMatches([3, 1]),
132 "Expected: matches [<3>, <1>] unordered "
133 "Actual: [1, 2] "
134 "Which: has no match for <3> at index 0");
135 shouldFail(d, unorderedMatches([greaterThan(3), greaterThan(0)]),
136 "Expected: matches [a value greater than <3>, a value greater than "
137 "<0>] unordered "
138 "Actual: [1, 2] "
139 "Which: has no match for a value greater than <3> at index 0");
140 });
141
142 test('pairwise compare', () {
143 var c = [1, 2];
144 var d = [1, 2, 3];
145 var e = [1, 4, 9];
146 shouldFail('x', pairwiseCompare(e, (e,a) => a <= e,
147 "less than or equal"),
148 "Expected: pairwise less than or equal [1, 4, 9] "
149 "Actual: 'x' "
150 "Which: is not an Iterable");
151 shouldFail(c, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"),
152 "Expected: pairwise less than or equal [1, 4, 9] "
153 "Actual: [1, 2] "
154 "Which: has length 2 instead of 3");
155 shouldPass(d, pairwiseCompare(e, (e,a) => a <= e, "less than or equal"));
156 shouldFail(d, pairwiseCompare(e, (e,a) => a < e, "less than"),
157 "Expected: pairwise less than [1, 4, 9] "
158 "Actual: [1, 2, 3] "
159 "Which: has <1> which is not less than <1> at index 0");
160 shouldPass(d, pairwiseCompare(e, (e,a) => a * a == e, "square root of"));
161 shouldFail(d, pairwiseCompare(e, (e,a) => a + a == e, "double"),
162 "Expected: pairwise double [1, 4, 9] "
163 "Actual: [1, 2, 3] "
164 "Which: has <1> which is not double <1> at index 0");
165 });
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698