| 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 import 'dart:collection'; | |
| 6 | |
| 7 import 'package:unittest/src/pretty_print.dart'; | 5 import 'package:unittest/src/pretty_print.dart'; |
| 8 import 'package:unittest/unittest.dart'; | 6 import 'package:unittest/unittest.dart'; |
| 9 | 7 |
| 10 class DefaultToString {} | |
| 11 | |
| 12 class CustomToString { | |
| 13 String toString() => "string representation"; | |
| 14 } | |
| 15 | |
| 16 class _PrivateName { | |
| 17 String toString() => "string representation"; | |
| 18 } | |
| 19 | |
| 20 class _PrivateNameIterable extends IterableMixin { | |
| 21 Iterator get iterator => [1, 2, 3].iterator; | |
| 22 } | |
| 23 | |
| 24 void main() { | 8 void main() { |
| 25 test('with primitive objects', () { | 9 test('with primitive objects', () { |
| 26 expect(prettyPrint(12), equals('<12>')); | 10 expect(prettyPrint(12), equals('<12>')); |
| 27 expect(prettyPrint(12.13), equals('<12.13>')); | 11 expect(prettyPrint(12.13), equals('<12.13>')); |
| 28 expect(prettyPrint(true), equals('<true>')); | 12 expect(prettyPrint(true), equals('<true>')); |
| 29 expect(prettyPrint(null), equals('<null>')); | 13 expect(prettyPrint(null), equals('<null>')); |
| 30 expect(prettyPrint(() => 12), | 14 expect(prettyPrint(() => 12), |
| 31 matches(r'<Closure(: \(dynamic\) => dynamic)?>')); | 15 matches(r'<Closure(: \(dynamic\) => dynamic)?>')); |
| 32 }); | 16 }); |
| 33 | 17 |
| 34 test('with an object with a default [toString]', () { | |
| 35 expect(prettyPrint(new DefaultToString()), | |
| 36 equals("<Instance of 'DefaultToString'>")); | |
| 37 }); | |
| 38 | |
| 39 test('with an object with a custom [toString]', () { | |
| 40 expect(prettyPrint(new CustomToString()), | |
| 41 equals('CustomToString:<string representation>')); | |
| 42 }); | |
| 43 | |
| 44 test('with an object with a custom [toString] and a private name', () { | |
| 45 expect(prettyPrint(new _PrivateName()), | |
| 46 equals('?:<string representation>')); | |
| 47 }); | |
| 48 | |
| 49 group('with a string', () { | 18 group('with a string', () { |
| 50 test('containing simple characters', () { | 19 test('containing simple characters', () { |
| 51 expect(prettyPrint('foo'), equals("'foo'")); | 20 expect(prettyPrint('foo'), equals("'foo'")); |
| 52 }); | 21 }); |
| 53 | 22 |
| 54 test('containing newlines', () { | 23 test('containing newlines', () { |
| 55 expect(prettyPrint('foo\nbar\nbaz'), equals( | 24 expect(prettyPrint('foo\nbar\nbaz'), equals( |
| 56 "'foo\\n'\n" | 25 "'foo\\n'\n" |
| 57 " 'bar\\n'\n" | 26 " 'bar\\n'\n" |
| 58 " 'baz'")); | 27 " 'baz'")); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 test("that's under maxItems", () { | 94 test("that's under maxItems", () { |
| 126 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10), | 95 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10), |
| 127 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); | 96 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); |
| 128 }); | 97 }); |
| 129 | 98 |
| 130 test("that's over maxItems", () { | 99 test("that's over maxItems", () { |
| 131 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9), | 100 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9), |
| 132 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]")); | 101 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]")); |
| 133 }); | 102 }); |
| 134 | 103 |
| 135 test("that's not a list", () { | |
| 136 expect(prettyPrint([1, 2, 3, 4].map((n) => n * 2)), | |
| 137 equals("MappedListIterable:[2, 4, 6, 8]")); | |
| 138 }); | |
| 139 | |
| 140 test("that's not a list and has a private name", () { | |
| 141 expect(prettyPrint(new _PrivateNameIterable()), | |
| 142 equals("?:[1, 2, 3]")); | |
| 143 }); | |
| 144 | |
| 145 test("that's recursive", () { | 104 test("that's recursive", () { |
| 146 var list = [1, 2, 3]; | 105 var list = [1, 2, 3]; |
| 147 list.add(list); | 106 list.add(list); |
| 148 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]")); | 107 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]")); |
| 149 }); | 108 }); |
| 150 }); | 109 }); |
| 151 | 110 |
| 152 group("with a map", () { | 111 group("with a map", () { |
| 153 test('containing primitive objects', () { | 112 test('containing primitive objects', () { |
| 154 expect(prettyPrint({'foo': 1, 'bar': true}), | 113 expect(prettyPrint({'foo': 1, 'bar': true}), |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), | 172 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), |
| 214 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); | 173 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); |
| 215 }); | 174 }); |
| 216 | 175 |
| 217 test("that's over maxItems", () { | 176 test("that's over maxItems", () { |
| 218 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), | 177 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), |
| 219 equals("{'0': 1, '2': 3, ...}")); | 178 equals("{'0': 1, '2': 3, ...}")); |
| 220 }); | 179 }); |
| 221 }); | 180 }); |
| 222 } | 181 } |
| OLD | NEW |