Chromium Code Reviews| 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 /** | 7 /** |
| 8 * Some matchers, like those for Futures and exception testing, | 8 * Some matchers, like those for Futures and exception testing, |
| 9 * can fail in asynchronous sections, and throw exceptions. | 9 * can fail in asynchronous sections, and throw exceptions. |
| 10 * A user of this library will typically want to catch and handle | 10 * A user of this library will typically want to catch and handle |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 115 ErrorFormatter _assertErrorFormatter = null; | 115 ErrorFormatter _assertErrorFormatter = null; |
| 116 | 116 |
| 117 // The default error formatter implementation. | 117 // The default error formatter implementation. |
| 118 String _defaultErrorFormatter(actual, Matcher matcher, String reason, | 118 String _defaultErrorFormatter(actual, Matcher matcher, String reason, |
| 119 MatchState matchState, bool verbose) { | 119 MatchState matchState, bool verbose) { |
| 120 var description = new StringDescription(); | 120 var description = new StringDescription(); |
| 121 description.add('Expected: ').addDescriptionOf(matcher). | 121 description.add('Expected: ').addDescriptionOf(matcher). |
| 122 add('\n but: '); | 122 add('\n but: '); |
| 123 matcher.describeMismatch(actual, description, matchState, verbose); | 123 matcher.describeMismatch(actual, description, matchState, verbose); |
| 124 description.add('.\n'); | 124 description.add('.\n'); |
| 125 if (verbose && actual is Iterable) { | 125 if (verbose) { |
| 126 description.add('Actual: ').addDescriptionOf(actual).add('\n'); | 126 if (actual is Iterable) { |
| 127 description.add('Actual: ').addDescriptionOf(actual).add('\n'); | |
| 128 } else if (actual is Map) { | |
| 129 description.add('Actual: '); | |
| 130 var count = 25; | |
|
Siggi Cherem (dart-lang)
2013/02/12 21:06:15
seems quite arbitrary to use 25 =)... maybe 10? (e
gram
2013/02/12 21:08:09
As you say, it is arbitrary. 10 feels too small fo
| |
| 131 for (var k in actual.keys) { | |
|
Siggi Cherem (dart-lang)
2013/02/12 21:06:15
Is this description used for any other purpose? Wi
gram
2013/02/12 21:08:09
No. Unlike the matcher description; this is the er
| |
| 132 if (count == 0) { | |
| 133 description.add('...\n'); | |
| 134 break; | |
| 135 } | |
| 136 description.addDescriptionOf(k); | |
| 137 description.add(' : '); | |
| 138 description.addDescriptionOf(actual[k]); | |
| 139 description.add('\n'); | |
| 140 --count; | |
| 141 } | |
| 142 } | |
| 127 } | 143 } |
| 128 if (reason != null) { | 144 if (reason != null) { |
| 129 description.add(reason).add('\n'); | 145 description.add(reason).add('\n'); |
| 130 } | 146 } |
| 131 return description.toString(); | 147 return description.toString(); |
| 132 } | 148 } |
| 133 | 149 |
| 134 /** | 150 /** |
| 135 * Changes or resets to default the failure message formatter for expect(). | 151 * Changes or resets to default the failure message formatter for expect(). |
| 136 * [formatter] is a reference to the new formatter; if this is omitted or | 152 * [formatter] is a reference to the new formatter; if this is omitted or |
| 137 * null then the failure formatter is reset to the default. The new | 153 * null then the failure formatter is reset to the default. The new |
| 138 * formatter is returned; this allows custom expect handlers to easily | 154 * formatter is returned; this allows custom expect handlers to easily |
| 139 * get a reference to the default formatter. | 155 * get a reference to the default formatter. |
| 140 */ | 156 */ |
| 141 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { | 157 ErrorFormatter configureExpectFormatter([ErrorFormatter formatter = null]) { |
| 142 if (formatter == null) { | 158 if (formatter == null) { |
| 143 formatter = _defaultErrorFormatter; | 159 formatter = _defaultErrorFormatter; |
| 144 } | 160 } |
| 145 return _assertErrorFormatter = formatter; | 161 return _assertErrorFormatter = formatter; |
| 146 } | 162 } |
| 147 | 163 |
| OLD | NEW |