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

Side by Side Diff: pkg/unittest/lib/src/interfaces.dart

Issue 10928216: revert 1204. Will investigate when I get a chance. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 3 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
« no previous file with comments | « pkg/unittest/lib/src/html_print.dart ('k') | pkg/unittest/lib/src/map_matchers.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 MatchState matchState, bool verbose);
18
19 /**
20 * Matchers build up their error messages by appending to
21 * Description objects. This interface is implemented by
22 * StringDescription. This interface is unlikely to need
23 * other implementations, but could be useful to replace in
24 * some cases - e.g. language conversion.
25 */
26 abstract class Description {
27 /** Change the value of the description. */
28 Description replace(String text);
29
30 /** This is used to add arbitrary text to the description. */
31 Description add(String text);
32
33 /** This is used to add a meaningful description of a value. */
34 Description addDescriptionOf(value);
35
36 /**
37 * This is used to add a description of an [Iterable] [list],
38 * with appropriate [start] and [end] markers and inter-element [separator].
39 */
40 Description addAll(String start, String separator, String end,
41 Iterable list);
42 }
43
44 /**
45 * [expect] Matchers must implement the Matcher class.
46 * The base Matcher class that implements this interface has
47 * a generic implementation of [describeMismatch] so this does
48 * not need to be provided unless a more clear description is
49 * required. The other two methods ([matches] and [describe])
50 * must always be provided as they are highly matcher-specific.
51 */
52 abstract class Matcher {
53 /**
54 * This does the matching of the actual vs expected values.
55 * [item] is the actual value. [matchState] can be supplied
56 * and may be used to add details about the mismatch that are too
57 * costly to determine in [describeMismatch].
58 */
59 bool matches(item, MatchState matchState);
60
61 /** This builds a textual description of the matcher. */
62 Description describe(Description description);
63
64 /**
65 * This builds a textual description of a specific mismatch. [item]
66 * is the value that was tested by [matches]; [matchState] is
67 * the [MatchState] that was passed to and supplemented by [matches]
68 * with additional information about the mismact, and [mismatchDescription]
69 * is the [Description] that is being built to decribe the mismatch.
70 * A few matchers make use of the [verbose] flag to provide detailed
71 * information that is not typically included but can be of help in
72 * diagnosing failures, such as stack traces.
73 */
74 Description describeMismatch(item, Description mismatchDescription,
75 MatchState matchState, bool verbose);
76 }
77
78 /**
79 * Failed matches are reported using a default IFailureHandler.
80 * The default implementation simply throws ExpectExceptions;
81 * this can be replaced by some other implementation of
82 * IFailureHandler by calling configureExpectHandler.
83 */
84 abstract class FailureHandler {
85 /** This handles failures given a textual decription */
86 void fail(String reason);
87
88 /**
89 * This handles failures given the actual [value], the [matcher]
90 * the [reason] (argument from [expect]), some additonal [matchState]
91 * generated by the [matcher], and a verbose flag which controls in
92 * some cases how much [matchState] information is used. It will use
93 * these to create a detailed error message (typically by calling
94 * an [ErrorFormatter]) and then call [fail] with this message.
95 */
96 void failMatch(actual, Matcher matcher, String reason,
97 MatchState matchState, bool verbose);
98 }
99
OLDNEW
« no previous file with comments | « pkg/unittest/lib/src/html_print.dart ('k') | pkg/unittest/lib/src/map_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698