Chromium Code Reviews| OLD | NEW |
|---|---|
| (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 IErrorFormatter interface is implemented by classes that | |
| 10 * can be used to build up error reports upon expect() failures. | |
|
Bob Nystrom
2012/05/30 23:23:51
Square brackets around [expect()], [StringDescript
| |
| 11 * There is one built-in implementation (StringDescription) which | |
| 12 * is used by the default failure handler. If the failure handler | |
| 13 * is replaced it may be desirable to replace the StringDescription | |
| 14 * error description formatter with another; this can be done | |
| 15 * by implementing this interface. | |
| 16 */ | |
| 17 interface IErrorFormatter { | |
| 18 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.
| |
| 19 } | |
| 20 | |
| 21 /** | |
| 22 * Matchers build up their error messages by appending to | |
| 23 * IDescription objects. This interface is also implemented | |
| 24 * by StringDescription. This interface is unlikely to need | |
| 25 * other implementations, but could be useful to replace in | |
| 26 * some cases - e.g. language conversion. | |
| 27 */ | |
| 28 interface IDescription { | |
| 29 IDescription append(text); | |
|
Bob Nystrom
2012/05/30 23:23:51
"append" -> "add"
gram
2012/06/01 17:33:15
Done.
| |
| 30 IDescription appendDescriptionOf(value); | |
| 31 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.
| |
| 32 } | |
| 33 | |
| 34 /** | |
| 35 * Matchers must implement the IMatcher interface. There | |
| 36 * 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.
| |
| 37 * describe, which builds a description of the matcher, | |
| 38 * and describeMismatch, which builds a description of | |
| 39 * a specific mismatch. The base Matcher class that implements | |
| 40 * this interface has a generic implementation of | |
| 41 * describeMismatch so this does not need to be provided | |
| 42 * unless a more clear description is required. The other | |
| 43 * two methods must always be provided as they are highly | |
| 44 * matcher-specific. | |
| 45 */ | |
| 46 interface IMatcher { | |
| 47 bool matches(item); | |
| 48 IDescription describe(IDescription description); | |
| 49 IDescription describeMismatch(item, IDescription mismatchDescription); | |
| 50 } | |
| 51 | |
| 52 /** | |
| 53 * Failed matches are reported using a default IFailureHandler. | |
| 54 * The default implementation simply throws ExpectExceptions; | |
| 55 * this can be replaced by some other implementation of | |
| 56 * IFailureHandler by calling configureExpectHandler. | |
| 57 */ | |
| 58 interface IFailureHandler { | |
| 59 void fail(String reason); | |
| 60 void failMatch(actual, IMatcher matcher, String reason); | |
| 61 } | |
| 62 | |
| OLD | NEW |