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