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

Side by Side Diff: pkg/unittest/lib/src/iterable_matchers.dart

Issue 18442002: Add missing newline after Actual value in fail message. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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
« no previous file with comments | « pkg/unittest/lib/src/interfaces.dart ('k') | pkg/unittest/lib/src/map_matchers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of matcher; 5 part of matcher;
6 6
7 /** 7 /**
8 * Returns a matcher which matches [Iterable]s in which all elements 8 * Returns a matcher which matches [Iterable]s in which all elements
9 * match the given [matcher]. 9 * match the given [matcher].
10 */ 10 */
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 /** 79 /**
80 * Returns a matcher which matches [Iterable]s that have the same 80 * Returns a matcher which matches [Iterable]s that have the same
81 * length and the same elements as [expected], and in the same order. 81 * length and the same elements as [expected], and in the same order.
82 * This is equivalent to equals but does not recurse. 82 * This is equivalent to equals but does not recurse.
83 */ 83 */
84 84
85 Matcher orderedEquals(Iterable expected) => new _OrderedEquals(expected); 85 Matcher orderedEquals(Iterable expected) => new _OrderedEquals(expected);
86 86
87 class _OrderedEquals extends BaseMatcher { 87 class _OrderedEquals extends Matcher {
88 final Iterable _expected; 88 final Iterable _expected;
89 Matcher _matcher; 89 Matcher _matcher;
90 90
91 _OrderedEquals(this._expected) { 91 _OrderedEquals(this._expected) {
92 _matcher = equals(_expected, 1); 92 _matcher = equals(_expected, 1);
93 } 93 }
94 94
95 bool matches(item, Map matchState) => 95 bool matches(item, Map matchState) =>
96 (item is Iterable) && _matcher.matches(item, matchState); 96 (item is Iterable) && _matcher.matches(item, matchState);
97 97
(...skipping 12 matching lines...) Expand all
110 } 110 }
111 /** 111 /**
112 * Returns a matcher which matches [Iterable]s that have the same 112 * Returns a matcher which matches [Iterable]s that have the same
113 * length and the same elements as [expected], but not necessarily in 113 * length and the same elements as [expected], but not necessarily in
114 * the same order. Note that this is O(n^2) so should only be used on 114 * the same order. Note that this is O(n^2) so should only be used on
115 * small objects. 115 * small objects.
116 */ 116 */
117 Matcher unorderedEquals(Iterable expected) => 117 Matcher unorderedEquals(Iterable expected) =>
118 new _UnorderedEquals(expected); 118 new _UnorderedEquals(expected);
119 119
120 class _UnorderedEquals extends BaseMatcher { 120 class _UnorderedEquals extends Matcher {
121 Iterable _expected; 121 Iterable _expected;
122 122
123 _UnorderedEquals(Iterable this._expected); 123 _UnorderedEquals(Iterable this._expected);
124 124
125 String _test(item) { 125 String _test(item) {
126 if (item is !Iterable) { 126 if (item is !Iterable) {
127 return 'not iterable'; 127 return 'not iterable';
128 } 128 }
129 // Check the lengths are the same. 129 // Check the lengths are the same.
130 var expectedLength = _expected.length; 130 var expectedLength = _expected.length;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 170
171 Description describeMismatch(item, Description mismatchDescription, 171 Description describeMismatch(item, Description mismatchDescription,
172 Map matchState, bool verbose) => 172 Map matchState, bool verbose) =>
173 mismatchDescription.add(_test(item)); 173 mismatchDescription.add(_test(item));
174 } 174 }
175 175
176 /** 176 /**
177 * Iterable matchers match against [Iterable]s. We add this intermediate 177 * Iterable matchers match against [Iterable]s. We add this intermediate
178 * class to give better mismatch error messages than the base Matcher class. 178 * class to give better mismatch error messages than the base Matcher class.
179 */ 179 */
180 abstract class _IterableMatcher extends BaseMatcher { 180 abstract class _IterableMatcher extends Matcher {
181 const _IterableMatcher(); 181 const _IterableMatcher();
182 Description describeMismatch(item, Description mismatchDescription, 182 Description describeMismatch(item, Description mismatchDescription,
183 Map matchState, bool verbose) { 183 Map matchState, bool verbose) {
184 if (item is! Iterable) { 184 if (item is! Iterable) {
185 return mismatchDescription. 185 return mismatchDescription.
186 addDescriptionOf(item). 186 addDescriptionOf(item).
187 add(' not an Iterable'); 187 add(' not an Iterable');
188 } else { 188 } else {
189 return super.describeMismatch(item, mismatchDescription, matchState, 189 return super.describeMismatch(item, mismatchDescription, matchState,
190 verbose); 190 verbose);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 return mismatchDescription. 240 return mismatchDescription.
241 add('has '). 241 add('has ').
242 addDescriptionOf(matchState["actual"]). 242 addDescriptionOf(matchState["actual"]).
243 add(' which is not $_description '). 243 add(' which is not $_description ').
244 addDescriptionOf(matchState["expected"]). 244 addDescriptionOf(matchState["expected"]).
245 add(' at index ${matchState["index"]}'); 245 add(' at index ${matchState["index"]}');
246 } 246 }
247 } 247 }
248 } 248 }
249 249
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/interfaces.dart ('k') | pkg/unittest/lib/src/map_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698