1 # Oil builtins
2
3 #### repr
4 x=42
5 repr x
6 echo status=$?
7 repr nonexistent
8 echo status=$?
9 ## STDOUT:
10 x = (cell exported:F readonly:F nameref:F val:(value.Str s:42))
11 status=0
12 status=1
13 ## END
14
15 #### repr on indexed array with hole
16 declare -a array
17 array[3]=42
18 repr array
19 ## STDOUT:
20 array = (cell exported:F readonly:F nameref:F val:(value.MaybeStrArray strs:[_ _ _ 42]))
21 ## END
22
23
24 #### push onto a=(1 2)
25 shopt -s parse_at
26 a=(1 2)
27 push :a '3 4' '5'
28 argv.py @a
29 ## STDOUT:
30 ['1', '2', '3 4', '5']
31 ## END
32
33 #### push onto var a = @(1 2)
34 shopt -s parse_at
35 var a = @(1 2)
36 push a '3 4' '5' # : is optional
37 argv.py @a
38 ## STDOUT:
39 ['1', '2', '3 4', '5']
40 ## END
41
42 #### push with invalid type
43 s=''
44 push :s a b
45 echo status=$?
46 ## stdout: status=1
47
48 #### push with invalid var name
49 push - a b
50 echo status=$?
51 ## stdout: status=2
52
53 #### write -sep, -end, -n, varying flag syntax
54 shopt -s oil:all
55 var a = @('a b' 'c d')
56 write @a
57 write .
58 write -- @a
59 write .
60
61 write -sep '' -end '' @a; write
62 write .
63
64 write -sep '_' -- @a
65 write -sep '_' -end $' END\n' -- @a
66
67 # with =
68 write -sep='_' -end=$' END\n' -- @a
69 # long flags
70 write --sep '_' --end $' END\n' -- @a
71 # long flags with =
72 write --sep='_' --end=$' END\n' -- @a
73
74 write -n x
75 write -n y
76 write
77
78 ## STDOUT:
79 a b
80 c d
81 .
82 a b
83 c d
84 .
85 a bc d
86 .
87 a b_c d
88 a b_c d END
89 a b_c d END
90 a b_c d END
91 a b_c d END
92 xy
93 ## END
94
95 #### write -e not supported
96 shopt -s oil:all
97 write -e foo
98 write status=$?
99 ## stdout-json: ""
100 ## status: 2
101
102 #### write syntax error
103 shopt -s oil:all
104 write ---end foo
105 write status=$?
106 ## stdout-json: ""
107 ## status: 2
108
109 #### write --
110 shopt -s oil:all
111 write --
112 # This is annoying
113 write -- --
114 write done
115
116 # this is a syntax error! Doh.
117 write ---
118 ## status: 2
119 ## STDOUT:
120
121 --
122 done
123 ## END
124
125 #### getline
126 shopt -s oil:basic
127
128 # Hm this preserves the newline?
129 seq 3 | while getline :line {
130 write line=$line
131 }
132 write a b | while getline --end=T :line {
133 write -end '' line=$line
134 }
135 ## STDOUT:
136 line=1
137 line=2
138 line=3
139 line=a
140 line=b
141 ## END