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

Side by Side 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, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // To decouple the reporting of errors, and allow for extensibility of
6 // matchers, we make use of some interfaces.
7
8 /**
9 * The ErrorFormatter type is used for functions that
10 * can be used to build up error reports upon [expect] failures.
11 * There is one built-in implementation ([defaultErrorFormatter])
12 * which is used by the default failure handler. If the failure handler
13 * is replaced it may be desirable to replace the [stringDescription]
14 * error formatter with another.
15 */
16 typedef String ErrorFormatter(actual, Matcher matcher, String reason);
17
18 /**
19 * Matchers build up their error messages by appending to
20 * Description objects. This interface is implemented by
21 * StringDescription. This interface is unlikely to need
22 * other implementations, but could be useful to replace in
23 * some cases - e.g. language conversion.
24 */
25 interface Description {
26 /** This is used to add arbitrary text to the description. */
27 Description add(String text);
28 /** This is used to add a meaningful description of a value. */
Siggi Cherem (dart-lang) 2012/06/06 00:26:08 style nit: add empty line above this comment (here
gram 2012/06/06 16:23:56 Done.
29 Description addDescriptionOf(value);
30 /**
31 * This is used to add a description of an [Iterable] [list],
32 * with appropriate [start] and [end] markers and inter-element [separator].
33 */
34 Description addAll(String start, String separator, String end,
35 Iterable list);
36 }
37
38 /**
39 * [expect] Matchers must implement the Matcher interface.
40 * The base Matcher class that implements this interface has
41 * a generic implementation of [describeMismatch] so this does
42 * not need to be provided unless a more clear description is
43 * required. The other two methods ([matches] and [describe])
44 * must always be provided as they are highly matcher-specific.
45 */
46 interface Matcher {
47 /** This does the matching of the actual vs expected values. */
48 bool matches(item);
49 /** This builds a textual description of the matcher. */
50 Description describe(Description description);
51 /**This builds a textual description of a specific mismatch. */
52 Description describeMismatch(item, Description mismatchDescription);
53 }
54
55 /**
56 * Failed matches are reported using a default IFailureHandler.
57 * The default implementation simply throws ExpectExceptions;
58 * this can be replaced by some other implementation of
59 * IFailureHandler by calling configureExpectHandler.
60 */
61 interface FailureHandler {
62 /** This handles failures given a textual decription */
63 void fail(String reason);
64 /**
65 * This handles failures given the actual [value], the [matcher]
66 * and the [reason]. It will typically use these to create a
67 * detailed error message (typically using an [ErrorFormatter])
68 * and then call [fail].
69 */
70 void failMatch(actual, Matcher matcher, String reason);
71 }
72
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698