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

Side by Side Diff: pkg/matcher/lib/src/description.dart

Issue 313563002: pkg/matcher: Reverting 36881,36896 while investigating dart2js checked crash (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 6 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 | « pkg/matcher/lib/src/core_matchers.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | 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) 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 library matcher.description; 5 library matcher.description;
6 6
7 import 'interfaces.dart'; 7 import 'interfaces.dart';
8 import 'pretty_print.dart'; 8 import 'pretty_print.dart';
9 import 'utils.dart';
9 10
10 /// The default implementation of [Description]. This should rarely need 11 /**
11 /// substitution, although conceivably it is a place where other languages 12 * The default implementation of IDescription. This should rarely need
12 /// could be supported. 13 * substitution, although conceivably it is a place where other languages
14 * could be supported.
15 */
13 class StringDescription implements Description { 16 class StringDescription implements Description {
14 final StringBuffer _out = new StringBuffer(); 17 var _out;
15 18
16 /// Initialize the description with initial contents [init]. 19 /** Initialize the description with initial contents [init]. */
17 StringDescription([String init = '']) { 20 StringDescription([String init = '']) {
18 _out.write(init); 21 _out = init;
19 } 22 }
20 23
21 int get length => _out.length; 24 int get length => _out.length;
22 25
23 /// Get the description as a string. 26 /** Get the description as a string. */
24 String toString() => _out.toString(); 27 String toString() => _out;
25 28
26 /// Append [text] to the description. 29 /** Append [text] to the description. */
27 Description add(String text) { 30 Description add(text) {
28 _out.write(text); 31 _out = '${_out}${text}';
29 return this; 32 return this;
30 } 33 }
31 34
32 /// Change the value of the description. 35 /** Change the value of the description. */
33 Description replace(String text) { 36 Description replace(String text) {
34 _out.clear(); 37 _out = text;
35 return add(text); 38 return this;
36 } 39 }
37 40
38 /// Appends a description of [value]. If it is an IMatcher use its 41 /**
39 /// describe method; if it is a string use its literal value after 42 * Appends a description of [value]. If it is an IMatcher use its
40 /// escaping any embedded control characters; otherwise use its 43 * describe method; if it is a string use its literal value after
41 /// toString() value and wrap it in angular "quotes". 44 * escaping any embedded control characters; otherwise use its
45 * toString() value and wrap it in angular "quotes".
46 */
42 Description addDescriptionOf(value) { 47 Description addDescriptionOf(value) {
43 if (value is Matcher) { 48 if (value is Matcher) {
44 value.describe(this); 49 value.describe(this);
45 } else { 50 } else {
46 add(prettyPrint(value, maxLineLength: 80, maxItems: 25)); 51 add(prettyPrint(value, maxLineLength: 80, maxItems: 25));
47 } 52 }
48 return this; 53 return this;
49 } 54 }
50 55
51 /// Append an [Iterable] [list] of objects to the description, using the 56 /**
52 /// specified [separator] and framing the list with [start] 57 * Append an [Iterable] [list] of objects to the description, using the
53 /// and [end]. 58 * specified [separator] and framing the list with [start]
59 * and [end].
60 */
54 Description addAll(String start, String separator, String end, 61 Description addAll(String start, String separator, String end,
55 Iterable list) { 62 Iterable list) {
56 var separate = false; 63 var separate = false;
57 add(start); 64 add(start);
58 for (var item in list) { 65 for (var item in list) {
59 if (separate) { 66 if (separate) {
60 add(separator); 67 add(separator);
61 } 68 }
62 addDescriptionOf(item); 69 addDescriptionOf(item);
63 separate = true; 70 separate = true;
64 } 71 }
65 add(end); 72 add(end);
66 return this; 73 return this;
67 } 74 }
75
76 /** Escape the control characters in [string] so that they are visible. */
77 _addEscapedString(String string) {
78 add("'");
79 add(escapeString(string));
80 add("'");
81 }
68 } 82 }
OLDNEW
« no previous file with comments | « pkg/matcher/lib/src/core_matchers.dart ('k') | pkg/matcher/lib/src/error_matchers.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698