| 1 | ### Pretty Printing Unit Tests
 | 
| 2 | 
 | 
| 3 | # This is a set of unit tests for pretty printing.
 | 
| 4 | #
 | 
| 5 | # Each test case has three parts: a printing `Width`, an `Input` value string,
 | 
| 6 | # and an `Expect`ed result. It ensures that:
 | 
| 7 | #
 | 
| 8 | #     PrettyPrinter.PrintValue(width, j8.Parser.ParseValue(value)) == expected
 | 
| 9 | 
 | 
| 10 | # Vim syntax highlighting:
 | 
| 11 | #     syn match section "#.*$"
 | 
| 12 | #     syn keyword kw Input Expect Width
 | 
| 13 | #     syn match punct '^>'
 | 
| 14 | #     syn match punct ' >'
 | 
| 15 | #     hi def link section Comment
 | 
| 16 | #     hi def link punct   Delimiter
 | 
| 17 | #     hi def link kw      Keyword
 | 
| 18 | # (Place in ~/.config/nvim/syntax/pretty_tests.vim,
 | 
| 19 | #  then enable with :set syntax=pretty_tests)
 | 
| 20 | 
 | 
| 21 | ## Primitives
 | 
| 22 | 
 | 
| 23 | Width  > 10
 | 
| 24 | 
 | 
| 25 | Input  > null
 | 
| 26 | Expect > null
 | 
| 27 | 
 | 
| 28 | Input  > true
 | 
| 29 | Expect > true
 | 
| 30 | 
 | 
| 31 | Input  > false
 | 
| 32 | Expect > false
 | 
| 33 | 
 | 
| 34 | Input  > 0
 | 
| 35 | Expect > 0
 | 
| 36 | 
 | 
| 37 | Input  > -123
 | 
| 38 | Expect > -123
 | 
| 39 | 
 | 
| 40 | Input  > 123456789123456789123456789
 | 
| 41 | Expect > 123456789123456789123456789
 | 
| 42 | 
 | 
| 43 | Input  > 0.0
 | 
| 44 | Expect > 0.0
 | 
| 45 | 
 | 
| 46 | Input  > 1.00
 | 
| 47 | Expect > 1.0
 | 
| 48 | 
 | 
| 49 | Input  > -0.000
 | 
| 50 | Expect > -0.0
 | 
| 51 | 
 | 
| 52 | Input  > 2.99792458e8
 | 
| 53 | Expect > 299792458.0
 | 
| 54 | 
 | 
| 55 | Input  >   "hello"
 | 
| 56 | Expect > "hello"
 | 
| 57 | 
 | 
| 58 | Input  > "\"For the `n`'th time,\" she said."
 | 
| 59 | Expect > "\"For the `n`'th time,\" she said."
 | 
| 60 | 
 | 
| 61 | ## Lists
 | 
| 62 | 
 | 
| 63 | Width  > 20
 | 
| 64 | Input  > []
 | 
| 65 | Expect > []
 | 
| 66 | 
 | 
| 67 | Input  > [100, 200, 300]
 | 
| 68 | 
 | 
| 69 | Width  > 20
 | 
| 70 | Expect > [100, 200, 300]
 | 
| 71 | 
 | 
| 72 | Width  > 12
 | 
| 73 | Expect
 | 
| 74 | > [
 | 
| 75 | >     100,
 | 
| 76 | >     200, 300
 | 
| 77 | > ]
 | 
| 78 | 
 | 
| 79 | Width  > 10
 | 
| 80 | Expect
 | 
| 81 | > [
 | 
| 82 | >     100,
 | 
| 83 | >     200,
 | 
| 84 | >     300
 | 
| 85 | > ]
 | 
| 86 | 
 | 
| 87 | Input  > [[100, 200, 300], [100, 200, 300]]
 | 
| 88 | 
 | 
| 89 | Width  > 20
 | 
| 90 | Expect
 | 
