OLD | NEW |
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 /** | 5 /** |
6 * Expect is used for tests that do not want to make use of the | 6 * Expect is used for tests that do not want to make use of the |
7 * Dart unit test library - for example, the core language tests. | 7 * Dart unit test library - for example, the core language tests. |
8 * Third parties are discouraged from using this, and should use | 8 * Third parties are discouraged from using this, and should use |
9 * the expect() function in the unit test library instead for | 9 * the expect() function in the unit test library instead for |
10 * test assertions. | 10 * test assertions. |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 * every element of [actual] is also in [expected]. | 220 * every element of [actual] is also in [expected]. |
221 */ | 221 */ |
222 static void setEquals(Iterable expected, | 222 static void setEquals(Iterable expected, |
223 Iterable actual, | 223 Iterable actual, |
224 [String reason = null]) { | 224 [String reason = null]) { |
225 final missingSet = new Set.from(expected); | 225 final missingSet = new Set.from(expected); |
226 missingSet.removeAll(actual); | 226 missingSet.removeAll(actual); |
227 final extraSet = new Set.from(actual); | 227 final extraSet = new Set.from(actual); |
228 extraSet.removeAll(expected); | 228 extraSet.removeAll(expected); |
229 | 229 |
230 if (extraSet.isEmpty() && missingSet.isEmpty()) return; | 230 if (extraSet.isEmpty && missingSet.isEmpty) return; |
231 String msg = _getMessage(reason); | 231 String msg = _getMessage(reason); |
232 | 232 |
233 StringBuffer sb = new StringBuffer("Expect.setEquals($msg) fails"); | 233 StringBuffer sb = new StringBuffer("Expect.setEquals($msg) fails"); |
234 // Report any missing items. | 234 // Report any missing items. |
235 if (!missingSet.isEmpty()) { | 235 if (!missingSet.isEmpty) { |
236 sb.add('\nExpected collection does not contain: '); | 236 sb.add('\nExpected collection does not contain: '); |
237 } | 237 } |
238 | 238 |
239 for (final val in missingSet) { | 239 for (final val in missingSet) { |
240 sb.add('$val '); | 240 sb.add('$val '); |
241 } | 241 } |
242 | 242 |
243 // Report any extra items. | 243 // Report any extra items. |
244 if (!extraSet.isEmpty()) { | 244 if (!extraSet.isEmpty) { |
245 sb.add('\nExpected collection should not contain: '); | 245 sb.add('\nExpected collection should not contain: '); |
246 } | 246 } |
247 | 247 |
248 for (final val in extraSet) { | 248 for (final val in extraSet) { |
249 sb.add('$val '); | 249 sb.add('$val '); |
250 } | 250 } |
251 _fail(sb.toString()); | 251 _fail(sb.toString()); |
252 } | 252 } |
253 | 253 |
254 /** | 254 /** |
(...skipping 27 matching lines...) Expand all Loading... |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 typedef bool _CheckExceptionFn(exception); | 285 typedef bool _CheckExceptionFn(exception); |
286 | 286 |
287 class ExpectException implements Exception { | 287 class ExpectException implements Exception { |
288 ExpectException(this.message); | 288 ExpectException(this.message); |
289 String toString() => message; | 289 String toString() => message; |
290 String message; | 290 String message; |
291 } | 291 } |
OLD | NEW |