Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1041)

Unified Diff: pkg/unittest/lib/src/expect.dart

Issue 14600029: Add pretty-printing to unittest and more thoroughly print values. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/unittest/lib/src/expect.dart
diff --git a/pkg/unittest/lib/src/expect.dart b/pkg/unittest/lib/src/expect.dart
index 3542f7a8bf03586a04e96d7b031948455f2eb177..f10309dec55500c7f4c244a8e385667623b5d9c8 100644
--- a/pkg/unittest/lib/src/expect.dart
+++ b/pkg/unittest/lib/src/expect.dart
@@ -137,28 +137,15 @@ ErrorFormatter _assertErrorFormatter = null;
String _defaultErrorFormatter(actual, Matcher matcher, String reason,
MatchState matchState, bool verbose) {
var description = new StringDescription();
- description.add('Expected: ').addDescriptionOf(matcher).
- add('\n but: ');
- matcher.describeMismatch(actual, description, matchState, verbose);
- description.add('.\n');
- if (verbose) {
- if (actual is Iterable) {
- description.add('Actual: ').addDescriptionOf(actual).add('\n');
- } else if (actual is Map) {
- description.add('Actual: ');
- var count = 25;
- for (var k in actual.keys) {
- if (count == 0) {
- description.add('...\n');
- break;
- }
- description.addDescriptionOf(k);
- description.add(' : ');
- description.addDescriptionOf(actual[k]);
- description.add('\n');
- --count;
- }
- }
+ description.add('Expected: ').addDescriptionOf(matcher).add('\n');
+
+ var mismatchDescription = new StringDescription();
+ matcher.describeMismatch(actual, mismatchDescription, matchState, verbose);
+ description.add(' But: ')
+ .add(mismatchDescription.toString()).add('.\n');
+
+ if (!mismatchDescription.toString().startsWith("was ")) {
+ description.add('Actual: ').addDescriptionOf(actual);
}
if (reason != null) {
description.add(reason).add('\n');

Powered by Google App Engine
This is Rietveld 408576698