OLD | NEW |
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 matcher.pretty_print_test; | 5 library matcher.pretty_print_test; |
6 | 6 |
| 7 import 'dart:collection'; |
| 8 |
7 import 'package:matcher/matcher.dart'; | 9 import 'package:matcher/matcher.dart'; |
8 import 'package:matcher/src/pretty_print.dart'; | 10 import 'package:matcher/src/pretty_print.dart'; |
9 import 'package:unittest/unittest.dart' show group, test, expect; | 11 import 'package:unittest/unittest.dart' show group, test, expect; |
10 | 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 |
11 void main() { | 27 void main() { |
12 test('with primitive objects', () { | 28 test('with primitive objects', () { |
13 expect(prettyPrint(12), equals('<12>')); | 29 expect(prettyPrint(12), equals('<12>')); |
14 expect(prettyPrint(12.13), equals('<12.13>')); | 30 expect(prettyPrint(12.13), equals('<12.13>')); |
15 expect(prettyPrint(true), equals('<true>')); | 31 expect(prettyPrint(true), equals('<true>')); |
16 expect(prettyPrint(null), equals('<null>')); | 32 expect(prettyPrint(null), equals('<null>')); |
17 expect(prettyPrint(() => 12), matches(r'<Closure(: \(\) => dynamic)?>')); | 33 expect(prettyPrint(() => 12), matches(r'<Closure(: \(\) => dynamic)?>')); |
18 }); | 34 }); |
19 | 35 |
20 group('with a string', () { | 36 group('with a string', () { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 test("that's under maxItems", () { | 200 test("that's under maxItems", () { |
185 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), | 201 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), |
186 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); | 202 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); |
187 }); | 203 }); |
188 | 204 |
189 test("that's over maxItems", () { | 205 test("that's over maxItems", () { |
190 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), | 206 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), |
191 equals("{'0': 1, '2': 3, ...}")); | 207 equals("{'0': 1, '2': 3, ...}")); |
192 }); | 208 }); |
193 }); | 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 }); |
194 } | 237 } |
OLD | NEW |