OILS / spec / ysh-printing.test.sh View on Github | oilshell.org

230 lines, 141 significant
1# Pretty printing tests
2
3#### Int
4= -123
5## stdout: (Int) -123
6
7#### Float
8= -0.00
9## stdout: (Float) -0.0
10
11#### Null
12= null
13## stdout: (Null) null
14
15#### Bool
16= true
17= false
18## STDOUT:
19(Bool) true
20(Bool) false
21## END
22
23#### String
24= "double quoted"
25= 'single quoted'
26## STDOUT:
27(Str) 'double quoted'
28(Str) 'single quoted'
29## END
30
31#### Range
32var x = 1..100
33
34pp (x)
35
36# TODO: show type here, like (Range 1 .. 100)
37
38pp ({k: x})
39
40echo
41
42remove-addr() {
43 sed 's/0x[0-9a-f]\+/0x---/'
44}
45
46pp line (x) | remove-addr
47pp line ({k: x}) | remove-addr
48
49## STDOUT:
50(Range 1 .. 100)
51(Dict) {k: (Range 1 .. 100)}
52
53<Range 0x--->
54(Dict) {"k":<Range 0x--->}
55## END
56
57
58#### Eggex (reference type)
59var pat = /d+/
60
61remove-addr() {
62 sed 's/0x[0-9a-f]\+/0x---/'
63}
64
65pp (pat) | remove-addr
66
67pp ({k: pat}) | remove-addr
68
69# TODO: change this
70
71echo
72
73pp line (pat) | remove-addr
74pp line ({k: pat}) | remove-addr
75
76## STDOUT:
77<Eggex 0x--->
78(Dict) {k: <Eggex 0x--->}
79
80<Eggex 0x--->
81(Dict) {"k":<Eggex 0x--->}
82## END
83
84#### BashArray, short
85declare -a empty=()
86declare -a array_1=(hello)
87
88pp (empty)
89pp (array_1)
90echo
91
92pp ({k: empty})
93pp ({k: array_1})
94echo
95
96pp line (empty)
97pp line (array_1)
98echo
99
100pp line ({k: empty})
101pp line ({k: array_1})
102
103## STDOUT:
104(BashArray)
105(BashArray 'hello')
106
107(Dict) {k: (BashArray)}
108(Dict) {k: (BashArray 'hello')}
109
110(BashArray) []
111(BashArray) ["hello"]
112
113(Dict) {"k":[]}
114(Dict) {"k":["hello"]}
115## END
116
117#### BashArray, long
118declare -a array_3
119array_3[0]="world"
120array_3[2]=*.py
121declare array_long=(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
122do eiusmod.)
123= array_3
124= array_long
125## STDOUT:
126(BashArray 'world' null '*.py')
127(BashArray
128 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
129 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
130 'eiusmod.'
131)
132## END
133
134#### BashAssoc, short
135declare -A empty
136declare -A assoc=(['k']=$'foo \x01\u03bc')
137
138pp (empty)
139pp (assoc)
140echo
141
142pp ({k:empty})
143pp ({k:assoc})
144echo
145
146pp line (empty)
147pp line (assoc)
148echo
149
150pp line ({k:empty})
151pp line ({k:assoc})
152
153## STDOUT:
154(BashAssoc)
155(BashAssoc ['k']=$'foo \u0001μ')
156
157(Dict) {k: (BashAssoc)}
158(Dict) {k: (BashAssoc ['k']=$'foo \u0001μ')}
159
160(BashAssoc) {}
161(BashAssoc) {"k":"foo \u0001μ"}
162
163(Dict) {"k":{}}
164(Dict) {"k":{"k":"foo \u0001μ"}}
165## END
166
167
168#### BashAssoc, long
169declare -A assoc_0=()
170declare -A assoc_1=([1]=one)
171declare assoc_3=([1]=one [two]=2 [3]=three)
172declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
173= assoc_0
174= assoc_1
175= assoc_3
176= assoc_long
177## STDOUT:
178(BashAssoc)
179(BashAssoc ['1']='one')
180(BashAssoc ['1']='one' ['two']='2' ['3']='three')
181(BashAssoc
182 ['Lorem']='ipsum'
183 ['dolor']='sit amet,'
184 ['consectetur adipiscing']='elit, sed'
185 ['do']='eiusmod.'
186)
187## END
188
189#### Simple Cycles
190var cyclic_array = ["one", "two", "three"]
191setvar cyclic_array[2] = cyclic_array
192var cyclic_dict = {"dead_end": null}
193setvar cyclic_dict["live_end"] = cyclic_dict
194= cyclic_array
195= cyclic_dict
196## STDOUT:
197(List) ['one', 'two', [...]]
198(Dict) {dead_end: null, live_end: {...}}
199## END
200
201#### Complex Cycles
202var dict = {}
203setvar dict["nothing"] = null
204var simple_cycle = [["dummy"]]
205setvar simple_cycle[0][0] = simple_cycle
206setvar dict["simple_cycle"] = simple_cycle
207var tricky_cycle = ["dummy"]
208setvar tricky_cycle[0] = dict
209setvar dict["tricky_cycle"] = tricky_cycle
210var dag = [1, 2, "dummy"]
211setvar dag[2] = dag
212setvar dict["dag"] = [dag, dag]
213var alpha = {}
214var omega = {}
215setvar alpha["omega"] = omega
216setvar omega["alpha"] = alpha
217setvar dict["key_alpha"] = alpha
218setvar dict["key_omega"] = omega
219= dict
220## STDOUT:
221(Dict)
222{
223 nothing: null,
224 simple_cycle: [[[...]]],
225 tricky_cycle: [{...}],
226 dag: [[1, 2, [...]], [1, 2, [...]]],
227 key_alpha: {omega: {alpha: {...}}},
228 key_omega: {alpha: {omega: {...}}}
229}
230## END