1 ## our_shell: ysh
2 ## oils_failures_allowed: 0
3
4 #### single quoted -- implicit and explicit raw
5 var x = 'foo bar'
6 echo $x
7 setvar x = r'foo bar' # Same string
8 echo $x
9 setvar x = r'\t\n' # This is raw
10 echo $x
11 ## STDOUT:
12 foo bar
13 foo bar
14 \t\n
15 ## END
16
17 #### Implicit raw single quote with backslash is a syntax error
18 var x = '\t\n'
19 echo $x
20 ## status: 2
21 ## stdout-json: ""
22
23 #### single quoted C strings: $'foo\n'
24
25 # expression mode
26 var x = $'foo\nbar'
27 echo "$x"
28
29 # command mode
30 if test "$x" = $'foo\nbar'; then
31 echo equal
32 fi
33
34 ## STDOUT:
35 foo
36 bar
37 equal
38 ## END
39
40 #### raw strings and J8 strings don't work in OSH
41 shopt --unset ysh:all
42
43 echo r'hello \'
44 echo u'mu \u{3bc}'
45 echo b'byte \yff'
46
47 echo --
48
49 echo r'''
50 raw multi
51 '''
52
53 echo u'''
54 u multi
55 '''
56
57 echo b'''
58 b multi
59 '''
60
61 ## STDOUT:
62 rhello \
63 umu \u{3bc}
64 bbyte \yff
65 --
66 r
67 raw multi
68
69 u
70 u multi
71
72 b
73 b multi
74
75 ## END
76
77 #### J8-style u'' and b'' strings in expression mode
78
79 var x = u'\u{3bc}'
80 var y = b'\yff'
81
82
83 write --end '' -- $x | od -A n -t x1
84 write --end '' -- $y | od -A n -t x1
85
86 ## STDOUT:
87 ce bc
88 ff
89 ## END
90
91 #### J8-style u'' and b'' strings in command mode
92
93 write --end '' -- u'\u{3bc}' | od -A n -t x1
94 write --end '' -- b'\yff' | od -A n -t x1
95
96 # TODO: make this be illegal
97 # echo u'hello \u03bc'
98
99 ## STDOUT:
100 ce bc
101 ff
102 ## END
103
104 #### J8-style multi-line strings u''' b''' in command mode
105
106 write --end '' -- u'''
107 --
108 \u{61}
109 --
110 '''
111 write --end '' -- b'''
112 --
113 \y62
114 --
115 '''
116
117 # Should be illegal?
118 #echo u'hello \u03bc'
119
120 ## STDOUT:
121 --
122 a
123 --
124 --
125 b
126 --
127 ## END
128
129 #### Double Quoted
130 var name = 'World'
131 var g = "Hello $name"
132
133 echo "Hello $name"
134 echo $g
135 ## STDOUT:
136 Hello World
137 Hello World
138 ## END
139
140 #### Multiline strings with '' and ""
141
142 var single = '
143 single
144 '
145
146 var x = 42
147 var double = "
148 double $x
149 "
150
151 echo $single
152 echo $double
153
154 ## STDOUT:
155
156 single
157
158
159 double 42
160
161 ## END
162
163 #### C strings in %() array literals
164 shopt -s oil:upgrade
165
166 var lines=%($'aa\tbb' $'cc\tdd')
167 write @lines
168
169 ## STDOUT:
170 aa bb
171 cc dd
172 ## END
173
174 #### shopt parse_ysh_string
175
176 # Ignored prefix
177 echo r'\'
178
179 # space
180 write r '' end
181
182 # These use shell rules!
183 echo ra'\'
184 echo raw'\'
185
186 echo r"\\"
187
188 # Now it's a regular r
189 shopt --unset parse_ysh_string
190 write unset r'\'
191
192 ## STDOUT:
193 \
194 r
195
196 end
197 ra\
198 raw\
199 r\
200 unset
201 r\
202 ## END
203
204 #### Triple Double Quotes, Expression Mode
205
206 var line1 = """line1"""
207 echo line1=$line1
208 var line2 = """
209 line2"""
210 echo line2=$line2
211
212 var two = 2
213 var three = 3
214 var x = """
215 one "
216 two = $two ""
217 three = $three
218 """
219 echo "[$x]"
220
221 var x = """
222 good
223 bad
224 """
225 echo "[$x]"
226
227 ## STDOUT:
228 line1=line1
229 line2=line2
230 [one "
231 two = 2 ""
232 three = 3
233 ]
234 [good
235 bad
236 ]
237 ## END
238
239 #### Triple Single Quotes, Expression Mode
240
241 var two = 2
242 var three = 2
243
244 var x = '''
245 two = $two '
246 three = $three ''
247 \u{61}
248 '''
249 echo "[$x]"
250
251 var x = u'''
252 two = $two '
253 three = $three ''
254 \u{61}
255 '''
256 echo "[$x]"
257
258 var x = b'''
259 two = $two '
260 three = $three ''
261 \u{61} \y61
262 '''
263 echo "[$x]"
264
265 ## STDOUT:
266 [two = $two '
267 three = $three ''
268 \u{61}
269 ]
270 [two = $two '
271 three = $three ''
272 a
273 ]
274 [two = $two '
275 three = $three ''
276 a a
277 ]
278 ## END
279
280
281 #### Triple Double Quotes, Command Mode
282
283 var two=2
284 var three=3
285
286 echo ""a # test lookahead
287
288 echo --
289 echo """
290 one "
291 two = $two ""
292 three = $three
293 """
294
295 echo --
296 tac <<< """
297 one "
298 two = $two ""
299 three = $three
300 """
301
302 shopt --unset parse_triple_quote
303
304 echo --
305 echo """
306 one
307 two = $two
308 three = $three
309 """
310
311
312 ## STDOUT:
313 a
314 --
315 one "
316 two = 2 ""
317 three = 3
318
319 --
320
321 three = 3
322 two = 2 ""
323 one "
324 --
325
326 one
327 two = 2
328 three = 3
329
330 ## END
331
332 #### raw strings and triple quotes
333
334 echo r'''a'''
335
336 shopt --unset parse_ysh_string
337
338 echo r'''a'''
339
340 ## STDOUT:
341 a
342 ra
343 ## END
344
345
346 #### Triple Single Quotes, Command Mode
347
348 echo ''a # make sure lookahead doesn't mess up
349
350 echo --
351 echo '''
352 two = $two
353 '
354 '' '
355 \u{61}
356 '''
357 ## STDOUT:
358 a
359 --
360 two = $two
361 '
362 '' '
363 \u{61}
364
365 ## END
366
367 #### Triple Single Quotes, Here Doc
368
369 tac <<< '''
370 two = $two
371 '
372 '' '
373 \u{61}
374 '''
375
376 ## STDOUT:
377
378 \u{61}
379 '' '
380 '
381 two = $two
382 ## END
383
384 #### Triple Single Quotes without parse_triple_quote
385
386 shopt --unset parse_triple_quote
387
388 echo '''
389 two = $two
390 \u{61}
391 '''
392
393 ## STDOUT:
394
395 two = $two
396 \u{61}
397
398 ## END
399
400 #### here doc with quotes
401
402 # This has 3 right double quotes
403
404 cat <<EOF
405 "hello"
406 ""
407 """
408 EOF
409
410
411 ## STDOUT:
412 "hello"
413 ""
414 """
415 ## END
416
417 #### triple quoted and implicit concatenation
418
419 # Should we allow this? Or I think it's possible to make it a syntax error
420
421 echo '''
422 single
423 '''zz
424
425 echo """
426 double
427 """zz
428 ## status: 2
429 ## stdout-json: ""