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

Unified Diff: pkg/matcher/lib/src/core_matchers.dart

Issue 438473002: pkg/matcher: refactored code around data-structure vs execution-based matchers (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/matcher/lib/matcher.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/core_matchers.dart
diff --git a/pkg/matcher/lib/src/core_matchers.dart b/pkg/matcher/lib/src/core_matchers.dart
index f1a724a72719a7ea4839439bd492a86cda64238f..8de3a013def9b8dda05e12f59408c9deac11a58e 100644
--- a/pkg/matcher/lib/src/core_matchers.dart
+++ b/pkg/matcher/lib/src/core_matchers.dart
@@ -4,11 +4,9 @@
library matcher.core_matchers;
-import 'dart:async';
-
import 'description.dart';
-import 'expect.dart';
import 'interfaces.dart';
+import 'util.dart';
/// Returns a matcher that matches empty strings, maps or iterables
/// (including collections).
@@ -390,36 +388,6 @@ class isInstanceOf<T> extends Matcher {
description.add('an instance of ${_name}');
}
-/// This can be used to match two kinds of objects:
-///
-/// * A [Function] that throws an exception when called. The function cannot
-/// take any arguments. If you want to test that a function expecting
-/// arguments throws, wrap it in another zero-argument function that calls
-/// the one you want to test.
-///
-/// * A [Future] that completes with an exception. Note that this creates an
-/// asynchronous expectation. The call to `expect()` that includes this will
-/// return immediately and execution will continue. Later, when the future
-/// completes, the actual expectation will run.
-const Matcher throws = const Throws();
-
-/// This can be used to match two kinds of objects:
-///
-/// * A [Function] that throws an exception when called. The function cannot
-/// take any arguments. If you want to test that a function expecting
-/// arguments throws, wrap it in another zero-argument function that calls
-/// the one you want to test.
-///
-/// * A [Future] that completes with an exception. Note that this creates an
-/// asynchronous expectation. The call to `expect()` that includes this will
-/// return immediately and execution will continue. Later, when the future
-/// completes, the actual expectation will run.
-///
-/// In both cases, when an exception is thrown, this will test that the exception
-/// object matches [matcher]. If [matcher] is not an instance of [Matcher], it
-/// will implicitly be treated as `equals(matcher)`.
-Matcher throwsA(matcher) => new Throws(wrapMatcher(matcher));
-
/// A matcher that matches a function call against no exception.
/// The function will be called once. Any exceptions will be silently swallowed.
/// The value passed to expect() should be a reference to the function.
@@ -427,77 +395,6 @@ Matcher throwsA(matcher) => new Throws(wrapMatcher(matcher));
/// a wrapper will have to be created.
const Matcher returnsNormally = const _ReturnsNormally();
-class Throws extends Matcher {
- final Matcher _matcher;
-
- const Throws([Matcher matcher]) : this._matcher = matcher;
-
- bool matches(item, Map matchState) {
- if (item is! Function && item is! Future) return false;
- if (item is Future) {
- var done = wrapAsync((fn) => fn());
-
- // Queue up an asynchronous expectation that validates when the future
- // completes.
- item.then((value) {
- done(() {
- fail("Expected future to fail, but succeeded with '$value'.");
- });
- }, onError: (error, trace) {
- done(() {
- if (_matcher == null) return;
- var reason;
- if (trace != null) {
- var stackTrace = trace.toString();
- stackTrace = " ${stackTrace.replaceAll("\n", "\n ")}";
- reason = "Actual exception trace:\n$stackTrace";
- }
- expect(error, _matcher, reason: reason);
- });
- });
- // It hasn't failed yet.
- return true;
- }
-
- try {
- item();
- return false;
- } catch (e, s) {
- if (_matcher == null || _matcher.matches(e, matchState)) {
- return true;
- } else {
- addStateInfo(matchState, {'exception': e, 'stack': s});
- return false;
- }
- }
- }
-
- Description describe(Description description) {
- if (_matcher == null) {
- return description.add("throws");
- } else {
- return description.add('throws ').addDescriptionOf(_matcher);
- }
- }
-
- Description describeMismatch(item, Description mismatchDescription,
- Map matchState,
- bool verbose) {
- if (item is! Function && item is! Future) {
- return mismatchDescription.add('is not a Function or Future');
- } else if (_matcher == null || matchState['exception'] == null) {
- return mismatchDescription.add('did not throw');
- } else {
- mismatchDescription. add('threw ').
- addDescriptionOf(matchState['exception']);
- if (verbose) {
- mismatchDescription.add(' at ').add(matchState['stack'].toString());
- }
- return mismatchDescription;
- }
- }
-}
-
class _ReturnsNormally extends Matcher {
const _ReturnsNormally();
« no previous file with comments | « pkg/matcher/lib/matcher.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698