| OLD | NEW |
| (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 'package:matcher/matcher.dart'; | |
| 8 import 'package:matcher/src/pretty_print.dart'; | |
| 9 import 'package:unittest/unittest.dart' show group, test; | |
| 10 | |
| 11 void main() { | |
| 12 test('with primitive objects', () { | |
| 13 expect(prettyPrint(12), equals('<12>')); | |
| 14 expect(prettyPrint(12.13), equals('<12.13>')); | |
| 15 expect(prettyPrint(true), equals('<true>')); | |
| 16 expect(prettyPrint(null), equals('<null>')); | |
| 17 expect(prettyPrint(() => 12), | |
| 18 matches(r'<Closure(: \(\) => dynamic)?>')); | |
| 19 }); | |
| 20 | |
| 21 group('with a string', () { | |
| 22 test('containing simple characters', () { | |
| 23 expect(prettyPrint('foo'), equals("'foo'")); | |
| 24 }); | |
| 25 | |
| 26 test('containing newlines', () { | |
| 27 expect(prettyPrint('foo\nbar\nbaz'), equals( | |
| 28 "'foo\\n'\n" | |
| 29 " 'bar\\n'\n" | |
| 30 " 'baz'")); | |
| 31 }); | |
| 32 | |
| 33 test('containing escapable characters', () { | |
| 34 expect(prettyPrint("foo\rbar\tbaz'qux"), | |
| 35 equals("'foo\\rbar\\tbaz\\'qux'")); | |
| 36 }); | |
| 37 }); | |
| 38 | |
| 39 group('with an iterable', () { | |
| 40 test('containing primitive objects', () { | |
| 41 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']")); | |
| 42 }); | |
| 43 | |
| 44 test('containing a multiline string', () { | |
| 45 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n" | |
| 46 " 'foo',\n" | |
| 47 " 'bar\\n'\n" | |
| 48 " 'baz\\n'\n" | |
| 49 " 'bip',\n" | |
| 50 " 'qux'\n" | |
| 51 "]")); | |
| 52 }); | |
| 53 | |
| 54 test('containing a matcher', () { | |
| 55 expect(prettyPrint(['foo', endsWith('qux')]), | |
| 56 equals("['foo', <a string ending with 'qux'>]")); | |
| 57 }); | |
| 58 | |
| 59 test("that's under maxLineLength", () { | |
| 60 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 30), | |
| 61 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); | |
| 62 }); | |
| 63 | |
| 64 test("that's over maxLineLength", () { | |
| 65 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxLineLength: 29), | |
| 66 equals("[\n" | |
| 67 " 0,\n" | |
| 68 " 1,\n" | |
| 69 " 2,\n" | |
| 70 " 3,\n" | |
| 71 " 4,\n" | |
| 72 " 5,\n" | |
| 73 " 6,\n" | |
| 74 " 7,\n" | |
| 75 " 8,\n" | |
| 76 " 9\n" | |
| 77 "]")); | |
| 78 }); | |
| 79 | |
| 80 test("factors indentation into maxLineLength", () { | |
| 81 expect(prettyPrint([ | |
| 82 "foo\nbar", | |
| 83 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | |
| 84 ], maxLineLength: 30), equals("[\n" | |
| 85 " 'foo\\n'\n" | |
| 86 " 'bar',\n" | |
| 87 " [\n" | |
| 88 " 0,\n" | |
| 89 " 1,\n" | |
| 90 " 2,\n" | |
| 91 " 3,\n" | |
| 92 " 4,\n" | |
| 93 " 5,\n" | |
| 94 " 6,\n" | |
| 95 " 7,\n" | |
| 96 " 8,\n" | |
| 97 " 9\n" | |
| 98 " ]\n" | |
| 99 "]")); | |
| 100 }); | |
| 101 | |
| 102 test("that's under maxItems", () { | |
| 103 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 10), | |
| 104 equals("[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]")); | |
| 105 }); | |
| 106 | |
| 107 test("that's over maxItems", () { | |
| 108 expect(prettyPrint([0, 1, 2, 3, 4, 5, 6, 7, 8, 9], maxItems: 9), | |
| 109 equals("[0, 1, 2, 3, 4, 5, 6, 7, ...]")); | |
| 110 }); | |
| 111 | |
| 112 test("that's recursive", () { | |
| 113 var list = [1, 2, 3]; | |
| 114 list.add(list); | |
| 115 expect(prettyPrint(list), equals("[1, 2, 3, (recursive)]")); | |
| 116 }); | |
| 117 }); | |
| 118 | |
| 119 group("with a map", () { | |
| 120 test('containing primitive objects', () { | |
| 121 expect(prettyPrint({'foo': 1, 'bar': true}), | |
| 122 equals("{'foo': 1, 'bar': true}")); | |
| 123 }); | |
| 124 | |
| 125 test('containing a multiline string key', () { | |
| 126 expect(prettyPrint({'foo\nbar': 1, 'bar': true}), equals("{\n" | |
| 127 " 'foo\\n'\n" | |
| 128 " 'bar': 1,\n" | |
| 129 " 'bar': true\n" | |
| 130 "}")); | |
| 131 }); | |
| 132 | |
| 133 test('containing a multiline string value', () { | |
| 134 expect(prettyPrint({'foo': 'bar\nbaz', 'qux': true}), equals("{\n" | |
| 135 " 'foo': 'bar\\n'\n" | |
| 136 " 'baz',\n" | |
| 137 " 'qux': true\n" | |
| 138 "}")); | |
| 139 }); | |
| 140 | |
| 141 test('containing a multiline string key/value pair', () { | |
| 142 expect(prettyPrint({'foo\nbar': 'baz\nqux'}), equals("{\n" | |
| 143 " 'foo\\n'\n" | |
| 144 " 'bar': 'baz\\n'\n" | |
| 145 " 'qux'\n" | |
| 146 "}")); | |
| 147 }); | |
| 148 | |
| 149 test('containing a matcher key', () { | |
| 150 expect(prettyPrint({endsWith('bar'): 'qux'}), | |
| 151 equals("{<a string ending with 'bar'>: 'qux'}")); | |
| 152 }); | |
| 153 | |
| 154 test('containing a matcher value', () { | |
| 155 expect(prettyPrint({'foo': endsWith('qux')}), | |
| 156 equals("{'foo': <a string ending with 'qux'>}")); | |
| 157 }); | |
| 158 | |
| 159 test("that's under maxLineLength", () { | |
| 160 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 32), | |
| 161 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); | |
| 162 }); | |
| 163 | |
| 164 test("that's over maxLineLength", () { | |
| 165 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxLineLength: 31), | |
| 166 equals("{\n" | |
| 167 " '0': 1,\n" | |
| 168 " '2': 3,\n" | |
| 169 " '4': 5,\n" | |
| 170 " '6': 7\n" | |
| 171 "}")); | |
| 172 }); | |
| 173 | |
| 174 test("factors indentation into maxLineLength", () { | |
| 175 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}], | |
| 176 maxLineLength: 32), | |
| 177 equals("[\n" | |
| 178 " 'foo\\n'\n" | |
| 179 " 'bar',\n" | |
| 180 " {\n" | |
| 181 " '0': 1,\n" | |
| 182 " '2': 3,\n" | |
| 183 " '4': 5,\n" | |
| 184 " '6': 7\n" | |
| 185 " }\n" | |
| 186 "]")); | |
| 187 }); | |
| 188 | |
| 189 test("that's under maxItems", () { | |
| 190 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), | |
| 191 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); | |
| 192 }); | |
| 193 | |
| 194 test("that's over maxItems", () { | |
| 195 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), | |
| 196 equals("{'0': 1, '2': 3, ...}")); | |
| 197 }); | |
| 198 }); | |
| 199 } | |
| OLD | NEW |