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

Side by Side Diff: test/iterable_matchers_test.dart

Issue 1135653004: pkg/(unit)test: include a copy of old matcher (Closed) Base URL: https://github.com/dart-lang/test.git@stable
Patch Set: another nit Created 5 years, 7 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
« no previous file with comments | « test/future_matchers_test.dart ('k') | test/matchers_minified_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 unittest.matcher.iterable_matchers_test;
6
7 import 'package:unittest/unittest.dart';
8
9 import 'test_utils.dart';
10
11 void main() {
12 initUtils();
13
14 test('isEmpty', () {
15 shouldPass([], isEmpty);
16 shouldFail([1], isEmpty, "Expected: empty Actual: [1]");
17 });
18
19 test('isNotEmpty', () {
20 shouldFail([], isNotEmpty, "Expected: non-empty Actual: []");
21 shouldPass([1], isNotEmpty);
22 });
23
24 test('contains', () {
25 var d = [1, 2];
26 shouldPass(d, contains(1));
27 shouldFail(d, contains(0), "Expected: contains <0> "
28 "Actual: [1, 2]");
29 });
30
31 test('equals with matcher element', () {
32 var d = ['foo', 'bar'];
33 shouldPass(d, equals(['foo', startsWith('ba')]));
34 shouldFail(d, equals(['foo', endsWith('ba')]),
35 "Expected: ['foo', <a string ending with 'ba'>] "
36 "Actual: ['foo', 'bar'] "
37 "Which: does not match a string ending with 'ba' at location [1]");
38 });
39
40 test('isIn', () {
41 var d = [1, 2];
42 shouldPass(1, isIn(d));
43 shouldFail(0, isIn(d), "Expected: is in [1, 2] Actual: <0>");
44 });
45
46 test('everyElement', () {
47 var d = [1, 2];
48 var e = [1, 1, 1];
49 shouldFail(d, everyElement(1), "Expected: every element(<1>) "
50 "Actual: [1, 2] "
51 "Which: has value <2> which doesn't match <1> at index 1");
52 shouldPass(e, everyElement(1));
53 });
54
55 test('nested everyElement', () {
56 var d = [['foo', 'bar'], ['foo'], []];
57 var e = [['foo', 'bar'], ['foo'], 3, []];
58 shouldPass(d, everyElement(anyOf(isEmpty, contains('foo'))));
59 shouldFail(d, everyElement(everyElement(equals('foo'))),
60 "Expected: every element(every element('foo')) "
61 "Actual: [['foo', 'bar'], ['foo'], []] "
62 "Which: has value ['foo', 'bar'] which has value 'bar' "
63 "which is different. Expected: foo Actual: bar ^ "
64 "Differ at offset 0 at index 1 at index 0");
65 shouldFail(d,
66 everyElement(allOf(hasLength(greaterThan(0)), contains('foo'))),
67 "Expected: every element((an object with length of a value "
68 "greater than <0> and contains 'foo')) "
69 "Actual: [['foo', 'bar'], ['foo'], []] "
70 "Which: has value [] which has length of <0> at index 2");
71 shouldFail(d,
72 everyElement(allOf(contains('foo'), hasLength(greaterThan(0)))),
73 "Expected: every element((contains 'foo' and "
74 "an object with length of a value greater than <0>)) "
75 "Actual: [['foo', 'bar'], ['foo'], []] "
76 "Which: has value [] which doesn't match (contains 'foo' and "
77 "an object with length of a value greater than <0>) at index 2");
78 shouldFail(e,
79 everyElement(allOf(contains('foo'), hasLength(greaterThan(0)))),
80 "Expected: every element((contains 'foo' and an object with "
81 "length of a value greater than <0>)) "
82 "Actual: [['foo', 'bar'], ['foo'], 3, []] "
83 "Which: has value <3> which is not a string, map or iterable "
84 "at index 2");
85 });
86
87 test('anyElement', () {
88 var d = [1, 2];
89 var e = [1, 1, 1];
90 shouldPass(d, anyElement(2));
91 shouldFail(
92 e, anyElement(2), "Expected: some element <2> Actual: [1, 1, 1]");
93 });
94
95 test('orderedEquals', () {
96 shouldPass([null], orderedEquals([null]));
97 var d = [1, 2];
98 shouldPass(d, orderedEquals([1, 2]));
99 shouldFail(d, orderedEquals([2, 1]), "Expected: equals [2, 1] ordered "
100 "Actual: [1, 2] "
101 "Which: was <1> instead of <2> at location [0]");
102 });
103
104 test('unorderedEquals', () {
105 var d = [1, 2];
106 shouldPass(d, unorderedEquals([2, 1]));
107 shouldFail(d, unorderedEquals([1]), "Expected: equals [1] unordered "
108 "Actual: [1, 2] "
109 "Which: has too many elements (2 > 1)");
110 shouldFail(d, unorderedEquals([3, 2, 1]),
111 "Expected: equals [3, 2, 1] unordered "
112 "Actual: [1, 2] "
113 "Which: has too few elements (2 < 3)");
114 shouldFail(d, unorderedEquals([3, 1]), "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, "less than or equal"),
147 "Expected: pairwise less than or equal [1, 4, 9] "
148 "Actual: 'x' "
149 "Which: is not an Iterable");
150 shouldFail(c, pairwiseCompare(e, (e, a) => a <= e, "less than or equal"),
151 "Expected: pairwise less than or equal [1, 4, 9] "
152 "Actual: [1, 2] "
153 "Which: has length 2 instead of 3");
154 shouldPass(d, pairwiseCompare(e, (e, a) => a <= e, "less than or equal"));
155 shouldFail(d, pairwiseCompare(e, (e, a) => a < e, "less than"),
156 "Expected: pairwise less than [1, 4, 9] "
157 "Actual: [1, 2, 3] "
158 "Which: has <1> which is not less than <1> at index 0");
159 shouldPass(d, pairwiseCompare(e, (e, a) => a * a == e, "square root of"));
160 shouldFail(d, pairwiseCompare(e, (e, a) => a + a == e, "double"),
161 "Expected: pairwise double [1, 4, 9] "
162 "Actual: [1, 2, 3] "
163 "Which: has <1> which is not double <1> at index 0");
164 });
165 }
OLDNEW
« no previous file with comments | « test/future_matchers_test.dart ('k') | test/matchers_minified_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698