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

456 lines, 394 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
266## Everything at once
267
268Input
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
287Width > 58
288Expect
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
304Width > 53
305Expect
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
324Width > 47
325Expect
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
346Width > 37
347Expect
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
374Width > 36
375Expect
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
405Width > 30
406Expect
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> }