OILS / data_lang / pretty_test.txt View on Github | oilshell.org

463 lines, 400 significant
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
23Width > 10
24
25Input > null
26Expect > null
27
28Input > true
29Expect > true
30
31Input > false
32Expect > false
33
34Input > 0
35Expect > 0
36
37Input > -123
38Expect > -123
39
40Input > 123456789123456789123456789
41Expect > 123456789123456789123456789
42
43Input > 0.0
44Expect > 0.0
45
46Input > 1.00
47Expect > 1.0
48
49Input > -0.000
50Expect > -0.0
51
52Input > 2.99792458e8
53Expect > 299792458.0
54
55Input > "hello"
56Expect > "hello"
57
58Input > "\"For the `n`'th time,\" she said."
59Expect > "\"For the `n`'th time,\" she said."
60
61## Lists
62
63Width > 20
64Input > []
65Expect > []
66
67Input > [100, 200, 300]
68
69Width > 20
70Expect > [100, 200, 300]
71
72Width > 12
73Expect
74> [
75> 100,
76> 200, 300
77> ]
78
79Width > 10
80Expect
81> [
82> 100,
83> 200,
84> 300
85> ]
86
87Input > [[100, 200, 300], [100, 200, 300]]
88
89Width > 20
90Expect
91> [
92> [100, 200, 300],
93> [100, 200, 300]
94> ]
95
96Width > 19
97Expect
98> [
99> [
100> 100, 200,
101> 300
102> ],
103> [100, 200, 300]
104> ]
105
106Width > 11
107Expect
108> [
109> [
110> 100,
111> 200,
112> 300
113> ],
114> [
115> 100,
116> 200,
117> 300
118> ]
119> ]
120
121## Dictionaries
122
123Width > 10
124Input > {}
125Expect > {}
126
127Input > {"x":100, "y":200, "z":300}
128
129Width > 24
130Expect > {x: 100, y: 200, z: 300}
131
132Width > 23
133Expect
134> {
135> x: 100,
136> y: 200,
137> z: 300
138> }
139
140Input
141> {
142> "letters": {"1": "A", "2": "B", "3": "C"},
143> "numbers": {"1": "one", "2": "two", "3": "three"}
144> }
145
146Width > 51
147Expect
148> {
149> letters: {"1": "A", "2": "B", "3": "C"},
150> numbers: {"1": "one", "2": "two", "3": "three"}
151> }
152
153Width > 44
154Expect
155> {
156> letters: {"1": "A", "2": "B", "3": "C"},
157> numbers: {
158> "1": "one",
159> "2": "two",
160> "3": "three"
161> }
162> }
163
164Width > 43
165Expect
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
181Input > ["世界", "您好"]
182
183Width > 16
184Expect > ["世界", "您好"]
185
186Width > 15
187Expect
188> [
189> "世界",
190> "您好"
191> ]
192
193## Tabular alignment
194
195Input > ["aaaaaaa", "bbb", "ccccc"]
196
197Width > 27
198Expect > ["aaaaaaa", "bbb", "ccccc"]
199
200Width > 26
201Expect
202> [
203> "aaaaaaa", "bbb",
204> "ccccc"
205> ]
206
207Width > 21
208Expect
209> [
210> "aaaaaaa", "bbb",
211> "ccccc"
212> ]
213
214Width > 20
215Expect
216> [
217> "aaaaaaa",
218> "bbb",
219> "ccccc"
220> ]
221
222Input > ["aaa", "bbbbbbb", "ccccc"]
223
224Width > 27
225Expect > ["aaa", "bbbbbbb", "ccccc"]
226
227Width > 26
228Expect
229> [
230> "aaa", "bbbbbbb",
231> "ccccc"
232> ]
233
234Input > ["aaaaa", "bbbbbbb", "ccc"]
235
236Width > 27
237Expect > ["aaaaa", "bbbbbbb", "ccc"]
238
239Width > 26
240Expect
241> [
242> "aaaaa", "bbbbbbb",
243> "ccc"
244> ]
245
246Input > { "simple_primitives": [null, false, true] }
247Width > 30
248Expect
249> {
250> simple_primitives: [
251> null, false, true
252> ]
253> }
254
255# elements are too big for tabular alignment
256Input > ["aaaaaaaaaaaaaaaaaaa", "bbbbbbbbbbbbbbbbbbbbb", "cccccccccccccccccccc"]
257Width > 30
258Expect
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.
267Input > ["aaaaaaa", "bbbbbbb", "ccccccc", {"d": "k"}]
268Width > 40
269Expect
270> [
271> "aaaaaaa", "bbbbbbb", "ccccccc",
272> {d: "k"}
273> ]
274
275
276## Everything at once
277
278Input
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
297Width > 58
298Expect
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
314Width > 53
315Expect
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
334Width > 47
335Expect
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
356Width > 37
357Expect
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
383Width > 36
384Expect
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
413Width > 30
414Expect
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> }