| 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 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 { | 8 class TestFailure { |
| 9 String _message; | 9 String _message; |
| 10 | 10 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 } | 142 } |
| 143 | 143 |
| 144 // The error message formatter for failed asserts. | 144 // The error message formatter for failed asserts. |
| 145 ErrorFormatter _assertErrorFormatter = null; | 145 ErrorFormatter _assertErrorFormatter = null; |
| 146 | 146 |
| 147 // The default error formatter implementation. | 147 // The default error formatter implementation. |
| 148 String _defaultErrorFormatter(actual, Matcher matcher, String reason, | 148 String _defaultErrorFormatter(actual, Matcher matcher, String reason, |
| 149 Map matchState, bool verbose) { | 149 Map matchState, bool verbose) { |
| 150 var description = new StringDescription(); | 150 var description = new StringDescription(); |
| 151 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); | 151 description.add('Expected: ').addDescriptionOf(matcher).add('\n'); |
| 152 description.add(' Actual: ').addDescriptionOf(actual); | 152 description.add(' Actual: ').addDescriptionOf(actual).add('\n'); |
| 153 | 153 |
| 154 var mismatchDescription = new StringDescription(); | 154 var mismatchDescription = new StringDescription(); |
| 155 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); | 155 matcher.describeMismatch(actual, mismatchDescription, matchState, verbose); |
| 156 | 156 |
| 157 if (mismatchDescription.length > 0) { | 157 if (mismatchDescription.length > 0) { |
| 158 description.add(' Which: ${mismatchDescription}\n'); | 158 description.add(' Which: ${mismatchDescription}\n'); |
| 159 } | 159 } |
| 160 if (reason != null) { | 160 if (reason != null) { |
| 161 description.add(reason).add('\n'); | 161 description.add(reason).add('\n'); |
| 162 } | 162 } |
| 163 return description.toString(); | 163 return description.toString(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 /** | 166 /** |
| 167 * Changes or resets to default the failure message formatter for expect(). | 167 * Changes or resets to default the failure message formatter for expect(). |
| 168 * [formatter] is a reference to the new formatter; if this is omitted or | 168 * [formatter] is a reference to the new formatter; if this is omitted or |
| 169 * null then the failure formatter is reset to the default. The new | 169 * null then the failure formatter is reset to the default. The new |
| 170 * formatter is returned; this allows custom expect handlers to easily | 170 * formatter is returned; this allows custom expect handlers to easily |
| 171 * get a reference to the default formatter. | 171 * get a reference to the default formatter. |
| 172 */ | 172 */ |
| 173 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { | 173 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { |
| 174 if (formatter == null) { | 174 if (formatter == null) { |
| 175 formatter = _defaultErrorFormatter; | 175 formatter = _defaultErrorFormatter; |
| 176 } | 176 } |
| 177 return _assertErrorFormatter = formatter; | 177 return _assertErrorFormatter = formatter; |
| 178 } | 178 } |
| 179 | 179 |
| OLD | NEW |