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