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

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