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

Unified Diff: lib/unittest/interfaces.dart

Issue 10441104: New expectation functions plus convert old tests to use these. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 7 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
Index: lib/unittest/interfaces.dart
===================================================================
--- lib/unittest/interfaces.dart (revision 0)
+++ lib/unittest/interfaces.dart (revision 0)
@@ -0,0 +1,62 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// To decouple the reporting of errors, and allow for extensibility of
+// matchers, we make use of some interfaces.
+
+/**
+ * The IErrorFormatter interface is implemented by classes that
+ * can be used to build up error reports upon expect() failures.
Bob Nystrom 2012/05/30 23:23:51 Square brackets around [expect()], [StringDescript
+ * There is one built-in implementation (StringDescription) which
+ * is used by the default failure handler. If the failure handler
+ * is replaced it may be desirable to replace the StringDescription
+ * error description formatter with another; this can be done
+ * by implementing this interface.
+ */
+interface IErrorFormatter {
+ String format(actual, IMatcher matcher, String reason);
Bob Nystrom 2012/05/30 23:23:51 Should this just be a function type? Why make it a
gram 2012/06/01 17:33:15 Done.
+}
+
+/**
+ * Matchers build up their error messages by appending to
+ * IDescription objects. This interface is also implemented
+ * by StringDescription. This interface is unlikely to need
+ * other implementations, but could be useful to replace in
+ * some cases - e.g. language conversion.
+ */
+interface IDescription {
+ IDescription append(text);
Bob Nystrom 2012/05/30 23:23:51 "append" -> "add"
gram 2012/06/01 17:33:15 Done.
+ IDescription appendDescriptionOf(value);
+ IDescription appendList(start, separator, end, list);
Bob Nystrom 2012/05/30 23:23:51 Can these be typed?
gram 2012/06/01 17:33:15 Done.
+}
+
+/**
+ * Matchers must implement the IMatcher interface. There
+ * are three methods: match, which does the matching;
Bob Nystrom 2012/05/30 23:23:51 Instead of describing the methods here, just put c
gram 2012/06/01 17:33:15 Done.
+ * describe, which builds a description of the matcher,
+ * and describeMismatch, which builds a description of
+ * a specific mismatch. The base Matcher class that implements
+ * this interface has a generic implementation of
+ * describeMismatch so this does not need to be provided
+ * unless a more clear description is required. The other
+ * two methods must always be provided as they are highly
+ * matcher-specific.
+ */
+interface IMatcher {
+ bool matches(item);
+ IDescription describe(IDescription description);
+ IDescription describeMismatch(item, IDescription mismatchDescription);
+}
+
+/**
+ * Failed matches are reported using a default IFailureHandler.
+ * The default implementation simply throws ExpectExceptions;
+ * this can be replaced by some other implementation of
+ * IFailureHandler by calling configureExpectHandler.
+ */
+interface IFailureHandler {
+ void fail(String reason);
+ void failMatch(actual, IMatcher matcher, String reason);
+}
+

Powered by Google App Engine
This is Rietveld 408576698