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

Side by Side Diff: lib/unittest/description.dart

Issue 10441104: New expectation functions plus convert old tests to use these. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 /**
6 * The default implementation of IDescription. This should rarely need
7 * substitution, although conceivably it is a place where other languages
8 * could be supported.
9 */
10
Bob Nystrom 2012/05/30 23:23:51 Remove blank line.
gram 2012/06/01 17:33:15 Done.
11 class StringDescription implements IDescription {
12 var _out = '';
13
14 /**
15 * Get the description as a string.
16 */
17 String toString() => _out;
18
19 /**
20 * Append some plain [text] to the description.
21 */
22
Bob Nystrom 2012/05/30 23:23:51 Remove blank line, here and elsewhere.
gram 2012/06/01 17:33:15 Done.
23 IDescription append(text) {
Bob Nystrom 2012/05/30 23:23:51 "add" to be consistent with List and StringBuffer.
gram 2012/06/01 17:33:15 Done.
24 _out = '${_out}${text}';
25 return this;
26 }
27
28 /**
29 * Append a description of given [value]. If it is a string just
Bob Nystrom 2012/05/30 23:23:51 "Append" -> "appends". Remove "given".
gram 2012/06/01 17:33:15 Done.
30 * append it with some control characters escaped. Else try
Bob Nystrom 2012/05/30 23:23:51 This sentence needs some grammar work.
31 * call describe on the value itself, which will work for
32 * IMatchers. If that fails, just quote its toString() value.
33 */
34
35 IDescription appendDescriptionOf(value) {
36 try {
37 value.describe(this);
Bob Nystrom 2012/05/30 23:23:51 Instead of just trying to call describe(), why not
gram 2012/06/01 17:33:15 Done.
38 } catch(var e) {
39 if (value is String) {
40 _appendEscapedString(value);
41 } else {
42 String description = value.toString();
43 if (description.startsWith('<') && description.endsWith('>')) {
44 append(description);
45 } else {
46 append('<');
47 append(description);
48 append('>');
49 }
50 }
51 }
52 return this;
53 }
54
55 /**
56 * Append a [list] of objects to the description, using the
57 * specified [separator] and framing the list with [start]
58 * and [end].
59 */
60
61 IDescription appendList(start, separator, end, list) {
62 var separate = false;
63 append(start);
64 for (var item in list) {
65 if (separate) {
66 append(separator);
67 }
68 appendDescriptionOf(item);
69 separate = true;
70 }
71 append(end);
72 return this;
73 }
74
75 /**
76 * Escape the control characters in [string] so that they are visible.
77 */
78 _appendEscapedString(String string) {
79 append("'");
80 for (var i = 0; i < string.length; i++) {
81 append(_escape(string[i]));
82 }
83 append("'");
84 }
85
86 /**
87 * Return the escaped form of a character [ch].
88 */
89 _escape(ch) {
90 if (ch == "'")
91 return "\'";
92 else if (ch == '\n')
93 return '\\n';
94 else if (ch == '\r')
95 return '\\r';
96 else if (ch == '\t')
97 return '\\t';
98 else
99 return ch;
100 }
101 }
102
103
104
105
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698