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

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