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 part of unittest; | 5 part of matcher; |
6 | 6 |
7 /** | 7 /** |
8 * Returns a matcher that matches empty strings, maps or collections. | 8 * Returns a matcher that matches empty strings, maps or collections. |
9 */ | 9 */ |
10 const Matcher isEmpty = const _Empty(); | 10 const Matcher isEmpty = const _Empty(); |
11 | 11 |
12 class _Empty extends BaseMatcher { | 12 class _Empty extends BaseMatcher { |
13 const _Empty(); | 13 const _Empty(); |
14 bool matches(item, MatchState matchState) { | 14 bool matches(item, MatchState matchState) { |
15 if (item is Map || item is Collection) { | 15 if (item is Map || item is Collection) { |
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 class Throws extends BaseMatcher { | 277 class Throws extends BaseMatcher { |
278 final Matcher _matcher; | 278 final Matcher _matcher; |
279 | 279 |
280 const Throws([Matcher matcher]) : | 280 const Throws([Matcher matcher]) : |
281 this._matcher = matcher; | 281 this._matcher = matcher; |
282 | 282 |
283 bool matches(item, MatchState matchState) { | 283 bool matches(item, MatchState matchState) { |
284 if (item is Future) { | 284 if (item is Future) { |
285 // Queue up an asynchronous expectation that validates when the future | 285 // Queue up an asynchronous expectation that validates when the future |
286 // completes. | 286 // completes. |
287 item.onComplete(expectAsync1((future) { | 287 item.onComplete(_wrapAsync((future) { |
288 if (future.hasValue) { | 288 if (future.hasValue) { |
289 expect(false, isTrue, reason: | 289 expect(false, isTrue, reason: |
290 "Expected future to fail, but succeeded with '${future.value}'."); | 290 "Expected future to fail, but succeeded with '${future.value}'."); |
291 } else if (_matcher != null) { | 291 } else if (_matcher != null) { |
292 var reason; | 292 var reason; |
293 if (future.stackTrace != null) { | 293 if (future.stackTrace != null) { |
294 var stackTrace = future.stackTrace.toString(); | 294 var stackTrace = future.stackTrace.toString(); |
295 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; | 295 stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}"; |
296 reason = "Actual exception trace:\n$stackTrace"; | 296 reason = "Actual exception trace:\n$stackTrace"; |
297 } | 297 } |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
689 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); | 689 description.add(_featureDescription).add(' ').addDescriptionOf(_matcher); |
690 | 690 |
691 Description describeMismatch(item, Description mismatchDescription, | 691 Description describeMismatch(item, Description mismatchDescription, |
692 MatchState matchState, bool verbose) { | 692 MatchState matchState, bool verbose) { |
693 mismatchDescription.add(_featureName).add(' '); | 693 mismatchDescription.add(_featureName).add(' '); |
694 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, | 694 _matcher.describeMismatch(matchState.state['feature'], mismatchDescription, |
695 matchState.state['innerState'], verbose); | 695 matchState.state['innerState'], verbose); |
696 return mismatchDescription; | 696 return mismatchDescription; |
697 } | 697 } |
698 } | 698 } |
OLD | NEW |