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: packages/matcher/test/iterable_matchers_test.dart

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

Powered by Google App Engine
This is Rietveld 408576698