OLD | NEW |
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 part of unittest.matcher; | 5 part of matcher; |
6 | 6 |
7 /** The objects thrown by the default failure handler. */ | 7 /** The objects thrown by the default failure handler. */ |
8 class TestFailure extends Error { | 8 class TestFailure extends Error { |
9 final String message; | 9 final String message; |
10 | 10 |
11 TestFailure(this.message); | 11 TestFailure(this.message); |
12 | 12 |
13 String toString() => message; | 13 String toString() => message; |
14 } | 14 } |
15 | 15 |
16 /** | 16 /** |
17 * Useful utility for nesting match states. | 17 * Useful utility for nesting match states. |
18 */ | 18 */ |
19 | 19 |
20 void addStateInfo(Map matchState, Map values) { | 20 void addStateInfo(Map matchState, Map values) { |
21 var innerState = new Map.from(matchState); | 21 var innerState = new Map.from(matchState); |
22 matchState.clear(); | 22 matchState.clear(); |
23 matchState['state'] = innerState; | 23 matchState['state'] = innerState; |
24 matchState.addAll(values); | 24 matchState.addAll(values); |
25 } | 25 } |
26 | 26 |
27 /** | 27 /** |
28 * Some matchers, like those for Futures and exception testing, | 28 * Some matchers, like those for Futures and exception testing, |
29 * can fail in asynchronous sections, and throw exceptions. | 29 * can fail in asynchronous sections, and throw exceptions. |
30 * A user of this library will typically want to catch and handle | 30 * A user of this library will typically want to catch and handle |
31 * such exceptions. The [wrapAsync] property is a function that | 31 * such exceptions. The [wrapAsync] property is a function that |
32 * can wrap callbacks used by these Matchers so that they can be | 32 * can wrap callbacks used by these Matchers so that they can be |
33 * used safely. For example, the unittest library will set this | 33 * used safely. For example, the unittest library will set this |
34 * to be expectAsync1. By default this is an identity function. | 34 * to be `expectAsync`. By default this is an identity function. |
35 */ | 35 */ |
36 Function wrapAsync = (f, [id]) => f; | 36 Function wrapAsync = (Function f, [id]) => f; |
37 | 37 |
38 /** | 38 /** |
39 * This is the main assertion function. It asserts that [actual] | 39 * This is the main assertion function. It asserts that [actual] |
40 * matches the [matcher]. [reason] is optional and is typically not | 40 * matches the [matcher]. [reason] is optional and is typically not |
41 * supplied, as a reason is generated from the matcher; if [reason] | 41 * supplied, as a reason is generated from the matcher; if [reason] |
42 * is included it is appended to the reason generated by the matcher. | 42 * is included it is appended to the reason generated by the matcher. |
43 * | 43 * |
44 * [matcher] can be a value in which case it will be wrapped in an | 44 * [matcher] can be a value in which case it will be wrapped in an |
45 * [equals] matcher. | 45 * [equals] matcher. |
46 * | 46 * |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 * formatter is returned; this allows custom expect handlers to easily | 167 * formatter is returned; this allows custom expect handlers to easily |
168 * get a reference to the default formatter. | 168 * get a reference to the default formatter. |
169 */ | 169 */ |
170 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { | 170 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { |
171 if (formatter == null) { | 171 if (formatter == null) { |
172 formatter = _defaultErrorFormatter; | 172 formatter = _defaultErrorFormatter; |
173 } | 173 } |
174 return _assertErrorFormatter = formatter; | 174 return _assertErrorFormatter = formatter; |
175 } | 175 } |
176 | 176 |
OLD | NEW |