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 > 123456789123456789
|
41 | Expect > 123456789123456789
|
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, 300]
|
104 | > ]
|
105 |
|
106 | Width > 11
|
107 | Expect
|
108 | > [
|
109 | > [
|
110 | > 100,
|
111 | > 200,
|
112 | > 300
|
113 | > ],
|
114 | > [
|
115 | > 100,
|
116 | > 200,
|
117 | > 300
|
118 | > ]
|
119 | > ]
|
120 |
|
121 | ## Dictionaries
|
122 |
|
123 | Width > 10
|
124 | Input > {}
|
125 | Expect > {}
|
126 |
|
127 | Input > {"x":100, "y":200, "z":300}
|
128 |
|
129 | Width > 24
|
130 | Expect > {x: 100, y: 200, z: 300}
|
131 |
|
132 | Width > 23
|
133 | Expect
|
134 | > {
|
135 | > x: 100,
|
136 | > y: 200,
|
137 | > z: 300
|
138 | > }
|
139 |
|
140 | Input
|
141 | > {
|
142 | > "letters": {"1": "A", "2": "B", "3": "C"},
|
143 | > "numbers": {"1": "one", "2": "two", "3": "three"}
|
144 | > }
|
145 |
|
146 | Width > 51
|
147 | Expect
|
148 | > {
|
149 | > letters: {"1": "A", "2": "B", "3": "C"},
|
150 | > numbers: {"1": "one", "2": "two", "3": "three"}
|
151 | > }
|
152 |
|
153 | Width > 44
|
154 | Expect
|
155 | > {
|
156 | > letters: {"1": "A", "2": "B", "3": "C"},
|
157 | > numbers: {
|
158 | > "1": "one",
|
159 | > "2": "two",
|
160 | > "3": "three"
|
161 | > }
|
162 | > }
|
163 |
|
164 | Width > 43
|
165 | Expect
|
166 | > {
|
167 | > letters: {
|
168 | > "1": "A",
|
169 | > "2": "B",
|
170 | > "3": "C"
|
171 | > },
|
172 | > numbers: {
|
173 | > "1": "one",
|
174 | > "2": "two",
|
175 | > "3": "three"
|
176 | > }
|
177 | > }
|
178 |
|
179 | ## Full width characters
|
180 |
|
181 | Input > ["世界", "您好"]
|
182 |
|
183 | Width > 16
|
184 | Expect > ["世界", "您好"]
|
185 |
|
186 | Width > 15
|
187 | Expect
|
188 | > [
|
189 | > "世界",
|
190 | > "您好"
|
191 | > ]
|
192 |
|
193 | ## Tabular alignment
|
194 |
|
195 | Input > ["aaaaaaa", "bbb", "ccccc"]
|
196 |
|
197 | Width > 27
|
198 | Expect > ["aaaaaaa", "bbb", "ccccc"]
|
199 |
|
200 | Width > 26
|
201 | Expect
|
202 | > [
|
203 | > "aaaaaaa", "bbb",
|
204 | > "ccccc"
|
205 | > ]
|
206 |
|
207 | Width > 21
|
208 | Expect
|
209 | > [
|
210 | > "aaaaaaa", "bbb",
|
211 | > "ccccc"
|
212 | > ]
|
213 |
|
214 | Width > 20
|
215 | Expect
|
216 | > [
|
217 | > "aaaaaaa",
|
218 | > "bbb",
|
219 | > "ccccc"
|
220 | > ]
|
221 |
|
222 | Input > ["aaa", "bbbbbbb", "ccccc"]
|
223 |
|
224 | Width > 27
|
225 | Expect > ["aaa", "bbbbbbb", "ccccc"]
|
226 |
|
227 | Width > 26
|
228 | Expect
|
229 | > [
|
230 | > "aaa", "bbbbbbb",
|
231 | > "ccccc"
|
232 | > ]
|
233 |
|
234 | Input > ["aaaaa", "bbbbbbb", "ccc"]
|
235 |
|
236 | Width > 27
|
237 | Expect > ["aaaaa", "bbbbbbb", "ccc"]
|
238 |
|
239 | Width > 26
|
240 | Expect
|
241 | > [
|
242 | > "aaaaa", "bbbbbbb",
|
243 | > "ccc"
|
244 | > ]
|
245 |
|
246 | Input > { "simple_primitives": [null, false, true] }
|
247 | Width > 30
|
248 | Expect
|
249 | > {
|
250 | > simple_primitives: [
|
251 | > null, false, true
|
252 | > ]
|
253 | > }
|
254 |
|
255 | # elements are too big for tabular alignment
|
256 | Input > ["aaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccc"]
|
257 | Width > 30
|
258 | Expect
|
259 | > [
|
260 | > "aaaaaaaaaaaaaaaaaaa",
|
261 | > "bbbbbbbbbbbbbbbbbbbbb",
|
262 | > "cccccccccccccccccccc"
|
263 | > ]
|
264 |
|
265 | # Last element in tabular alignment wants to split across multiple lines,
|
266 | # but should not.
|
267 | Input > ["aaaaaaa", "bbbbbbb", "ccccccc", {"d": "k"}]
|
268 | Width > 40
|
269 | Expect
|
270 | > [
|
271 | > "aaaaaaa", "bbbbbbb", "ccccccc",
|
272 | > {d: "k"}
|
273 | > ]
|
274 |
|
275 |
|
276 | ## Everything at once
|
277 |
|
278 | Input
|
279 | > {
|
280 | > 'primitives': {
|
281 | > 'simple_primitives': [null, false, true],
|
282 | > 'numeric_primitives': [-123456789, 123.456789],
|
283 | > 'stringy_primitives': 'string'
|
284 | > },
|
285 | > 'compounds': [
|
286 | > [1, 2, 3],
|
287 | > {'dict': 'ionary'}
|
288 | > ],
|
289 | > 'variety-pack': [
|
290 | > null,
|
291 | > ['Los', 'pollitos', 'dicen', 'pío', 'pío', 'pío'],
|
292 | > [1, [2, [3, [4, [5, [6]]]]]],
|
293 | > [[[[[5], 4], 3], 2], 1]
|
294 | > ]
|
295 | > }
|
296 |
|
297 | Width > 58
|
298 | Expect
|
299 | > {
|
300 | > primitives: {
|
301 | > simple_primitives: [null, false, true],
|
302 | > numeric_primitives: [-123456789, 123.456789],
|
303 | > stringy_primitives: "string"
|
304 | > },
|
305 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
306 | > "variety-pack": [
|
307 | > null,
|
308 | > ["Los", "pollitos", "dicen", "pío", "pío", "pío"],
|
309 | > [1, [2, [3, [4, [5, [6]]]]]],
|
310 | > [[[[[5], 4], 3], 2], 1]
|
311 | > ]
|
312 | > }
|
313 |
|
314 | Width > 53
|
315 | Expect
|
316 | > {
|
317 | > primitives: {
|
318 | > simple_primitives: [null, false, true],
|
319 | > numeric_primitives: [-123456789, 123.456789],
|
320 | > stringy_primitives: "string"
|
321 | > },
|
322 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
323 | > "variety-pack": [
|
324 | > null,
|
325 | > [
|
326 | > "Los", "pollitos", "dicen",
|
327 | > "pío", "pío", "pío"
|
328 | > ],
|
329 | > [1, [2, [3, [4, [5, [6]]]]]],
|
330 | > [[[[[5], 4], 3], 2], 1]
|
331 | > ]
|
332 | > }
|
333 |
|
334 | Width > 47
|
335 | Expect
|
336 | > {
|
337 | > primitives: {
|
338 | > simple_primitives: [null, false, true],
|
339 | > numeric_primitives: [
|
340 | > -123456789, 123.456789
|
341 | > ],
|
342 | > stringy_primitives: "string"
|
343 | > },
|
344 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
345 | > "variety-pack": [
|
346 | > null,
|
347 | > [
|
348 | > "Los", "pollitos", "dicen",
|
349 | > "pío", "pío", "pío"
|
350 | > ],
|
351 | > [1, [2, [3, [4, [5, [6]]]]]],
|
352 | > [[[[[5], 4], 3], 2], 1]
|
353 | > ]
|
354 | > }
|
355 |
|
356 | Width > 37
|
357 | Expect
|
358 | > {
|
359 | > primitives: {
|
360 | > simple_primitives: [
|
361 | > null, false, true
|
362 | > ],
|
363 | > numeric_primitives: [
|
364 | > -123456789, 123.456789
|
365 | > ],
|
366 | > stringy_primitives: "string"
|
367 | > },
|
368 | > compounds: [
|
369 | > [1, 2, 3], {dict: "ionary"}
|
370 | > ],
|
371 | > "variety-pack": [
|
372 | > null,
|
373 | > [
|
374 | > "Los", "pollitos",
|
375 | > "dicen", "pío",
|
376 | > "pío", "pío"
|
377 | > ],
|
378 | > [1, [2, [3, [4, [5, [6]]]]]],
|
379 | > [[[[[5], 4], 3], 2], 1]
|
380 | > ]
|
381 | > }
|
382 |
|
383 | Width > 36
|
384 | Expect
|
385 | > {
|
386 | > primitives: {
|
387 | > simple_primitives: [
|
388 | > null, false, true
|
389 | > ],
|
390 | > numeric_primitives: [
|
391 | > -123456789, 123.456789
|
392 | > ],
|
393 | > stringy_primitives: "string"
|
394 | > },
|
395 | > compounds: [
|
396 | > [1, 2, 3], {dict: "ionary"}
|
397 | > ],
|
398 | > "variety-pack": [
|
399 | > null,
|
400 | > [
|
401 | > "Los", "pollitos",
|
402 | > "dicen", "pío",
|
403 | > "pío", "pío"
|
404 | > ],
|
405 | > [
|
406 | > 1,
|
407 | > [2, [3, [4, [5, [6]]]]]
|
408 | > ],
|
409 | > [[[[[5], 4], 3], 2], 1]
|
410 | > ]
|
411 | > }
|
412 |
|
413 | Width > 30
|
414 | Expect
|
415 | > {
|
416 | > primitives: {
|
417 | > simple_primitives: [
|
418 | > null, false, true
|
419 | > ],
|
420 | > numeric_primitives: [
|
421 | > -123456789,
|
422 | > 123.456789
|
423 | > ],
|
424 | > stringy_primitives: "string"
|
425 | > },
|
426 | > compounds: [
|
427 | > [1, 2, 3],
|
428 | > {dict: "ionary"}
|
429 | > ],
|
430 | > "variety-pack": [
|
431 | > null,
|
432 | > [
|
433 | > "Los",
|
434 | > "pollitos",
|
435 | > "dicen", "pío",
|
436 | > "pío", "pío"
|
437 | > ],
|
438 | > [
|
439 | > 1,
|
440 | > [
|
441 | > 2,
|
442 | > [
|
443 | > 3,
|
444 | > [
|
445 | > 4,
|
446 | > [
|
447 | > 5,
|
448 | > [
|
449 | > 6
|
450 | > ]
|
451 | > ]
|
452 | > ]
|
453 | > ]
|
454 | > ]
|
455 | > ],
|
456 | > [
|
457 | > [
|
458 | > [[[5], 4], 3],
|
459 | > 2
|
460 | > ], 1
|
461 | > ]
|
462 | > ]
|
463 | > }
|