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: 1 .. 100}
|
52 |
|
53 | (Range) <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) <Eggex 0x--->
|
78 | (Dict) {k: <Eggex 0x--->}
|
79 |
|
80 | (Eggex) <Eggex 0x--->
|
81 | (Dict) {"k":<Eggex 0x--->}
|
82 | ## END
|
83 |
|
84 | #### BashArray
|
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) (BashArray)
|
105 | (BashArray) (BashArray 'hello')
|
106 |
|
107 | (Dict) {k: (BashArray)}
|
108 | (Dict) {k: (BashArray 'hello')}
|
109 |
|
110 | (BashArray) []
|
111 | (BashArray) ["hello"]
|
112 |
|
113 | (Dict) {"k":[]}
|
114 | (Dict) {"k":["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) (BashArray 'world' null '*.py')
|
127 | (BashArray)
|
128 | (BashArray
|
129 | 'Lorem' 'ipsum' 'dolor' 'sit' 'amet,'
|
130 | 'consectetur' 'adipiscing' 'elit,' 'sed' 'do'
|
131 | 'eiusmod.'
|
132 | )
|
133 | ## END
|
134 |
|
135 | #### BashAssoc, short
|
136 | declare -A empty
|
137 | declare -A assoc=(['k']=$'foo \x01\u03bc')
|
138 |
|
139 | pp (empty)
|
140 | pp (assoc)
|
141 | echo
|
142 |
|
143 | pp ({k:empty})
|
144 | pp ({k:assoc})
|
145 | echo
|
146 |
|
147 | pp line (empty)
|
148 | pp line (assoc)
|
149 | echo
|
150 |
|
151 | pp line ({k:empty})
|
152 | pp line ({k:assoc})
|
153 |
|
154 | ## STDOUT:
|
155 | (BashAssoc) (BashAssoc)
|
156 | (BashAssoc) (BashAssoc ['k']=$'foo \u0001μ')
|
157 |
|
158 | (Dict) {k: (BashAssoc)}
|
159 | (Dict) {k: (BashAssoc ['k']=$'foo \u0001μ')}
|
160 |
|
161 | (BashAssoc) {}
|
162 | (BashAssoc) {"k":"foo \u0001μ"}
|
163 |
|
164 | (Dict) {"k":{}}
|
165 | (Dict) {"k":{"k":"foo \u0001μ"}}
|
166 | ## END
|
167 |
|
168 |
|
169 | #### BashAssoc, long
|
170 | declare -A assoc_0=()
|
171 | declare -A assoc_1=([1]=one)
|
172 | declare assoc_3=([1]=one [two]=2 [3]=three)
|
173 | declare assoc_long=([Lorem]=ipsum [dolor]="sit amet," ['consectetur adipiscing']="elit, sed" [do]="eiusmod.")
|
174 | = assoc_0
|
175 | = assoc_1
|
176 | = assoc_3
|
177 | = assoc_long
|
178 | ## STDOUT:
|
179 | (BashAssoc) (BashAssoc)
|
180 | (BashAssoc) (BashAssoc ['1']='one')
|
181 | (BashAssoc) (BashAssoc ['1']='one' ['two']='2' ['3']='three')
|
182 | (BashAssoc)
|
183 | (BashAssoc
|
184 | ['Lorem']='ipsum'
|
185 | ['dolor']='sit amet,'
|
186 | ['consectetur adipiscing']='elit, sed'
|
187 | ['do']='eiusmod.'
|
188 | )
|
189 | ## END
|
190 |
|
191 | #### Simple Cycles
|
192 | var cyclic_array = ["one", "two", "three"]
|
193 | setvar cyclic_array[2] = cyclic_array
|
194 | var cyclic_dict = {"dead_end": null}
|
195 | setvar cyclic_dict["live_end"] = cyclic_dict
|
196 | = cyclic_array
|
197 | = cyclic_dict
|
198 | ## STDOUT:
|
199 | (List) ['one', 'two', [...]]
|
200 | (Dict) {dead_end: null, live_end: {...}}
|
201 | ## END
|
202 |
|
203 | #### Complex Cycles
|
204 | var dict = {}
|
205 | setvar dict["nothing"] = null
|
206 | var simple_cycle = [["dummy"]]
|
207 | setvar simple_cycle[0][0] = simple_cycle
|
208 | setvar dict["simple_cycle"] = simple_cycle
|
209 | var tricky_cycle = ["dummy"]
|
210 | setvar tricky_cycle[0] = dict
|
211 | setvar dict["tricky_cycle"] = tricky_cycle
|
212 | var dag = [1, 2, "dummy"]
|
213 | setvar dag[2] = dag
|
214 | setvar dict["dag"] = [dag, dag]
|
215 | var alpha = {}
|
216 | var omega = {}
|
217 | setvar alpha["omega"] = omega
|
218 | setvar omega["alpha"] = alpha
|
219 | setvar dict["key_alpha"] = alpha
|
220 | setvar dict["key_omega"] = omega
|
221 | = dict
|
222 | ## STDOUT:
|
223 | (Dict)
|
224 | {
|
225 | nothing: null,
|
226 | simple_cycle: [[[...]]],
|
227 | tricky_cycle: [{...}],
|
228 | dag: [[1, 2, [...]], [1, 2, [...]]],
|
229 | key_alpha: {omega: {alpha: {...}}},
|
230 | key_omega: {alpha: {omega: {...}}}
|
231 | }
|
232 | ## END
|