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