| 91 | > [
 | 
| 92 | >     [100, 200, 300],
 | 
| 93 | >     [100, 200, 300]
 | 
| 94 | > ]
 | 
| 95 | 
 | 
| 96 | Width  > 19
 | 
| 97 | Expect
 | 
| 98 | > [
 | 
| 99 | >     [
 | 
| 100 | >         100, 200,
 | 
| 101 | >         300
 | 
| 102 | >     ], [
 | 
| 103 | >         100, 200,
 | 
| 104 | >         300
 | 
| 105 | >     ]
 | 
| 106 | > ]
 | 
| 107 | 
 | 
| 108 | Width  > 11
 | 
| 109 | Expect
 | 
| 110 | > [
 | 
| 111 | >     [
 | 
| 112 | >         100,
 | 
| 113 | >         200,
 | 
| 114 | >         300
 | 
| 115 | >     ], [
 | 
| 116 | >         100,
 | 
| 117 | >         200,
 | 
| 118 | >         300
 | 
| 119 | >     ]
 | 
| 120 | > ]
 | 
| 121 | 
 | 
| 122 | ## Dictionaries
 | 
| 123 | 
 | 
| 124 | Width  > 10
 | 
| 125 | Input  > {}
 | 
| 126 | Expect > {}
 | 
| 127 | 
 | 
| 128 | Input  > {"x":100, "y":200, "z":300}
 | 
| 129 | 
 | 
| 130 | Width  > 24
 | 
| 131 | Expect > {x: 100, y: 200, z: 300}
 | 
| 132 | 
 | 
| 133 | Width  > 23
 | 
| 134 | Expect
 | 
| 135 | > {
 | 
| 136 | >     x: 100,
 | 
| 137 | >     y: 200,
 | 
| 138 | >     z: 300
 | 
| 139 | > }
 | 
| 140 | 
 | 
| 141 | Input
 | 
| 142 | > {
 | 
| 143 | >     "letters": {"1": "A", "2": "B", "3": "C"},
 | 
| 144 | >     "numbers": {"1": "one", "2": "two", "3": "three"}
 | 
| 145 | > }
 | 
| 146 | 
 | 
| 147 | Width > 51
 | 
| 148 | Expect
 | 
| 149 | > {
 | 
| 150 | >     letters: {"1": "A", "2": "B", "3": "C"},
 | 
| 151 | >     numbers: {"1": "one", "2": "two", "3": "three"}
 | 
| 152 | > }
 | 
| 153 | 
 | 
| 154 | Width > 44
 | 
| 155 | Expect
 | 
| 156 | > {
 | 
| 157 | >     letters: {"1": "A", "2": "B", "3": "C"},
 | 
| 158 | >     numbers: {
 | 
| 159 | >         "1": "one",
 | 
| 160 | >         "2": "two",
 | 
| 161 | >         "3": "three"
 | 
| 162 | >     }
 | 
| 163 | > }
 | 
| 164 | 
 | 
| 165 | Width > 43
 | 
| 166 | Expect
 | 
| 167 | > {
 | 
| 168 | >     letters: {
 | 
| 169 | >         "1": "A",
 | 
| 170 | >         "2": "B",
 | 
| 171 | >         "3": "C"
 | 
| 172 | >     },
 | 
| 173 | >     numbers: {
 | 
| 174 | >         "1": "one",
 | 
| 175 | >         "2": "two",
 | 
| 176 | >         "3": "three"
 | 
| 177 | >     }
 | 
| 178 | > }
 | 
| 179 | 
 | 
| 180 | ## Full width characters
 | 
| 181 | 
 | 
| 182 | Input  > ["世界", "您好"]
 | 
| 183 | 
 | 
| 184 | Width  > 16
 | 
| 185 | Expect > ["世界", "您好"]
 | 
| 186 | 
 | 
| 187 | Width  > 15
 | 
| 188 | Expect
 | 
