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