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

232 lines, 143 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: 1 .. 100}
52
53(Range) <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) <Eggex 0x--->
78(Dict) {k: <Eggex 0x--->}
79
80(Eggex) <Eggex 0x--->
81(Dict) {"k":<Eggex 0x--->}
82## END
83
84#### BashArray
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) (BashArray)
105(BashArray) (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) (BashArray 'world' null '*.py')
127(BashArray)
128(BashArray
129 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
130 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
131 'eiusmod.'
132)
133## END
134
135#### BashAssoc, short
136declare -A empty
137declare -A assoc=(['k']=$'foo \x01\u03bc')
138
139pp (empty)
140pp (assoc)
141echo
142
143pp ({k:empty})
144pp ({k:assoc})
145echo
146
147pp line (empty)
148pp line (assoc)
149echo
150
151pp line ({k:empty})
152pp line ({k:assoc})
153
154## STDOUT:
155(BashAssoc) (BashAssoc)
156(BashAssoc) (BashAssoc ['k']=$'foo \u0001μ')
157
158(Dict) {k: (BashAssoc)}
159(Dict) {k: (BashAssoc ['k']=$'foo \u0001μ')}
160
161(BashAssoc) {}
162(BashAssoc) {"k":"foo \u0001μ"}
163
164(Dict) {"k":{}}
165(Dict) {"k":{"k":"foo \u0001μ"}}
166## END
167
168
169#### BashAssoc, long
170declare -A assoc_0=()
171declare -A assoc_1=([1]=one)
172declare assoc_3=([1]=one [two]=2 [3]=three)
173declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
174= assoc_0
175= assoc_1
176= assoc_3
177= assoc_long
178## STDOUT:
179(BashAssoc) (BashAssoc)
180(BashAssoc) (BashAssoc ['1']='one')
181(BashAssoc) (BashAssoc ['1']='one' ['two']='2' ['3']='three')
182(BashAssoc)
183(BashAssoc
184 ['Lorem']='ipsum'
185 ['dolor']='sit amet,'
186 ['consectetur adipiscing']='elit, sed'
187 ['do']='eiusmod.'
188)
189## END
190
191#### Simple Cycles
192var cyclic_array = ["one", "two", "three"]
193setvar cyclic_array[2] = cyclic_array
194var cyclic_dict = {"dead_end": null}
195setvar cyclic_dict["live_end"] = cyclic_dict
196= cyclic_array
197= cyclic_dict
198## STDOUT:
199(List) ['one', 'two', [...]]
200(Dict) {dead_end: null, live_end: {...}}
201## END
202
203#### Complex Cycles
204var dict = {}
205setvar dict["nothing"] = null
206var simple_cycle = [["dummy"]]
207setvar simple_cycle[0][0] = simple_cycle
208setvar dict["simple_cycle"] = simple_cycle
209var tricky_cycle = ["dummy"]
210setvar tricky_cycle[0] = dict
211setvar dict["tricky_cycle"] = tricky_cycle
212var dag = [1, 2, "dummy"]
213setvar dag[2] = dag
214setvar dict["dag"] = [dag, dag]
215var alpha = {}
216var omega = {}
217setvar alpha["omega"] = omega
218setvar omega["alpha"] = alpha
219setvar dict["key_alpha"] = alpha
220setvar dict["key_omega"] = omega
221= dict
222## STDOUT:
223(Dict)
224{
225 nothing: null,
226 simple_cycle: [[[...]]],
227 tricky_cycle: [{...}],
228 dag: [[1, 2, [...]], [1, 2, [...]]],
229 key_alpha: {omega: {alpha: {...}}},
230 key_omega: {alpha: {omega: {...}}}
231}
232## END