1 |
# Pretty printing tests
|
2 |
|
3 |
|
4 |
= -123
|
5 |
## STDOUT:
|
6 |
(Int) -123
|
7 |
## END
|
8 |
|
9 |
|
10 |
= -0.00
|
11 |
## STDOUT:
|
12 |
(Float) -0.0
|
13 |
## END
|
14 |
|
15 |
|
16 |
= null
|
17 |
## STDOUT:
|
18 |
(Null) null
|
19 |
## END
|
20 |
|
21 |
|
22 |
= true
|
23 |
= false
|
24 |
## STDOUT:
|
25 |
(Bool) true
|
26 |
(Bool) false
|
27 |
## END
|
28 |
|
29 |
|
30 |
= "double quoted"
|
31 |
= 'single quoted'
|
32 |
## STDOUT:
|
33 |
(Str) 'double quoted'
|
34 |
(Str) 'single quoted'
|
35 |
## END
|
36 |
|
37 |
|
38 |
var x = 1..100
|
39 |
|
40 |
pp value (x)
|
41 |
|
42 |
# TODO: show type here, like (Range 1 .. 100)
|
43 |
|
44 |
pp value ({k: x})
|
45 |
|
46 |
echo
|
47 |
|
48 |
pp test_ (x)
|
49 |
pp 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 |
|
61 |
var pat = /d+/
|
62 |
|
63 |
remove-addr() {
|
64 |
sed 's/0x[0-9a-f]\+/0x---/'
|
65 |
}
|
66 |
|
67 |
pp value (pat) | remove-addr
|
68 |
|
69 |
pp value ({k: pat}) | remove-addr
|
70 |
|
71 |
# TODO: change this
|
72 |
|
73 |
echo
|
74 |
|
75 |
pp test_ (pat)
|
76 |
pp 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 |
|
87 |
declare -a empty=()
|
88 |
declare -a array_1=(hello)
|
89 |
array_1[5]=5
|
90 |
|
91 |
var empty = _a2sp(empty)
|
92 |
var array_1 = _a2sp(array_1)
|
93 |
|
94 |
pp value (empty)
|
95 |
pp value (array_1)
|
96 |
echo
|
97 |
|
98 |
pp value ({k: empty})
|
99 |
pp value ({k: array_1})
|
100 |
echo
|
101 |
|
102 |
pp test_ (empty)
|
103 |
pp test_ (array_1)
|
104 |
echo
|
105 |
|
106 |
pp test_ ({k: empty})
|
107 |
pp 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 |
|
124 |
declare -a empty=()
|
125 |
declare -a array_1=(hello)
|
126 |
|
127 |
pp value (empty)
|
128 |
pp value (array_1)
|
129 |
echo
|
130 |
|
131 |
pp value ({k: empty})
|
132 |
pp value ({k: array_1})
|
133 |
echo
|
134 |
|
135 |
pp test_ (empty)
|
136 |
pp test_ (array_1)
|
137 |
echo
|
138 |
|
139 |
pp test_ ({k: empty})
|
140 |
pp 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 |
|
157 |
declare -a array_3
|
158 |
array_3[0]="world"
|
159 |
array_3[2]=*.py
|
160 |
declare array_long=(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
|
161 |
do 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 |
|
174 |
declare -A empty
|
175 |
declare -A assoc=(['k']=$'foo \x01\u03bc')
|
176 |
|
177 |
pp value (empty)
|
178 |
pp value (assoc)
|
179 |
echo
|
180 |
|
181 |
pp value ({k:empty})
|
182 |
pp value ({k:assoc})
|
183 |
echo
|
184 |
|
185 |
pp test_ (empty)
|
186 |
pp test_ (assoc)
|
187 |
echo
|
188 |
|
189 |
pp test_ ({k:empty})
|
190 |
pp 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 |
|
208 |
declare -A assoc_0=()
|
209 |
declare -A assoc_1=([1]=one)
|
210 |
declare assoc_3=([1]=one [two]=2 [3]=three)
|
211 |
declare 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 |
|
229 |
var cyclic_array = ["one", "two", "three"]
|
230 |
setvar cyclic_array[2] = cyclic_array
|
231 |
var cyclic_dict = {"dead_end": null}
|
232 |
setvar 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 |
|
241 |
var dict = {}
|
242 |
setvar dict["nothing"] = null
|
243 |
var simple_cycle = [["dummy"]]
|
244 |
setvar simple_cycle[0][0] = simple_cycle
|
245 |
setvar dict["simple_cycle"] = simple_cycle
|
246 |
var tricky_cycle = ["dummy"]
|
247 |
setvar tricky_cycle[0] = dict
|
248 |
setvar dict["tricky_cycle"] = tricky_cycle
|
249 |
var dag = [1, 2, "dummy"]
|
250 |
setvar dag[2] = dag
|
251 |
setvar dict["dag"] = [dag, dag]
|
252 |
var alpha = {}
|
253 |
var omega = {}
|
254 |
setvar alpha["omega"] = omega
|
255 |
setvar omega["alpha"] = alpha
|
256 |
setvar dict["key_alpha"] = alpha
|
257 |
setvar 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
|