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, 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 |
|
266 | ## Everything at once
|
267 |
|
268 | Input
|
269 | > {
|
270 | > 'primitives': {
|
271 | > 'simple_primitives': [null, false, true],
|
272 | > 'numeric_primitives': [-123456789, 123.456789],
|
273 | > 'stringy_primitives': 'string'
|
274 | > },
|
275 | > 'compounds': [
|
276 | > [1, 2, 3],
|
277 | > {'dict': 'ionary'}
|
278 | > ],
|
279 | > 'variety-pack': [
|
280 | > null,
|
281 | > ['Los', 'pollitos', 'dicen', 'pío', 'pío', 'pío'],
|
282 | > [1, [2, [3, [4, [5, [6]]]]]],
|
283 | > [[[[[5], 4], 3], 2], 1]
|
284 | > ]
|
285 | > }
|
286 |
|
287 | Width > 58
|
288 | Expect
|
289 | > {
|
290 | > primitives: {
|
291 | > simple_primitives: [null, false, true],
|
292 | > numeric_primitives: [-123456789, 123.456789],
|
293 | > stringy_primitives: "string"
|
294 | > },
|
295 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
296 | > "variety-pack": [
|
297 | > null,
|
298 | > ["Los", "pollitos", "dicen", "pío", "pío", "pío"],
|
299 | > [1, [2, [3, [4, [5, [6]]]]]],
|
300 | > [[[[[5], 4], 3], 2], 1]
|
301 | > ]
|
302 | > }
|
303 |
|
304 | Width > 53
|
305 | Expect
|
306 | > {
|
307 | > primitives: {
|
308 | > simple_primitives: [null, false, true],
|
309 | > numeric_primitives: [-123456789, 123.456789],
|
310 | > stringy_primitives: "string"
|
311 | > },
|
312 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
313 | > "variety-pack": [
|
314 | > null,
|
315 | > [
|
316 | > "Los", "pollitos", "dicen",
|
317 | > "pío", "pío", "pío"
|
318 | > ],
|
319 | > [1, [2, [3, [4, [5, [6]]]]]],
|
320 | > [[[[[5], 4], 3], 2], 1]
|
321 | > ]
|
322 | > }
|
323 |
|
324 | Width > 47
|
325 | Expect
|
326 | > {
|
327 | > primitives: {
|
328 | > simple_primitives: [null, false, true],
|
329 | > numeric_primitives: [
|
330 | > -123456789, 123.456789
|
331 | > ],
|
332 | > stringy_primitives: "string"
|
333 | > },
|
334 | > compounds: [[1, 2, 3], {dict: "ionary"}],
|
335 | > "variety-pack": [
|
336 | > null,
|
337 | > [
|
338 | > "Los", "pollitos", "dicen",
|
339 | > "pío", "pío", "pío"
|
340 | > ],
|
341 | > [1, [2, [3, [4, [5, [6]]]]]],
|
342 | > [[[[[5], 4], 3], 2], 1]
|
343 | > ]
|
344 | > }
|
345 |
|
346 | Width > 37
|
347 | Expect
|
348 | > {
|
349 | > primitives: {
|
350 | > simple_primitives: [
|
351 | > null, false, true
|
352 | > ],
|
353 | > numeric_primitives: [
|
354 | > -123456789, 123.456789
|
355 | > ],
|
356 | > stringy_primitives: "string"
|
357 | > },
|
358 | > compounds: [
|
359 | > [1, 2, 3],
|
360 | > {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],
|
388 | > {dict: "ionary"}
|
389 | > ],
|
390 | > "variety-pack": [
|
391 | > null,
|
392 | > [
|
393 | > "Los", "pollitos",
|
394 | > "dicen", "pío",
|
395 | > "pío", "pío"
|
396 | > ],
|
397 | > [
|
398 | > 1,
|
399 | > [2, [3, [4, [5, [6]]]]]
|
400 | > ],
|
401 | > [[[[[5], 4], 3], 2], 1]
|
402 | > ]
|
403 | > }
|
404 |
|
405 | Width > 30
|
406 | Expect
|
407 | > {
|
408 | > primitives: {
|
409 | > simple_primitives: [
|
410 | > null, false, true
|
411 | > ],
|
412 | > numeric_primitives: [
|
413 | > -123456789,
|
414 | > 123.456789
|
415 | > ],
|
416 | > stringy_primitives: "string"
|
417 | > },
|
418 | > compounds: [
|
419 | > [1, 2, 3],
|
420 | > {dict: "ionary"}
|
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 | > ],
|
453 | > 1
|
454 | > ]
|
455 | > ]
|
456 | > }
|