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

388 lines, 342 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 Constant
16# hi def link punct Statement
17# hi def link kw PreProc
18# (Place in ~/.config/nvim/syntax/pretty_tests.vim,
19# then enable with :set syntax=pretty_tests.vim)
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 > 10
73Expect
74> [
75> 100,
76> 200,
77> 300
78> ]
79
80Input > [[100, 200, 300], [100, 200, 300]]
81
82Width > 20
83Expect
84> [
85> [100, 200, 300],
86> [100, 200, 300]
87> ]
88
89Width > 17
90Expect
91> [
92> [
93> 100,
94> 200,
95> 300
96> ],
97> [100, 200, 300]
98> ]
99
100Width > 16
101Expect
102> [
103> [
104> 100,
105> 200,
106> 300
107> ],
108> [
109> 100,
110> 200,
111> 300
112> ]
113> ]
114
115## Dictionaries
116
117Width > 10
118Input > {}
119Expect > {}
120
121Input > {"x":100, "y":200, "z":300}
122
123Width > 24
124Expect > {x: 100, y: 200, z: 300}
125
126Width > 23
127Expect
128> {
129> x: 100,
130> y: 200,
131> z: 300
132> }
133
134Input
135> {
136> "letters": {"1": "A", "2": "B", "3": "C"},
137> "numbers": {"1": "one", "2": "two", "3": "three"}
138> }
139
140Width > 49
141Expect
142> {
143> letters: {"1": "A", "2": "B", "3": "C"},
144> numbers: {"1": "one", "2": "two", "3": "three"}
145> }
146
147Width > 42
148Expect
149> {
150> letters: {"1": "A", "2": "B", "3": "C"},
151> numbers: {
152> "1": "one",
153> "2": "two",
154> "3": "three"
155> }
156> }
157
158Width > 41
159Expect
160> {
161> letters: {
162> "1": "A",
163> "2": "B",
164> "3": "C"
165> },
166> numbers: {
167> "1": "one",
168> "2": "two",
169> "3": "three"
170> }
171> }
172
173## Full width characters
174
175Input > ["世界", "您好"]
176
177Width > 16
178Expect > ["世界", "您好"]
179
180Width > 15
181Expect
182> [
183> "世界",
184> "您好"
185> ]
186
187## Everything at once
188
189Input
190> {
191> 'primitives': {
192> 'simple_primitives': [null, false, true],
193> 'numeric_primitives': [-123456789, 123.456789],
194> 'stringy_primitives': 'string'
195> },
196> 'compounds': [
197> [1, 2, 3],
198> {'dict': 'ionary'}
199> ],
200> 'variety-pack': [
201> null,
202> ['Los', 'pollitos', 'dicen', 'pío', 'pío', 'pío'],
203> [1, [2, [3, [4, [5, [6]]]]]],
204> [[[[[5], 4], 3], 2], 1]
205> ]
206> }
207
208Width > 54
209Expect
210> {
211> primitives: {
212> simple_primitives: [null, false, true],
213> numeric_primitives: [-123456789, 123.456789],
214> stringy_primitives: "string"
215> },
216> compounds: [[1, 2, 3], {dict: "ionary"}],
217> "variety-pack": [
218> null,
219> ["Los", "pollitos", "dicen", "pío", "pío", "pío"],
220> [1, [2, [3, [4, [5, [6]]]]]],
221> [[[[[5], 4], 3], 2], 1]
222> ]
223> }
224
225Width > 49
226Expect
227> {
228> primitives: {
229> simple_primitives: [null, false, true],
230> numeric_primitives: [-123456789, 123.456789],
231> stringy_primitives: "string"
232> },
233> compounds: [[1, 2, 3], {dict: "ionary"}],
234> "variety-pack": [
235> null,
236> [
237> "Los",
238> "pollitos",
239> "dicen",
240> "pío",
241> "pío",
242> "pío"
243> ],
244> [1, [2, [3, [4, [5, [6]]]]]],
245> [[[[[5], 4], 3], 2], 1]
246> ]
247> }
248
249Width > 43
250Expect
251> {
252> primitives: {
253> simple_primitives: [null, false, true],
254> numeric_primitives: [
255> -123456789,
256> 123.456789
257> ],
258> stringy_primitives: "string"
259> },
260> compounds: [[1, 2, 3], {dict: "ionary"}],
261> "variety-pack": [
262> null,
263> [
264> "Los",
265> "pollitos",
266> "dicen",
267> "pío",
268> "pío",
269> "pío"
270> ],
271> [1, [2, [3, [4, [5, [6]]]]]],
272> [[[[[5], 4], 3], 2], 1]
273> ]
274> }
275
276Width > 33
277Expect
278> {
279> primitives: {
280> simple_primitives: [
281> null,
282> false,
283> true
284> ],
285> numeric_primitives: [
286> -123456789,
287> 123.456789
288> ],
289> stringy_primitives: "string"
290> },
291> compounds: [
292> [1, 2, 3],
293> {dict: "ionary"}
294> ],
295> "variety-pack": [
296> null,
297> [
298> "Los",
299> "pollitos",
300> "dicen",
301> "pío",
302> "pío",
303> "pío"
304> ],
305> [1, [2, [3, [4, [5, [6]]]]]],
306> [[[[[5], 4], 3], 2], 1]
307> ]
308> }
309
310Width > 32
311Expect
312> {
313> primitives: {
314> simple_primitives: [
315> null,
316> false,
317> true
318> ],
319> numeric_primitives: [
320> -123456789,
321> 123.456789
322> ],
323> stringy_primitives: "string"
324> },
325> compounds: [
326> [1, 2, 3],
327> {dict: "ionary"}
328> ],
329> "variety-pack": [
330> null,
331> [
332> "Los",
333> "pollitos",
334> "dicen",
335> "pío",
336> "pío",
337> "pío"
338> ],
339> [
340> 1,
341> [2, [3, [4, [5, [6]]]]]
342> ],
343> [[[[[5], 4], 3], 2], 1]
344> ]
345> }
346
347Width > 26
348Expect
349> {
350> primitives: {
351> simple_primitives: [
352> null,
353> false,
354> true
355> ],
356> numeric_primitives: [
357> -123456789,
358> 123.456789
359> ],
360> stringy_primitives: "string"
361> },
362> compounds: [
363> [1, 2, 3],
364> {dict: "ionary"}
365> ],
366> "variety-pack": [
367> null,
368> [
369> "Los",
370> "pollitos",
371> "dicen",
372> "pío",
373> "pío",
374> "pío"
375> ],
376> [
377> 1,
378> [
379> 2,
380> [3, [4, [5, [6]]]]
381> ]
382> ],
383> [
384> [[[[5], 4], 3], 2],
385> 1
386> ]
387> ]
388> }