| 189 | > [
 | 
| 190 | >     "世界",
 | 
| 191 | >     "您好"
 | 
| 192 | > ]
 | 
| 193 | 
 | 
| 194 | ## Tabular alignment
 | 
| 195 | 
 | 
| 196 | Input  > ["aaaaaaa", "bbb", "ccccc"]
 | 
| 197 | 
 | 
| 198 | Width  > 27
 | 
| 199 | Expect > ["aaaaaaa", "bbb", "ccccc"]
 | 
| 200 | 
 | 
| 201 | Width > 26
 | 
| 202 | Expect
 | 
| 203 | > [
 | 
| 204 | >     "aaaaaaa", "bbb",
 | 
| 205 | >     "ccccc"
 | 
| 206 | > ]
 | 
| 207 | 
 | 
| 208 | Width > 21
 | 
| 209 | Expect
 | 
| 210 | > [
 | 
| 211 | >     "aaaaaaa", "bbb",
 | 
| 212 | >     "ccccc"
 | 
| 213 | > ]
 | 
| 214 | 
 | 
| 215 | Width > 20
 | 
| 216 | Expect
 | 
| 217 | > [
 | 
| 218 | >     "aaaaaaa",
 | 
| 219 | >     "bbb",
 | 
| 220 | >     "ccccc"
 | 
| 221 | > ]
 | 
| 222 | 
 | 
| 223 | Input  > ["aaa", "bbbbbbb", "ccccc"]
 | 
| 224 | 
 | 
| 225 | Width  > 27
 | 
| 226 | Expect > ["aaa", "bbbbbbb", "ccccc"]
 | 
| 227 | 
 | 
| 228 | Width  > 26
 | 
| 229 | Expect
 | 
| 230 | > [
 | 
| 231 | >     "aaa",     "bbbbbbb",
 | 
| 232 | >     "ccccc"
 | 
| 233 | > ]
 | 
| 234 | 
 | 
| 235 | Input  > ["aaaaa", "bbbbbbb", "ccc"]
 | 
| 236 | 
 | 
| 237 | Width  > 27
 | 
| 238 | Expect > ["aaaaa", "bbbbbbb", "ccc"]
 | 
| 239 | 
 | 
| 240 | Width  > 26
 | 
| 241 | Expect
 | 
| 242 | > [
 | 
| 243 | >     "aaaaa",   "bbbbbbb",
 | 
| 244 | >     "ccc"
 | 
| 245 | > ]
 | 
| 246 | 
 | 
| 247 | Input  > { "simple_primitives": [null, false, true] }
 | 
| 248 | Width  > 30
 | 
| 249 | Expect
 | 
| 250 | > {
 | 
| 251 | >     simple_primitives: [
 | 
| 252 | >         null, false, true
 | 
| 253 | >     ]
 | 
| 254 | > }
 | 
| 255 | 
 | 
| 256 | # elements are too big for tabular alignment
 | 
| 257 | Input > ["aaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccc"]
 | 
| 258 | Width > 30
 | 
| 259 | Expect
 | 
| 260 | > [
 | 
| 261 | >     "aaaaaaaaaaaaaaaaaaa",
 | 
| 262 | >     "bbbbbbbbbbbbbbbbbbbbb",
 | 
| 263 | >     "cccccccccccccccccccc"
 | 
| 264 | > ]
 | 
| 265 | 
 | 
| 266 | 
 | 
| 267 | ## Everything at once
 | 
| 268 | 
 | 
| 269 | Input
 | 
| 270 | > {
 | 
| 271 | >     'primitives': {
 | 
| 272 | >         'simple_primitives': [null, false, true],
 | 
| 273 | >         'numeric_primitives': [-123456789, 123.456789],
 | 
| 274 | >         'stringy_primitives': 'string'
 | 
| 275 | >     },
 | 
| 276 | >     'compounds': [
 | 
| 277 | >         [1, 2, 3],
 | 
| 278 | >         {'dict': 'ionary'}
 | 
| 279 | >     ],
 | 
| 280 | >     'variety-pack': [
 | 
| 281 | >         null,
 | 
| 282 | >         ['Los', 'pollitos', 'dicen', 'pío', 'pío', 'pío'],
 | 
| 283 | >         [1, [2, [3, [4, [5, [6]]]]]],
 | 
| 284 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 285 | >     ]
 | 
| 286 | > }
 | 
