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