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