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

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

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

Powered by Google App Engine
This is Rietveld 408576698