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