1 | ## oils_failures_allowed: 0
|
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 | 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 | #### Eggex (reference type)
|
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 | #### SparseArray, new representation for bash array
|
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 | #### BashArray, short
|
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 | #### BashArray, long
|
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 | #### BashAssoc, short
|
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 | #### BashAssoc, long
|
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 | #### Simple Cycles
|
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 | #### Complex Cycles
|
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
|
270 |
|
271 | #### pp test_: List cycle
|
272 |
|
273 | var no_cycle = [5, 6]
|
274 | pp test_ (no_cycle)
|
275 |
|
276 | var two = [no_cycle, no_cycle]
|
277 | pp test_ (two)
|
278 | #pp value (two)
|
279 |
|
280 | echo
|
281 |
|
282 | var L = [42]
|
283 | call L->append(L)
|
284 | pp test_ (L)
|
285 | #pp value (L)
|
286 |
|
287 | var two = [L, L]
|
288 | pp test_ (two)
|
289 | #pp value (two)
|
290 |
|
291 | ## STDOUT:
|
292 | (List) [5,6]
|
293 | (List) [[5,6],[5,6]]
|
294 |
|
295 | (List) [42,[...]]
|
296 | (List) [[42,[...]],[42,[...]]]
|
297 | ## END
|
298 |
|
299 | #### pp test_: Dict cycle
|
300 |
|
301 | var no_cycle = {z: 99}
|
302 | pp test_ (no_cycle)
|
303 |
|
304 | var two = [no_cycle, no_cycle]
|
305 | pp test_ (two)
|
306 |
|
307 | #pp value (two)
|
308 |
|
309 | echo
|
310 |
|
311 | var d = {k: 42}
|
312 | setvar d.cycle = d
|
313 | pp test_ (d)
|
314 | #pp value (d)
|
315 |
|
316 | var two = [d, d]
|
317 | pp test_ (two)
|
318 | #pp value (two)
|
319 |
|
320 |
|
321 | ## STDOUT:
|
322 | (Dict) {"z":99}
|
323 | (List) [{"z":99},{"z":99}]
|
324 |
|
325 | (Dict) {"k":42,"cycle":{...}}
|
326 | (List) [{"k":42,"cycle":{...}},{"k":42,"cycle":{...}}]
|
327 | ## END
|
328 |
|
329 | #### pp test_: Obj cycle
|
330 |
|
331 | var methods = Object(null, {__foo__: null})
|
332 | var obj = Object(methods, {z: 99})
|
333 | pp test_ (obj)
|
334 |
|
335 | setvar obj.cycle = obj
|
336 | pp test_ (obj)
|
337 |
|
338 | echo
|
339 |
|
340 | var two = [obj, obj]
|
341 | pp test_ (two)
|
342 |
|
343 | ## STDOUT:
|
344 | (Obj) ("z":99) --> ("__foo__":null)
|
345 | (Obj) ("z":99,"cycle":(...)) --> ("__foo__":null)
|
346 |
|
347 | (List) [("z":99,"cycle":(...)) --> ("__foo__":null),("z":99,"cycle":(...)) --> ("__foo__":null)]
|
348 | ## END
|
349 |
|
350 |
|
351 |
|
352 | #### pp test_: Obj with dict cycle
|
353 |
|
354 | var methods = Object(null, {__foo__: null})
|
355 | var no_cycle = Object(methods, {z: 99})
|
356 | pp test_ (no_cycle)
|
357 |
|
358 | var two = [no_cycle, no_cycle]
|
359 | pp test_ (two)
|
360 |
|
361 | echo
|
362 |
|
363 | var d = {k: 42}
|
364 | setvar d.cycle = d
|
365 |
|
366 | # This cycle detection doesn't quite work
|
367 | # Because we're only considering the object itself
|
368 |
|
369 | var o = Object(null, d)
|
370 | pp test_ (o)
|
371 |
|
372 | var two = [o, o]
|
373 | pp test_ (two)
|
374 |
|
375 | #var o2 = Object(o, {z: 99})
|
376 | #pp test_ (o2)
|
377 |
|
378 | ## STDOUT:
|
379 | (Obj) ("z":99) --> ("__foo__":null)
|
380 | (List) [("z":99) --> ("__foo__":null),("z":99) --> ("__foo__":null)]
|
381 |
|
382 | (Obj) ("k":42,"cycle":{"k":42,"cycle":{...}})
|
383 | (List) [("k":42,"cycle":{"k":42,"cycle":{...}}),("k":42,"cycle":{"k":42,"cycle":{...}})]
|
384 | ## END
|
385 |
|