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

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

Issue 10928139: Changed interfaces to abstract classes where possible in {lib,samples,pkg} (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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // To decouple the reporting of errors, and allow for extensibility of 5 // To decouple the reporting of errors, and allow for extensibility of
6 // matchers, we make use of some interfaces. 6 // matchers, we make use of some interfaces.
7 7
8 /** 8 /**
9 * The ErrorFormatter type is used for functions that 9 * The ErrorFormatter type is used for functions that
10 * can be used to build up error reports upon [expect] failures. 10 * can be used to build up error reports upon [expect] failures.
11 * There is one built-in implementation ([defaultErrorFormatter]) 11 * There is one built-in implementation ([defaultErrorFormatter])
12 * which is used by the default failure handler. If the failure handler 12 * which is used by the default failure handler. If the failure handler
13 * is replaced it may be desirable to replace the [stringDescription] 13 * is replaced it may be desirable to replace the [stringDescription]
14 * error formatter with another. 14 * error formatter with another.
15 */ 15 */
16 typedef String ErrorFormatter(actual, Matcher matcher, String reason, 16 typedef String ErrorFormatter(actual, Matcher matcher, String reason,
17 MatchState matchState, bool verbose); 17 MatchState matchState, bool verbose);
18 18
19 /** 19 /**
20 * Matchers build up their error messages by appending to 20 * Matchers build up their error messages by appending to
21 * Description objects. This interface is implemented by 21 * Description objects. This interface is implemented by
22 * StringDescription. This interface is unlikely to need 22 * StringDescription. This interface is unlikely to need
23 * other implementations, but could be useful to replace in 23 * other implementations, but could be useful to replace in
24 * some cases - e.g. language conversion. 24 * some cases - e.g. language conversion.
25 */ 25 */
26 interface Description { 26 abstract class Description {
27 /** Change the value of the description. */ 27 /** Change the value of the description. */
28 Description replace(String text); 28 Description replace(String text);
29 29
30 /** This is used to add arbitrary text to the description. */ 30 /** This is used to add arbitrary text to the description. */
31 Description add(String text); 31 Description add(String text);
32 32
33 /** This is used to add a meaningful description of a value. */ 33 /** This is used to add a meaningful description of a value. */
34 Description addDescriptionOf(value); 34 Description addDescriptionOf(value);
35 35
36 /** 36 /**
37 * This is used to add a description of an [Iterable] [list], 37 * This is used to add a description of an [Iterable] [list],
38 * with appropriate [start] and [end] markers and inter-element [separator]. 38 * with appropriate [start] and [end] markers and inter-element [separator].
39 */ 39 */
40 Description addAll(String start, String separator, String end, 40 Description addAll(String start, String separator, String end,
41 Iterable list); 41 Iterable list);
42 } 42 }
43 43
44 /** 44 /**
45 * [expect] Matchers must implement the Matcher interface. 45 * [expect] Matchers must implement the Matcher interface.
ngeoffray 2012/09/12 10:41:47 Matcher interface -> Matcher class.
bakster 2012/09/12 10:45:49 Done.
46 * The base Matcher class that implements this interface has 46 * The base Matcher class that implements this interface has
47 * a generic implementation of [describeMismatch] so this does 47 * a generic implementation of [describeMismatch] so this does
48 * not need to be provided unless a more clear description is 48 * not need to be provided unless a more clear description is
49 * required. The other two methods ([matches] and [describe]) 49 * required. The other two methods ([matches] and [describe])
50 * must always be provided as they are highly matcher-specific. 50 * must always be provided as they are highly matcher-specific.
51 */ 51 */
52 interface Matcher { 52 abstract class Matcher {
53 /** 53 /**
54 * This does the matching of the actual vs expected values. 54 * This does the matching of the actual vs expected values.
55 * [item] is the actual value. [matchState] can be supplied 55 * [item] is the actual value. [matchState] can be supplied
56 * and may be used to add details about the mismatch that are too 56 * and may be used to add details about the mismatch that are too
57 * costly to determine in [describeMismatch]. 57 * costly to determine in [describeMismatch].
58 */ 58 */
59 bool matches(item, MatchState matchState); 59 bool matches(item, MatchState matchState);
60 60
61 /** This builds a textual description of the matcher. */ 61 /** This builds a textual description of the matcher. */
62 Description describe(Description description); 62 Description describe(Description description);
(...skipping 11 matching lines...) Expand all
74 Description describeMismatch(item, Description mismatchDescription, 74 Description describeMismatch(item, Description mismatchDescription,
75 MatchState matchState, bool verbose); 75 MatchState matchState, bool verbose);
76 } 76 }
77 77
78 /** 78 /**
79 * Failed matches are reported using a default IFailureHandler. 79 * Failed matches are reported using a default IFailureHandler.
80 * The default implementation simply throws ExpectExceptions; 80 * The default implementation simply throws ExpectExceptions;
81 * this can be replaced by some other implementation of 81 * this can be replaced by some other implementation of
82 * IFailureHandler by calling configureExpectHandler. 82 * IFailureHandler by calling configureExpectHandler.
83 */ 83 */
84 interface FailureHandler { 84 abstract class FailureHandler {
85 /** This handles failures given a textual decription */ 85 /** This handles failures given a textual decription */
86 void fail(String reason); 86 void fail(String reason);
87 87
88 /** 88 /**
89 * This handles failures given the actual [value], the [matcher] 89 * This handles failures given the actual [value], the [matcher]
90 * the [reason] (argument from [expect]), some additonal [matchState] 90 * the [reason] (argument from [expect]), some additonal [matchState]
91 * generated by the [matcher], and a verbose flag which controls in 91 * generated by the [matcher], and a verbose flag which controls in
92 * some cases how much [matchState] information is used. It will use 92 * some cases how much [matchState] information is used. It will use
93 * these to create a detailed error message (typically by calling 93 * these to create a detailed error message (typically by calling
94 * an [ErrorFormatter]) and then call [fail] with this message. 94 * an [ErrorFormatter]) and then call [fail] with this message.
95 */ 95 */
96 void failMatch(actual, Matcher matcher, String reason, 96 void failMatch(actual, Matcher matcher, String reason,
97 MatchState matchState, bool verbose); 97 MatchState matchState, bool verbose);
98 } 98 }
99 99
OLDNEW
« lib/utf/utf_core.dart ('K') | « pkg/fixnum/intx.dart ('k') | samples/markdown/ast.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698