1 | # Pretty printing tests
|
2 |
|
3 | #### Int
|
4 | = -123
|
5 | ## stdout: (Int) -123
|
6 |
|
7 | #### Float
|
8 | = -0.00
|
9 | ## stdout: (Float) -0.0
|
10 |
|
11 | #### Null
|
12 | = null
|
13 | ## stdout: (Null) null
|
14 |
|
15 | #### Bool
|
16 | = true
|
17 | = false
|
18 | ## STDOUT:
|
19 | (Bool) true
|
20 | (Bool) false
|
21 | ## END
|
22 |
|
23 | #### String
|
24 | = "double quoted"
|
25 | = 'single quoted'
|
26 | ## STDOUT:
|
27 | (Str) 'double quoted'
|
28 | (Str) 'single quoted'
|
29 | ## END
|
30 |
|
31 | #### Range
|
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 | #### Eggex (reference type)
|
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 | #### BashArray, short
|
85 | declare -a empty=()
|
86 | declare -a array_1=(hello)
|
87 |
|
88 | pp (empty)
|
89 | pp (array_1)
|
90 | echo
|
91 |
|
92 | pp ({k: empty})
|
93 | pp ({k: array_1})
|
94 | echo
|
95 |
|
96 | pp line (empty)
|
97 | pp line (array_1)
|
98 | echo
|
99 |
|
100 | pp line ({k: empty})
|
101 | pp line ({k: array_1})
|
102 |
|
103 | ## STDOUT:
|
104 | (BashArray)
|
105 | (BashArray 'hello')
|
106 |
|
107 | (Dict) {k: (BashArray)}
|
108 | (Dict) {k: (BashArray 'hello')}
|
109 |
|
110 | {"type":"BashArray","data":{}}
|
111 | {"type":"BashArray","data":{"0":"hello"}}
|
112 |
|
113 | (Dict) {"k":{"type":"BashArray","data":{}}}
|
114 | (Dict) {"k":{"type":"BashArray","data":{"0":"hello"}}}
|
115 | ## END
|
116 |
|
117 | #### BashArray, long
|
118 | declare -a array_3
|
119 | array_3[0]="world"
|
120 | array_3[2]=*.py
|
121 | declare array_long=(Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
|
122 | do eiusmod.)
|
123 | = array_3
|
124 | = array_long
|
125 | ## STDOUT:
|
126 | (BashArray 'world' null '*.py')
|
127 | (BashArray
|
128 | 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
|
129 | 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
|
130 | 'eiusmod.'
|
131 | )
|
132 | ## END
|
133 |
|
134 | #### BashAssoc, short
|
135 | declare -A empty
|
136 | declare -A assoc=(['k']=$'foo \x01\u03bc')
|
137 |
|
138 | pp (empty)
|
139 | pp (assoc)
|
140 | echo
|
141 |
|
142 | pp ({k:empty})
|
143 | pp ({k:assoc})
|
144 | echo
|
145 |
|
146 | pp line (empty)
|
147 | pp line (assoc)
|
148 | echo
|
149 |
|
150 | pp line ({k:empty})
|
151 | pp line ({k:assoc})
|
152 |
|
153 | ## STDOUT:
|
154 | (BashAssoc)
|
155 | (BashAssoc ['k']=$'foo \u0001μ')
|
156 |
|
157 | (Dict) {k: (BashAssoc)}
|
158 | (Dict) {k: (BashAssoc ['k']=$'foo \u0001μ')}
|
159 |
|
160 | {"type":"BashAssoc","data":{}}
|
161 | {"type":"BashAssoc","data":{"k":"foo \u0001μ"}}
|
162 |
|
163 | (Dict) {"k":{"type":"BashAssoc","data":{}}}
|
164 | (Dict) {"k":{"type":"BashAssoc","data":{"k":"foo \u0001μ"}}}
|
165 | ## END
|
166 |
|
167 |
|
168 | #### BashAssoc, long
|
169 | declare -A assoc_0=()
|
170 | declare -A assoc_1=([1]=one)
|
171 | declare assoc_3=([1]=one [two]=2 [3]=three)
|
172 | declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
|
173 | = assoc_0
|
174 | = assoc_1
|
175 | = assoc_3
|
176 | = assoc_long
|
177 | ## STDOUT:
|
178 | (BashAssoc)
|
179 | (BashAssoc ['1']='one')
|
180 | (BashAssoc ['1']='one' ['two']='2' ['3']='three')
|
181 | (BashAssoc
|
182 | ['Lorem']='ipsum'
|
183 | ['dolor']='sit amet,'
|
184 | ['consectetur adipiscing']='elit, sed'
|
185 | ['do']='eiusmod.'
|
186 | )
|
187 | ## END
|
188 |
|
189 | #### Simple Cycles
|
190 | var cyclic_array = ["one", "two", "three"]
|
191 | setvar cyclic_array[2] = cyclic_array
|
192 | var cyclic_dict = {"dead_end": null}
|
193 | setvar cyclic_dict["live_end"] = cyclic_dict
|
194 | = cyclic_array
|
195 | = cyclic_dict
|
196 | ## STDOUT:
|
197 | (List) ['one', 'two', [...]]
|
198 | (Dict) {dead_end: null, live_end: {...}}
|
199 | ## END
|
200 |
|
201 | #### Complex Cycles
|
202 | var dict = {}
|
203 | setvar dict["nothing"] = null
|
204 | var simple_cycle = [["dummy"]]
|
205 | setvar simple_cycle[0][0] = simple_cycle
|
206 | setvar dict["simple_cycle"] = simple_cycle
|
207 | var tricky_cycle = ["dummy"]
|
208 | setvar tricky_cycle[0] = dict
|
209 | setvar dict["tricky_cycle"] = tricky_cycle
|
210 | var dag = [1, 2, "dummy"]
|
211 | setvar dag[2] = dag
|
212 | setvar dict["dag"] = [dag, dag]
|
213 | var alpha = {}
|
214 | var omega = {}
|
215 | setvar alpha["omega"] = omega
|
216 | setvar omega["alpha"] = alpha
|
217 | setvar dict["key_alpha"] = alpha
|
218 | setvar dict["key_omega"] = omega
|
219 | = dict
|
220 | ## STDOUT:
|
221 | (Dict)
|
222 | {
|
223 | nothing: null,
|
224 | simple_cycle: [[[...]]],
|
225 | tricky_cycle: [{...}],
|
226 | dag: [[1, 2, [...]], [1, 2, [...]]],
|
227 | key_alpha: {omega: {alpha: {...}}},
|
228 | key_omega: {alpha: {omega: {...}}}
|
229 | }
|
230 | ## END
|