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

Side by Side Diff: pkg/unittest/lib/src/pretty_print.dart

Issue 15589002: Stop working around issue 10721. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 library pretty_print; 5 library pretty_print;
6 6
7 import 'utils.dart'; 7 import 'utils.dart';
8 8
9 /** 9 /**
10 * Returns a pretty-printed representation of [object]. 10 * Returns a pretty-printed representation of [object].
(...skipping 30 matching lines...) Expand all
41 singleLine.length + indent <= maxLineLength) && 41 singleLine.length + indent <= maxLineLength) &&
42 !singleLine.contains("\n")) { 42 !singleLine.contains("\n")) {
43 return singleLine; 43 return singleLine;
44 } 44 }
45 45
46 // Otherwise, print each member on its own line. 46 // Otherwise, print each member on its own line.
47 return "$type[\n" + strings.map((string) { 47 return "$type[\n" + strings.map((string) {
48 return _indent(indent + 2) + string; 48 return _indent(indent + 2) + string;
49 }).join(",\n") + "\n" + _indent(indent) + "]"; 49 }).join(",\n") + "\n" + _indent(indent) + "]";
50 } else if (object is Map) { 50 } else if (object is Map) {
51 // TODO(nweiz): This re-assignment is necessary to work around issue
52 // 10721. Remove it when that issue is fixed.
53 var map = object;
54
55 // Convert the contents of the map to string representations. 51 // Convert the contents of the map to string representations.
56 var strings = map.keys.map((key) { 52 var strings = object.keys.map((key) {
57 return '${pp(key)}: ${pp(map[key])}'; 53 return '${pp(key)}: ${pp(object[key])}';
58 }).toList(); 54 }).toList();
59 55
60 // Truncate the list of strings if it's longer than [maxItems]. 56 // Truncate the list of strings if it's longer than [maxItems].
61 if (maxItems != null && strings.length > maxItems) { 57 if (maxItems != null && strings.length > maxItems) {
62 strings.replaceRange(maxItems - 1, strings.length, ['...']); 58 strings.replaceRange(maxItems - 1, strings.length, ['...']);
63 } 59 }
64 60
65 // If the printed string is short and doesn't contain a newline, print it 61 // If the printed string is short and doesn't contain a newline, print it
66 // as a single line. 62 // as a single line.
67 var singleLine = "{${strings.join(", ")}}"; 63 var singleLine = "{${strings.join(", ")}}";
(...skipping 29 matching lines...) Expand all
97 } else { 93 } else {
98 return "${typeName(object)}:$value"; 94 return "${typeName(object)}:$value";
99 } 95 }
100 } 96 }
101 } 97 }
102 98
103 return _prettyPrint(object, 0, new Set(), true); 99 return _prettyPrint(object, 0, new Set(), true);
104 } 100 }
105 101
106 String _indent(int length) => new List.filled(length, ' ').join(''); 102 String _indent(int length) => new List.filled(length, ' ').join('');
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698