| 287 | 
 | 
| 288 | Width > 58
 | 
| 289 | Expect
 | 
| 290 | > {
 | 
| 291 | >     primitives: {
 | 
| 292 | >         simple_primitives: [null, false, true],
 | 
| 293 | >         numeric_primitives: [-123456789, 123.456789],
 | 
| 294 | >         stringy_primitives: "string"
 | 
| 295 | >     },
 | 
| 296 | >     compounds: [[1, 2, 3], {dict: "ionary"}],
 | 
| 297 | >     "variety-pack": [
 | 
| 298 | >         null,
 | 
| 299 | >         ["Los", "pollitos", "dicen", "pío", "pío", "pío"],
 | 
| 300 | >         [1, [2, [3, [4, [5, [6]]]]]],
 | 
| 301 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 302 | >     ]
 | 
| 303 | > }
 | 
| 304 | 
 | 
| 305 | Width > 53
 | 
| 306 | Expect
 | 
| 307 | > {
 | 
| 308 | >     primitives: {
 | 
| 309 | >         simple_primitives: [null, false, true],
 | 
| 310 | >         numeric_primitives: [-123456789, 123.456789],
 | 
| 311 | >         stringy_primitives: "string"
 | 
| 312 | >     },
 | 
| 313 | >     compounds: [[1, 2, 3], {dict: "ionary"}],
 | 
| 314 | >     "variety-pack": [
 | 
| 315 | >         null,
 | 
| 316 | >         [
 | 
| 317 | >             "Los",      "pollitos", "dicen",
 | 
| 318 | >             "pío",      "pío",      "pío"
 | 
| 319 | >         ],
 | 
| 320 | >         [1, [2, [3, [4, [5, [6]]]]]],
 | 
| 321 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 322 | >     ]
 | 
| 323 | > }
 | 
| 324 | 
 | 
| 325 | Width > 47
 | 
| 326 | Expect
 | 
| 327 | > {
 | 
| 328 | >     primitives: {
 | 
| 329 | >         simple_primitives: [null, false, true],
 | 
| 330 | >         numeric_primitives: [
 | 
| 331 | >             -123456789, 123.456789
 | 
| 332 | >         ],
 | 
| 333 | >         stringy_primitives: "string"
 | 
| 334 | >     },
 | 
| 335 | >     compounds: [[1, 2, 3], {dict: "ionary"}],
 | 
| 336 | >     "variety-pack": [
 | 
| 337 | >         null,
 | 
| 338 | >         [
 | 
| 339 | >             "Los",      "pollitos", "dicen",
 | 
| 340 | >             "pío",      "pío",      "pío"
 | 
| 341 | >         ],
 | 
| 342 | >         [1, [2, [3, [4, [5, [6]]]]]],
 | 
| 343 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 344 | >     ]
 | 
| 345 | > }
 | 
| 346 | 
 | 
| 347 | Width > 37
 | 
| 348 | Expect
 | 
| 349 | > {
 | 
| 350 | >     primitives: {
 | 
| 351 | >         simple_primitives: [
 | 
| 352 | >             null, false, true
 | 
| 353 | >         ],
 | 
| 354 | >         numeric_primitives: [
 | 
| 355 | >             -123456789, 123.456789
 | 
| 356 | >         ],
 | 
| 357 | >         stringy_primitives: "string"
 | 
| 358 | >     },
 | 
| 359 | >     compounds: [
 | 
| 360 | >         [1, 2, 3], {dict: "ionary"}
 | 
| 361 | >     ],
 | 
| 362 | >     "variety-pack": [
 | 
| 363 | >         null,
 | 
| 364 | >         [
 | 
| 365 | >             "Los",      "pollitos",
 | 
| 366 | >             "dicen",    "pío",
 | 
| 367 | >             "pío",      "pío"
 | 
| 368 | >         ],
 | 
| 369 | >         [1, [2, [3, [4, [5, [6]]]]]],
 | 
| 370 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 371 | >     ]
 | 
| 372 | > }
 | 
