| 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 /** | 5 /** |
| 6 * This is the main assertion function. It asserts that [actual] | 6 * This is the main assertion function. It asserts that [actual] |
| 7 * matches the [matcher]. [matcher] is optional and defaults to isTrue, | 7 * matches the [matcher]. [matcher] is optional and defaults to isTrue, |
| 8 * so expect can be used with a single predicate argument. [reason] | 8 * so expect can be used with a single predicate argument. [reason] |
| 9 * is optional and is typically not supplied if a reasonable matcher is | 9 * is optional and is typically not supplied if a reasonable matcher is |
| 10 * explicitly provided, as a reason can be generated from the matcher. | 10 * explicitly provided, as a reason can be generated from the matcher. |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 // The error message formatter for failed asserts. | 106 // The error message formatter for failed asserts. |
| 107 ErrorFormatter _assertErrorFormatter = null; | 107 ErrorFormatter _assertErrorFormatter = null; |
| 108 | 108 |
| 109 // The default error formatter implementation. | 109 // The default error formatter implementation. |
| 110 String _defaultErrorFormatter(actual, Matcher matcher, String reason) { | 110 String _defaultErrorFormatter(actual, Matcher matcher, String reason) { |
| 111 var description = new StringDescription(); | 111 var description = new StringDescription(); |
| 112 description.add('Expected: ').addDescriptionOf(matcher). | 112 description.add('Expected: ').addDescriptionOf(matcher). |
| 113 add('\n but: '); | 113 add('\n but: '); |
| 114 matcher.describeMismatch(actual, description); | 114 matcher.describeMismatch(actual, description); |
| 115 description.add('.\n'); |
| 115 if (reason != null) { | 116 if (reason != null) { |
| 116 description.add('\n').add(reason).add('\n'); | 117 description.add(reason).add('\n'); |
| 117 } | 118 } |
| 118 return description.toString(); | 119 return description.toString(); |
| 119 } | 120 } |
| 120 | 121 |
| 121 /** | 122 /** |
| 122 * Changes or resets to default the failure message formatter for expect(). | 123 * Changes or resets to default the failure message formatter for expect(). |
| 123 * [formatter] is a reference to the new formatter; if this is omitted or | 124 * [formatter] is a reference to the new formatter; if this is omitted or |
| 124 * null then the failure formatter is reset to the default. The new | 125 * null then the failure formatter is reset to the default. The new |
| 125 * formatter is returned; this allows custom expect handlers to easily | 126 * formatter is returned; this allows custom expect handlers to easily |
| 126 * get a reference to the default formatter. | 127 * get a reference to the default formatter. |
| 127 */ | 128 */ |
| 128 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { | 129 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { |
| 129 if (formatter == null) { | 130 if (formatter == null) { |
| 130 formatter = _defaultErrorFormatter; | 131 formatter = _defaultErrorFormatter; |
| 131 } | 132 } |
| 132 return _assertErrorFormatter = formatter; | 133 return _assertErrorFormatter = formatter; |
| 133 } | 134 } |
| 134 | 135 |
| OLD | NEW |