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

Unified Diff: pkg/matcher/lib/src/expect.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/src/error_matchers.dart ('k') | pkg/matcher/lib/src/future_matchers.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/matcher/lib/src/expect.dart
diff --git a/pkg/matcher/lib/src/expect.dart b/pkg/matcher/lib/src/expect.dart
index 073ef34300b24116fd61506758bc6e5b6e3d2030..bd54747685403042ad7830864c949482ce78c9fc 100644
--- a/pkg/matcher/lib/src/expect.dart
+++ b/pkg/matcher/lib/src/expect.dart
@@ -7,6 +7,7 @@ library matcher.expect;
import 'core_matchers.dart';
import 'description.dart';
import 'interfaces.dart';
+import 'util.dart';
/// The objects thrown by the default failure handler.
class TestFailure extends Error {
@@ -17,15 +18,33 @@ class TestFailure extends Error {
String toString() => message;
}
-/// Useful utility for nesting match states.
-
-void addStateInfo(Map matchState, Map values) {
- var innerState = new Map.from(matchState);
- matchState.clear();
- matchState['state'] = innerState;
- matchState.addAll(values);
+/// Failed matches are reported using a default IFailureHandler.
+/// The default implementation simply throws [TestFailure]s;
+/// this can be replaced by some other implementation of
+/// IFailureHandler by calling configureExpectHandler.
+abstract class FailureHandler {
+ /// This handles failures given a textual decription
+ void fail(String reason);
+
+ /// This handles failures given the actual [value], the [matcher]
+ /// the [reason] (argument from [expect]), some additonal [matchState]
+ /// generated by the [matcher], and a verbose flag which controls in
+ /// some cases how much [matchState] information is used. It will use
+ /// these to create a detailed error message (typically by calling
+ /// an [ErrorFormatter]) and then call [fail] with this message.
+ void failMatch(actual, Matcher matcher, String reason,
+ Map matchState, bool verbose);
}
+/// The ErrorFormatter type is used for functions that
+/// can be used to build up error reports upon [expect] failures.
+/// There is one built-in implementation ([defaultErrorFormatter])
+/// which is used by the default failure handler. If the failure handler
+/// is replaced it may be desirable to replace the [stringDescription]
+/// error formatter with another.
+typedef String ErrorFormatter(actual, Matcher matcher, String reason,
+ Map matchState, bool verbose);
+
/// Some matchers, like those for Futures and exception testing,
/// can fail in asynchronous sections, and throw exceptions.
/// A user of this library will typically want to catch and handle
@@ -81,20 +100,6 @@ void fail(String message, {FailureHandler failureHandler}) {
failureHandler.fail(message);
}
-/// Takes an argument and returns an equivalent matcher.
-/// If the argument is already a matcher this does nothing,
-/// else if the argument is a function, it generates a predicate
-/// function matcher, else it generates an equals matcher.
-Matcher wrapMatcher(x) {
- if (x is Matcher) {
- return x;
- } else if (x is Function) {
- return predicate(x);
- } else {
- return equals(x);
- }
-}
-
// The handler for failed asserts.
FailureHandler _assertFailureHandler = null;
« no previous file with comments | « pkg/matcher/lib/src/error_matchers.dart ('k') | pkg/matcher/lib/src/future_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698