| 373 | 
 | 
| 374 | Width > 36
 | 
| 375 | Expect
 | 
| 376 | > {
 | 
| 377 | >     primitives: {
 | 
| 378 | >         simple_primitives: [
 | 
| 379 | >             null, false, true
 | 
| 380 | >         ],
 | 
| 381 | >         numeric_primitives: [
 | 
| 382 | >             -123456789, 123.456789
 | 
| 383 | >         ],
 | 
| 384 | >         stringy_primitives: "string"
 | 
| 385 | >     },
 | 
| 386 | >     compounds: [
 | 
| 387 | >         [1, 2, 3], {dict: "ionary"}
 | 
| 388 | >     ],
 | 
| 389 | >     "variety-pack": [
 | 
| 390 | >         null,
 | 
| 391 | >         [
 | 
| 392 | >             "Los",      "pollitos",
 | 
| 393 | >             "dicen",    "pío",
 | 
| 394 | >             "pío",      "pío"
 | 
| 395 | >         ],
 | 
| 396 | >         [
 | 
| 397 | >             1,
 | 
| 398 | >             [2, [3, [4, [5, [6]]]]]
 | 
| 399 | >         ],
 | 
| 400 | >         [[[[[5], 4], 3], 2], 1]
 | 
| 401 | >     ]
 | 
| 402 | > }
 | 
| 403 | 
 | 
| 404 | Width > 30
 | 
| 405 | Expect
 | 
| 406 | > {
 | 
| 407 | >     primitives: {
 | 
| 408 | >         simple_primitives: [
 | 
| 409 | >             null, false, true
 | 
| 410 | >         ],
 | 
| 411 | >         numeric_primitives: [
 | 
| 412 | >             -123456789,
 | 
| 413 | >             123.456789
 | 
| 414 | >         ],
 | 
| 415 | >         stringy_primitives: "string"
 | 
| 416 | >     },
 | 
| 417 | >     compounds: [
 | 
| 418 | >         [1, 2, 3],        {
 | 
| 419 | >             dict: "ionary"
 | 
| 420 | >         }
 | 
| 421 | >     ],
 | 
| 422 | >     "variety-pack": [
 | 
| 423 | >         null,
 | 
| 424 | >         [
 | 
| 425 | >             "Los",
 | 
| 426 | >             "pollitos",
 | 
| 427 | >             "dicen",    "pío",
 | 
| 428 | >             "pío",      "pío"
 | 
| 429 | >         ],
 | 
| 430 | >         [
 | 
| 431 | >             1,
 | 
| 432 | >             [
 | 
| 433 | >                 2,
 | 
| 434 | >                 [
 | 
| 435 | >                     3,
 | 
| 436 | >                     [
 | 
| 437 | >                         4,
 | 
| 438 | >                         [
 | 
| 439 | >                             5,
 | 
| 440 | >                             [
 | 
| 441 | >                                 6
 | 
| 442 | >                             ]
 | 
| 443 | >                         ]
 | 
| 444 | >                     ]
 | 
| 445 | >                 ]
 | 
| 446 | >             ]
 | 
| 447 | >         ],
 | 
| 448 | >         [
 | 
| 449 | >             [
 | 
| 450 | >                 [[[5], 4], 3],
 | 
| 451 | >                 2
 | 
| 452 | >             ], 1
 | 
| 453 | >         ]
 | 
| 454 | >     ]
 | 
| 455 | > }
 |