| 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 '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 import 'package:unittest/unittest.dart' show group, test; |
| 10 | 10 |
| 11 void main() { | 11 void main() { |
| 12 test('with primitive objects', () { | 12 test('with primitive objects', () { |
| 13 expect(prettyPrint(12), equals('<12>')); | 13 expect(prettyPrint(12), equals('<12>')); |
| 14 expect(prettyPrint(12.13), equals('<12.13>')); | 14 expect(prettyPrint(12.13), equals('<12.13>')); |
| 15 expect(prettyPrint(true), equals('<true>')); | 15 expect(prettyPrint(true), equals('<true>')); |
| 16 expect(prettyPrint(null), equals('<null>')); | 16 expect(prettyPrint(null), equals('<null>')); |
| 17 expect(prettyPrint(() => 12), | 17 expect(prettyPrint(() => 12), matches(r'<Closure(: \(\) => dynamic)?>')); |
| 18 matches(r'<Closure(: \(\) => dynamic)?>')); | |
| 19 }); | 18 }); |
| 20 | 19 |
| 21 group('with a string', () { | 20 group('with a string', () { |
| 22 test('containing simple characters', () { | 21 test('containing simple characters', () { |
| 23 expect(prettyPrint('foo'), equals("'foo'")); | 22 expect(prettyPrint('foo'), equals("'foo'")); |
| 24 }); | 23 }); |
| 25 | 24 |
| 26 test('containing newlines', () { | 25 test('containing newlines', () { |
| 27 expect(prettyPrint('foo\nbar\nbaz'), equals( | 26 expect(prettyPrint('foo\nbar\nbaz'), equals("'foo\\n'\n" |
| 28 "'foo\\n'\n" | |
| 29 " 'bar\\n'\n" | 27 " 'bar\\n'\n" |
| 30 " 'baz'")); | 28 " 'baz'")); |
| 31 }); | 29 }); |
| 32 | 30 |
| 33 test('containing escapable characters', () { | 31 test('containing escapable characters', () { |
| 34 expect(prettyPrint("foo\rbar\tbaz'qux"), | 32 expect( |
| 35 equals("'foo\\rbar\\tbaz\\'qux'")); | 33 prettyPrint("foo\rbar\tbaz'qux"), equals("'foo\\rbar\\tbaz\\'qux'")); |
| 36 }); | 34 }); |
| 37 }); | 35 }); |
| 38 | 36 |
| 39 group('with an iterable', () { | 37 group('with an iterable', () { |
| 40 test('containing primitive objects', () { | 38 test('containing primitive objects', () { |
| 41 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']")); | 39 expect(prettyPrint([1, true, 'foo']), equals("[1, true, 'foo']")); |
| 42 }); | 40 }); |
| 43 | 41 |
| 44 test('containing a multiline string', () { | 42 test('containing a multiline string', () { |
| 45 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n" | 43 expect(prettyPrint(['foo', 'bar\nbaz\nbip', 'qux']), equals("[\n" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 71 " 4,\n" | 69 " 4,\n" |
| 72 " 5,\n" | 70 " 5,\n" |
| 73 " 6,\n" | 71 " 6,\n" |
| 74 " 7,\n" | 72 " 7,\n" |
| 75 " 8,\n" | 73 " 8,\n" |
| 76 " 9\n" | 74 " 9\n" |
| 77 "]")); | 75 "]")); |
| 78 }); | 76 }); |
| 79 | 77 |
| 80 test("factors indentation into maxLineLength", () { | 78 test("factors indentation into maxLineLength", () { |
| 81 expect(prettyPrint([ | 79 expect(prettyPrint(["foo\nbar", [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],], |
| 82 "foo\nbar", | 80 maxLineLength: 30), equals("[\n" |
| 83 [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | |
| 84 ], maxLineLength: 30), equals("[\n" | |
| 85 " 'foo\\n'\n" | 81 " 'foo\\n'\n" |
| 86 " 'bar',\n" | 82 " 'bar',\n" |
| 87 " [\n" | 83 " [\n" |
| 88 " 0,\n" | 84 " 0,\n" |
| 89 " 1,\n" | 85 " 1,\n" |
| 90 " 2,\n" | 86 " 2,\n" |
| 91 " 3,\n" | 87 " 3,\n" |
| 92 " 4,\n" | 88 " 4,\n" |
| 93 " 5,\n" | 89 " 5,\n" |
| 94 " 6,\n" | 90 " 6,\n" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 equals("{\n" | 162 equals("{\n" |
| 167 " '0': 1,\n" | 163 " '0': 1,\n" |
| 168 " '2': 3,\n" | 164 " '2': 3,\n" |
| 169 " '4': 5,\n" | 165 " '4': 5,\n" |
| 170 " '6': 7\n" | 166 " '6': 7\n" |
| 171 "}")); | 167 "}")); |
| 172 }); | 168 }); |
| 173 | 169 |
| 174 test("factors indentation into maxLineLength", () { | 170 test("factors indentation into maxLineLength", () { |
| 175 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}], | 171 expect(prettyPrint(["foo\nbar", {'0': 1, '2': 3, '4': 5, '6': 7}], |
| 176 maxLineLength: 32), | 172 maxLineLength: 32), equals("[\n" |
| 177 equals("[\n" | 173 " 'foo\\n'\n" |
| 178 " 'foo\\n'\n" | 174 " 'bar',\n" |
| 179 " 'bar',\n" | 175 " {\n" |
| 180 " {\n" | 176 " '0': 1,\n" |
| 181 " '0': 1,\n" | 177 " '2': 3,\n" |
| 182 " '2': 3,\n" | 178 " '4': 5,\n" |
| 183 " '4': 5,\n" | 179 " '6': 7\n" |
| 184 " '6': 7\n" | 180 " }\n" |
| 185 " }\n" | 181 "]")); |
| 186 "]")); | |
| 187 }); | 182 }); |
| 188 | 183 |
| 189 test("that's under maxItems", () { | 184 test("that's under maxItems", () { |
| 190 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), | 185 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 4), |
| 191 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); | 186 equals("{'0': 1, '2': 3, '4': 5, '6': 7}")); |
| 192 }); | 187 }); |
| 193 | 188 |
| 194 test("that's over maxItems", () { | 189 test("that's over maxItems", () { |
| 195 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), | 190 expect(prettyPrint({'0': 1, '2': 3, '4': 5, '6': 7}, maxItems: 3), |
| 196 equals("{'0': 1, '2': 3, ...}")); | 191 equals("{'0': 1, '2': 3, ...}")); |
| 197 }); | 192 }); |
| 198 }); | 193 }); |
| 199 } | 194 } |
| OLD | NEW |