| 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 Constant
|
| 16 | # hi def link punct Statement
|
| 17 | # hi def link kw PreProc
|
| 18 | # (Place in ~/.config/nvim/syntax/pretty_tests.vim,
|
| 19 | # then enable with :set syntax=pretty_tests.vim)
|
| 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 > 10
|
| 73 | Expect
|
| 74 | > [
|
| 75 | > 100,
|
| 76 | > 200,
|
| 77 | > 300
|
| 78 | > ]
|
| 79 |
|
| 80 | Input > [[100, 200, 300], [100, 200, 300]]
|
| 81 |
|
| 82 | Width > 20
|
| 83 | Expect
|
| 84 | > [
|
| 85 | > [100, 200, 300],
|
| 86 | > [100, 200, 300]
|
| 87 | > ]
|
| 88 |
|
| 89 | Width > 17
|
| 90 | Expect
|
| 91 | > [
|
| 92 | > [
|
| 93 | > 100,
|
| 94 | > 200,
|
| 95 | > 300
|
| 96 | > ],
|
| 97 | > [100, 200, 300]
|
| 98 | > ]
|
| 99 |
|
| 100 | Width > 16
|
| 101 | Expect
|
| 102 | > [
|
| 103 | > [
|
| 104 | > 100,
|
| 105 | > 200,
|
| 106 | > 300
|
| 107 | > ],
|
| 108 | > [
|
| 109 | > 100,
|
| 110 | > 200,
|
| 111 | > 300
|
| 112 | > ]
|
| 113 | > ]
|
| 114 |
|
| 115 | ## Dictionaries
|
| 116 |
|
| 117 | Width > 10
|
| 118 | Input > {}
|
| 119 | Expect > {}
|
| 120 |
|
| 121 | Input > {"x":100, "y":200, "z":300}
|
| 122 |
|
| 123 | Width > 24
|
| 124 | Expect > {x: 100, y: 200, z: 300}
|
| 125 |
|
| 126 | Width > 23
|
| 127 | Expect
|
| 128 | > {
|
| 129 | > x: 100,
|
| 130 | > y: 200,
|
| 131 | > z: 300
|
| 132 | > }
|
| 133 |
|
| 134 | Input
|
| 135 | > {
|
| 136 | > "letters": {"1": "A", "2": "B", "3": "C"},
|
| 137 | > "numbers": {"1": "one", "2": "two", "3": "three"}
|
| 138 | > }
|
| 139 |
|
| 140 | Width > 49
|
| 141 | Expect
|
| 142 | > {
|
| 143 | > letters: {"1": "A", "2": "B", "3": "C"},
|
| 144 | > numbers: {"1": "one", "2": "two", "3": "three"}
|
| 145 | > }
|
| 146 |
|
| 147 | Width > 42
|
| 148 | Expect
|
| 149 | > {
|
| 150 | > letters: {"1": "A", "2": "B", "3": "C"},
|
| 151 | > numbers: {
|
| 152 | > "1": "one",
|
| 153 | > "2": "two",
|
| 154 | > "3": "three"
|
| 155 | > }
|
| 156 | > }
|
| 157 |
|
| 158 | Width > 41
|
| 159 | Expect
|
| 160 | > {
|
| 161 | > letters: {
|
| 162 | > "1": "A",
|
| 163 | > "2": "B",
|
| 164 | > "3": "C"
|
| 165 | > },
|
| 166 | > numbers: {
|
| 167 | > "1": "one",
|
| 168 | > "2": "two",
|
| 169 | > "3": "three"
|
| 170 | > }
|
| 171 | > }
|
| 172 |
|
| 173 | ## Full width characters
|
| 174 |
|
| 175 | Input > ["世界", "您好"]
|
| 176 |
|
| 177 | Width > 16
|
| 178 | Expect > ["世界", "您好"]
|
| 179 |
|
| 180 | Width > 15
|
| 181 | Expect
|
| 182 | > [
|
| 183 | > "世界",
|
| 184 | > "您好"
|
| 185 | > ]
|
| 186 |
|
| 187 | ## Everything at once
|
| 188 |
|
| 189 | Input
|
| 190 | > {
|
| 191 | > 'primitives': {
|
| 192 | > 'simple_primitives': [null, false, true],
|
| 193 | > 'numeric_primitives': [-123456789, 123.456789],
|
| 194 | > 'stringy_primitives': 'string'
|
| 195 | > },
|
| 196 | > 'compounds': [
|
| 197 | > [1, 2, 3],
|
| 198 | > {'dict': 'ionary'}
|
| 199 | > ],
|
| 200 | > 'variety-pack': [
|
| 201 | > null,
|
| 202 | > ['Los', 'pollitos', 'dicen', 'pío', 'pío', 'pío'],
|
| 203 | > [1, [2, [3, [4, [5, [6]]]]]],
|
| 204 | > [[[[[5], 4], 3], 2], 1]
|
| 205 | > ]
|
| 206 | > }
|
| 207 |
|
| 208 | Width > 54
|
| 209 | Expect
|
| 210 | > {
|
| 211 | > primitives: {
|
| 212 | > simple_primitives: [null, false, true],
|
| 213 | > numeric_primitives: [-123456789, 123.456789],
|
| 214 | > stringy_primitives: "string"
|
| 215 | > },
|
| 216 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
| 217 | > "variety-pack": [
|
| 218 | > null,
|
| 219 | > ["Los", "pollitos", "dicen", "pío", "pío", "pío"],
|
| 220 | > [1, [2, [3, [4, [5, [6]]]]]],
|
| 221 | > [[[[[5], 4], 3], 2], 1]
|
| 222 | > ]
|
| 223 | > }
|
| 224 |
|
| 225 | Width > 49
|
| 226 | Expect
|
| 227 | > {
|
| 228 | > primitives: {
|
| 229 | > simple_primitives: [null, false, true],
|
| 230 | > numeric_primitives: [-123456789, 123.456789],
|
| 231 | > stringy_primitives: "string"
|
| 232 | > },
|
| 233 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
| 234 | > "variety-pack": [
|
| 235 | > null,
|
| 236 | > [
|
| 237 | > "Los",
|
| 238 | > "pollitos",
|
| 239 | > "dicen",
|
| 240 | > "pío",
|
| 241 | > "pío",
|
| 242 | > "pío"
|
| 243 | > ],
|
| 244 | > [1, [2, [3, [4, [5, [6]]]]]],
|
| 245 | > [[[[[5], 4], 3], 2], 1]
|
| 246 | > ]
|
| 247 | > }
|
| 248 |
|
| 249 | Width > 43
|
| 250 | Expect
|
| 251 | > {
|
| 252 | > primitives: {
|
| 253 | > simple_primitives: [null, false, true],
|
| 254 | > numeric_primitives: [
|
| 255 | > -123456789,
|
| 256 | > 123.456789
|
| 257 | > ],
|
| 258 | > stringy_primitives: "string"
|
| 259 | > },
|
| 260 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
| 261 | > "variety-pack": [
|
| 262 | > null,
|
| 263 | > [
|
| 264 | > "Los",
|
| 265 | > "pollitos",
|
| 266 | > "dicen",
|
| 267 | > "pío",
|
| 268 | > "pío",
|
| 269 | > "pío"
|
| 270 | > ],
|
| 271 | > [1, [2, [3, [4, [5, [6]]]]]],
|
| 272 | > [[[[[5], 4], 3], 2], 1]
|
| 273 | > ]
|
| 274 | > }
|
| 275 |
|
| 276 | Width > 33
|
| 277 | Expect
|
| 278 | > {
|
| 279 | > primitives: {
|
| 280 | > simple_primitives: [
|
| 281 | > null,
|
| 282 | > false,
|
| 283 | > true
|
| 284 | > ],
|
| 285 | > numeric_primitives: [
|
| 286 | > -123456789,
|
| 287 | > 123.456789
|
| 288 | > ],
|
| 289 | > stringy_primitives: "string"
|
| 290 | > },
|
| 291 | > compounds: [
|
| 292 | > [1, 2, 3],
|
| 293 | > {dict: "ionary"}
|
| 294 | > ],
|
| 295 | > "variety-pack": [
|
| 296 | > null,
|
| 297 | > [
|
| 298 | > "Los",
|
| 299 | > "pollitos",
|
| 300 | > "dicen",
|
| 301 | > "pío",
|
| 302 | > "pío",
|
| 303 | > "pío"
|
| 304 | > ],
|
| 305 | > [1, [2, [3, [4, [5, [6]]]]]],
|
| 306 | > [[[[[5], 4], 3], 2], 1]
|
| 307 | > ]
|
| 308 | > }
|
| 309 |
|
| 310 | Width > 32
|
| 311 | Expect
|
| 312 | > {
|
| 313 | > primitives: {
|
| 314 | > simple_primitives: [
|
| 315 | > null,
|
| 316 | > false,
|
| 317 | > true
|
| 318 | > ],
|
| 319 | > numeric_primitives: [
|
| 320 | > -123456789,
|
| 321 | > 123.456789
|
| 322 | > ],
|
| 323 | > stringy_primitives: "string"
|
| 324 | > },
|
| 325 | > compounds: [
|
| 326 | > [1, 2, 3],
|
| 327 | > {dict: "ionary"}
|
| 328 | > ],
|
| 329 | > "variety-pack": [
|
| 330 | > null,
|
| 331 | > [
|
| 332 | > "Los",
|
| 333 | > "pollitos",
|
| 334 | > "dicen",
|
| 335 | > "pío",
|
| 336 | > "pío",
|
| 337 | > "pío"
|
| 338 | > ],
|
| 339 | > [
|
| 340 | > 1,
|
| 341 | > [2, [3, [4, [5, [6]]]]]
|
| 342 | > ],
|
| 343 | > [[[[[5], 4], 3], 2], 1]
|
| 344 | > ]
|
| 345 | > }
|
| 346 |
|
| 347 | Width > 26
|
| 348 | Expect
|
| 349 | > {
|
| 350 | > primitives: {
|
| 351 | > simple_primitives: [
|
| 352 | > null,
|
| 353 | > false,
|
| 354 | > true
|
| 355 | > ],
|
| 356 | > numeric_primitives: [
|
| 357 | > -123456789,
|
| 358 | > 123.456789
|
| 359 | > ],
|
| 360 | > stringy_primitives: "string"
|
| 361 | > },
|
| 362 | > compounds: [
|
| 363 | > [1, 2, 3],
|
| 364 | > {dict: "ionary"}
|
| 365 | > ],
|
| 366 | > "variety-pack": [
|
| 367 | > null,
|
| 368 | > [
|
| 369 | > "Los",
|
| 370 | > "pollitos",
|
| 371 | > "dicen",
|
| 372 | > "pío",
|
| 373 | > "pío",
|
| 374 | > "pío"
|
| 375 | > ],
|
| 376 | > [
|
| 377 | > 1,
|
| 378 | > [
|
| 379 | > 2,
|
| 380 | > [3, [4, [5, [6]]]]
|
| 381 | > ]
|
| 382 | > ],
|
| 383 | > [
|
| 384 | > [[[[5], 4], 3], 2],
|
| 385 | > 1
|
| 386 | > ]
|
| 387 | > ]
|
| 388 | > }
|