1 | ## oils_failures_allowed: 2
|
2 |
|
3 | #### Type objects Bool, Int, Float, etc.
|
4 |
|
5 | pp test_ (Bool)
|
6 | pp test_ (Int)
|
7 | pp test_ (Float)
|
8 | pp test_ (Str)
|
9 |
|
10 | pp test_ (List)
|
11 | pp test_ (Dict)
|
12 | pp test_ (Obj)
|
13 | echo
|
14 |
|
15 | var b = Bool
|
16 |
|
17 | pp test_ (b is Bool)
|
18 |
|
19 | # Objects don't have equality, only identity
|
20 | #pp test_ (b === Bool)
|
21 |
|
22 | pp test_ (id(b) === id(Bool))
|
23 |
|
24 | ## STDOUT:
|
25 | (Obj) ("name":"Bool") --> ("__index__":<BuiltinFunc>)
|
26 | (Obj) ("name":"Int") --> ("__index__":<BuiltinFunc>)
|
27 | (Obj) ("name":"Float") --> ("__index__":<BuiltinFunc>)
|
28 | (Obj) ("name":"Str") --> ("__index__":<BuiltinFunc>)
|
29 | (Obj) ("name":"List") --> ("__index__":<BuiltinFunc>)
|
30 | (Obj) ("name":"Dict") --> ("__index__":<BuiltinFunc>)
|
31 | (Obj) ("name":"Obj") --> ("__index__":<BuiltinFunc>)
|
32 |
|
33 | (Bool) true
|
34 | (Bool) true
|
35 | ## END
|
36 |
|
37 | #### Parameterized types - List[Int], Dict[Str, Int]
|
38 | shopt -s ysh:upgrade
|
39 |
|
40 | var li = List[Int]
|
41 | var dsi = Dict[Str, Int]
|
42 |
|
43 | pp test_ (li)
|
44 | pp test_ (dsi)
|
45 |
|
46 | # test identity
|
47 | for i in a b c {
|
48 | assert [li is List[Int]]
|
49 | assert [dsi is Dict[Str,Int]]
|
50 | }
|
51 |
|
52 | assert [li is not dsi]
|
53 |
|
54 | var lli = List[li]
|
55 | pp test_ (lli)
|
56 |
|
57 | pp test_ (Dict[Str, List[Int]])
|
58 |
|
59 | ## STDOUT:
|
60 | (Obj) ("unique_id":"List[Int]")
|
61 | (Obj) ("unique_id":"Dict[Str,Int]")
|
62 | (Obj) ("unique_id":"List[List[Int]]")
|
63 | (Obj) ("unique_id":"Dict[Str,List[Int]]")
|
64 | ## END
|
65 |
|
66 | #### Errors for parameterized types
|
67 |
|
68 | # TODO: errors
|
69 |
|
70 | pp test_ (Bool[Str])
|
71 | pp test_ (List[Str, Str])
|
72 | pp test_ (Dict[Str])
|
73 |
|
74 | # I think this means
|
75 | # TODO: need very low precedence operation
|
76 | #
|
77 | # Func[Int, Str : Int]
|
78 | # Func[Int, Str -> Int]
|
79 | # Func[Int, Str --> Int]
|
80 |
|
81 | ## STDOUT:
|
82 | ## END
|
83 |
|
84 | #### runproc
|
85 | shopt --set parse_proc parse_at
|
86 |
|
87 | f() {
|
88 | write -- f "$@"
|
89 | }
|
90 | proc p {
|
91 | write -- p @ARGV
|
92 | }
|
93 | runproc f 1 2
|
94 | echo status=$?
|
95 |
|
96 | runproc p 3 4
|
97 | echo status=$?
|
98 |
|
99 | runproc invalid 5 6
|
100 | echo status=$?
|
101 |
|
102 | runproc
|
103 | echo status=$?
|
104 |
|
105 | ## STDOUT:
|
106 | f
|
107 | 1
|
108 | 2
|
109 | status=0
|
110 | p
|
111 | 3
|
112 | 4
|
113 | status=0
|
114 | status=1
|
115 | status=2
|
116 | ## END
|
117 |
|
118 |
|
119 | #### runproc typed args
|
120 | shopt --set parse_brace parse_proc
|
121 |
|
122 | proc p {
|
123 | echo 'hi from p'
|
124 | }
|
125 |
|
126 | # The block is ignored for now
|
127 | runproc p {
|
128 | echo myblock
|
129 | }
|
130 | echo
|
131 |
|
132 | proc ty (w; t; n; block) {
|
133 | echo 'ty'
|
134 | pp test_ (w)
|
135 | pp test_ (t)
|
136 | pp test_ (n)
|
137 | echo $[type(block)]
|
138 | }
|
139 |
|
140 | ty a (42; n=99; ^(echo ty))
|
141 | echo
|
142 |
|
143 | runproc ty a (42; n=99; ^(echo ty))
|
144 | echo
|
145 |
|
146 | runproc ty a (42; n=99) {
|
147 | echo 'ty gets literal'
|
148 | }
|
149 |
|
150 | # TODO: Command vs. Block vs. Literal Block should be unified
|
151 |
|
152 | ## STDOUT:
|
153 | hi from p
|
154 |
|
155 | ty
|
156 | (Str) "a"
|
157 | (Int) 42
|
158 | (Int) 99
|
159 | Command
|
160 |
|
161 | ty
|
162 | (Str) "a"
|
163 | (Int) 42
|
164 | (Int) 99
|
165 | Command
|
166 |
|
167 | ty
|
168 | (Str) "a"
|
169 | (Int) 42
|
170 | (Int) 99
|
171 | Command
|
172 | ## END
|
173 |
|
174 |
|
175 | #### pp asdl_
|
176 |
|
177 | shopt -s ysh:upgrade
|
178 |
|
179 | redir >out.txt {
|
180 | x=42
|
181 | setvar y = {foo: x}
|
182 |
|
183 | pp asdl_ (x)
|
184 | pp asdl_ (y)
|
185 |
|
186 | # TODO, this might be nice?
|
187 | # pp asdl_ (x, y)
|
188 | }
|
189 |
|
190 | # Two lines with value.Str
|
191 | grep -n -o value.Str out.txt
|
192 |
|
193 | # Dict should have an address
|
194 | #grep -n -o 'Dict 0x' out.txt
|
195 |
|
196 | #cat out.txt
|
197 |
|
198 | ## STDOUT:
|
199 | 1:value.Str
|
200 | 2:value.Str
|
201 | ## END
|
202 |
|
203 | #### pp asdl_ can handle an object cycle
|
204 |
|
205 | shopt -s ysh:upgrade
|
206 |
|
207 | var d = {}
|
208 | setvar d.cycle = d
|
209 |
|
210 | pp test_ (d) | fgrep -o '{"cycle":'
|
211 |
|
212 | pp asdl_ (d) | fgrep -o 'cycle ...'
|
213 |
|
214 | ## STDOUT:
|
215 | {"cycle":
|
216 | cycle ...
|
217 | ## END
|
218 |
|
219 |
|
220 | #### pp gc-stats_
|
221 |
|
222 | pp gc-stats_
|
223 |
|
224 | ## STDOUT:
|
225 | ## END
|
226 |
|
227 |
|
228 | #### pp cell_
|
229 | x=42
|
230 |
|
231 | pp cell_ x
|
232 | echo status=$?
|
233 |
|
234 | pp -- cell_ x
|
235 | echo status=$?
|
236 |
|
237 | pp cell_ nonexistent
|
238 | echo status=$?
|
239 | ## STDOUT:
|
240 | x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
|
241 | status=0
|
242 | x = (Cell exported:F readonly:F nameref:F val:(value.Str s:42))
|
243 | status=0
|
244 | status=1
|
245 | ## END
|
246 |
|
247 | #### pp cell_ on indexed array with hole
|
248 | declare -a array
|
249 | array[3]=42
|
250 | pp cell_ array
|
251 | ## STDOUT:
|
252 | array = (Cell exported:F readonly:F nameref:F val:(value.BashArray strs:[_ _ _ 42]))
|
253 | ## END
|
254 |
|
255 |
|
256 | #### pp proc
|
257 | shopt --set ysh:upgrade
|
258 |
|
259 | # This has to be a separate file because sh_spec.py strips comments!
|
260 | . $REPO_ROOT/spec/testdata/doc-comments.sh
|
261 |
|
262 | pp proc
|
263 | echo ---
|
264 |
|
265 | # print one
|
266 | pp proc f
|
267 |
|
268 | ## STDOUT:
|
269 | proc_name doc_comment
|
270 | f "doc ' comment with \" quotes"
|
271 | g ""
|
272 | myproc "YSH-style proc"
|
273 | "true" "Special quoting rule"
|
274 | ---
|
275 | proc_name doc_comment
|
276 | f "doc ' comment with \" quotes"
|
277 | ## END
|
278 |
|
279 | #### pp (x) and pp [x] quote code
|
280 |
|
281 | pp (42)
|
282 |
|
283 | shopt --set ysh:upgrade
|
284 |
|
285 | pp [42] | sed 's/0x[a-f0-9]\+/[replaced]/'
|
286 |
|
287 | ## STDOUT:
|
288 |
|
289 | pp (42)
|
290 | ^
|
291 | [ stdin ]:1: (Int) 42
|
292 |
|
293 | pp [42] | sed 's/0x[a-f0-9]\+/[replaced]/'
|
294 | ^
|
295 | [ stdin ]:5: <Expr [replaced]>
|
296 | ## END
|
297 |
|
298 | #### pp test_ supports BashArray, BashAssoc
|
299 |
|
300 | declare -a array=(a b c)
|
301 | pp test_ (array)
|
302 |
|
303 | array[5]=z
|
304 | pp test_ (array)
|
305 |
|
306 | declare -A assoc=([k]=v [k2]=v2)
|
307 | pp test_ (assoc)
|
308 |
|
309 | # I think assoc arrays can never null / unset
|
310 |
|
311 | assoc['k3']=
|
312 | pp test_ (assoc)
|
313 |
|
314 | ## STDOUT:
|
315 | {"type":"BashArray","data":{"0":"a","1":"b","2":"c"}}
|
316 | {"type":"BashArray","data":{"0":"a","1":"b","2":"c","5":"z"}}
|
317 | {"type":"BashAssoc","data":{"k":"v","k2":"v2"}}
|
318 | {"type":"BashAssoc","data":{"k":"v","k2":"v2","k3":""}}
|
319 | ## END
|
320 |
|
321 | #### pp value (x) is like = keyword
|
322 |
|
323 | shopt --set ysh:upgrade
|
324 | source $LIB_YSH/list.ysh
|
325 |
|
326 | # It can be piped!
|
327 |
|
328 | pp value ('foo') | cat
|
329 |
|
330 | pp value ("isn't this sq") | cat
|
331 |
|
332 | pp value ('"dq $myvar"') | cat
|
333 |
|
334 | pp value (r'\ backslash \\') | cat
|
335 |
|
336 | pp value (u'one \t two \n') | cat
|
337 |
|
338 | # Without a terminal, default width is 80
|
339 | pp value (repeat([123], 40)) | cat
|
340 |
|
341 | ## STDOUT:
|
342 | (Str) 'foo'
|
343 | (Str) b'isn\'t this sq'
|
344 | (Str) '"dq $myvar"'
|
345 | (Str) b'\\ backslash \\\\'
|
346 | (Str) b'one \t two \n'
|
347 | (List)
|
348 | [
|
349 | 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123,
|
350 | 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123, 123,
|
351 | 123, 123, 123, 123, 123, 123, 123, 123, 123, 123
|
352 | ]
|
353 | ## END
|
354 |
|