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

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

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

Powered by Google App Engine
This is Rietveld 408576698