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

Side by Side Diff: packages/matcher/test/pretty_print_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 5 years, 2 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
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 library matcher.pretty_print_test;
6
7 import 'dart:collection';
8
9 import 'package:matcher/matcher.dart';
10 import 'package:matcher/src/pretty_print.dart';
11 import 'package:test/test.dart' show group, test, expect;
12
13 class DefaultToString {}
14
15 class CustomToString {
16 String toString() => "string representation";
17 }
18
19 class _PrivateName {
20 String toString() => "string representation";
21 }
22
23 class _PrivateNameIterable extends IterableMixin {
24 Iterator get iterator => [1, 2, 3].iterator;
25 }
26
27 void main() {
28 test('with primitive objects', () {
29 expect(prettyPrint(12), equals('<12>'));
30 expect(prettyPrint(12.13), equals('<12.13>'));
31 expect(prettyPrint(true), equals('<true>'));
32 expect(prettyPrint(null), equals('<null>'));
33 expect(prettyPrint(() => 12), matches(r'<Closure(: \(\) => dynamic)?>'));
34 });
35
36 group('with a string', () {
37 test('containing simple characters', () {
38 expect(prettyPrint('foo'), equals("'foo'"));
39 });
40
41 test('containing newlines', () {
42 expect(prettyPrint('foo\nbar\nbaz'), equals("'foo\\n'\n"
43 " 'bar\\n'\n"
44 " 'baz'"));
45 });
46
47 test('containing escapable characters', () {
48 expect(
49 prettyPrint("foo\rbar\tbaz'qux\v"), equals(r"'foo\rbar\tbaz\'qux\v'")) ;
50 });
51 });
52
53 group('with an iterable', () {
54 test('containing primitive objects', () {
55 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']"));
56 });
57
58 test('containing a multiline string', () {
59 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n"
60 " 'foo',\n"
61 " 'bar\\n'\n"
62 " 'baz\\n'\n"
63 " 'bip',\n"
64 " 'qux'\n"
65 "]"));
66 });
67
68 test('containing a matcher', () {
69 expect(prettyPrint(['foo', endsWith('qux')]),
70 equals("['foo', <a string ending with 'qux'>]"));
71 });
72
73 test("that's under maxLineLength", () {
74 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 30),
75 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
76 });
77
78 test("that's over maxLineLength", () {
79 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 29),
80 equals("[\n"
81 " 0,\n"
82 " 1,\n"
83 " 2,\n"
84 " 3,\n"
85 " 4,\n"
86 " 5,\n"
87 " 6,\n"
88 " 7,\n"
89 " 8,\n"
90 " 9\n"
91 "]"));
92 });
93
94 test("factors indentation into maxLineLength", () {
95 expect(prettyPrint(["foo\nbar", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],],
96 maxLineLength: 30), equals("[\n"
97 " 'foo\\n'\n"
98 " 'bar',\n"
99 " [\n"
100 " 0,\n"
101 " 1,\n"
102 " 2,\n"
103 " 3,\n"
104 " 4,\n"
105 " 5,\n"
106 " 6,\n"
107 " 7,\n"
108 " 8,\n"
109 " 9\n"
110 " ]\n"
111 "]"));
112 });
113
114 test("that's under maxItems", () {
115 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10),
116 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]"));
117 });
118
119 test("that's over maxItems", () {
120 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9),
121 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]"));
122 });
123
124 test("that's recursive", () {
125 var list = [1, 2, 3];
126 list.add(list);
127 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]"));
128 });
129 });
130
131 group("with a map", () {
132 test('containing primitive objects', () {
133 expect(prettyPrint({'foo': 1, 'bar': true}),
134 equals("{'foo': 1, 'bar': true}"));
135 });
136
137 test('containing a multiline string key', () {
138 expect(prettyPrint({'foo\nbar': 1, 'bar': true}), equals("{\n"
139 " 'foo\\n'\n"
140 " 'bar': 1,\n"
141 " 'bar': true\n"
142 "}"));
143 });
144
145 test('containing a multiline string value', () {
146 expect(prettyPrint({'foo': 'bar\nbaz', 'qux': true}), equals("{\n"
147 " 'foo': 'bar\\n'\n"
148 " 'baz',\n"
149 " 'qux': true\n"
150 "}"));
151 });
152
153 test('containing a multiline string key/value pair', () {
154 expect(prettyPrint({'foo\nbar': 'baz\nqux'}), equals("{\n"
155 " 'foo\\n'\n"
156 " 'bar': 'baz\\n'\n"
157 " 'qux'\n"
158 "}"));
159 });
160
161 test('containing a matcher key', () {
162 expect(prettyPrint({endsWith('bar'): 'qux'}),
163 equals("{<a string ending with 'bar'>: 'qux'}"));
164 });
165
166 test('containing a matcher value', () {
167 expect(prettyPrint({'foo': endsWith('qux')}),
168 equals("{'foo': <a string ending with 'qux'>}"));
169 });
170
171 test("that's under maxLineLength", () {
172 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 32),
173 equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
174 });
175
176 test("that's over maxLineLength", () {
177 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 31),
178 equals("{\n"
179 " '0': 1,\n"
180 " '2': 3,\n"
181 " '4': 5,\n"
182 " '6': 7\n"
183 "}"));
184 });
185
186 test("factors indentation into maxLineLength", () {
187 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}],
188 maxLineLength: 32), equals("[\n"
189 " 'foo\\n'\n"
190 " 'bar',\n"
191 " {\n"
192 " '0': 1,\n"
193 " '2': 3,\n"
194 " '4': 5,\n"
195 " '6': 7\n"
196 " }\n"
197 "]"));
198 });
199
200 test("that's under maxItems", () {
201 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4),
202 equals("{'0': 1, '2': 3, '4': 5, '6': 7}"));
203 });
204
205 test("that's over maxItems", () {
206 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3),
207 equals("{'0': 1, '2': 3, ...}"));
208 });
209 });
210 group('with an object', () {
211 test('with a default [toString]', () {
212 expect(prettyPrint(new DefaultToString()),
213 equals("<Instance of 'DefaultToString'>"));
214 });
215
216 test('with a custom [toString]', () {
217 expect(prettyPrint(new CustomToString()),
218 equals('CustomToString:<string representation>'));
219 });
220
221 test('with a custom [toString] and a private name', () {
222 expect(
223 prettyPrint(new _PrivateName()), equals('?:<string representation>'));
224 });
225 });
226
227 group('with an iterable', () {
228 test("that's not a list", () {
229 expect(prettyPrint([1, 2, 3, 4].map((n) => n * 2)),
230 equals("MappedListIterable:[2, 4, 6, 8]"));
231 });
232
233 test("that's not a list and has a private name", () {
234 expect(prettyPrint(new _PrivateNameIterable()), equals("?:[1, 2, 3]"));
235 });
236 });
237 }
OLDNEW
« no previous file with comments | « packages/matcher/test/operator_matchers_test.dart ('k') | packages/matcher/test/string_matchers_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698