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