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