1 | ## our_shell: osh
|
2 | # compare_shells: bash
|
3 |
|
4 | #### Can't use x+= on YSH Int (issue #840)
|
5 |
|
6 | sh_str=2
|
7 | echo sh_str=$sh_str
|
8 |
|
9 | sh_str+=1
|
10 | echo sh_str=$sh_str
|
11 |
|
12 | sh_str+=1
|
13 | echo sh_str=$sh_str
|
14 |
|
15 | echo
|
16 |
|
17 | var ysh_int = 2
|
18 | echo ysh_int=$ysh_int
|
19 |
|
20 | # What should happen here?
|
21 |
|
22 | ysh_int+=1
|
23 | echo ysh_int=$ysh_int
|
24 |
|
25 | ysh_int+=1
|
26 | echo ysh_int=$ysh_int
|
27 |
|
28 | ## status: 1
|
29 | ## STDOUT:
|
30 | sh_str=2
|
31 | sh_str=21
|
32 | sh_str=211
|
33 |
|
34 | ysh_int=2
|
35 | ## END
|
36 |
|
37 | #### Can't x+= on other YSH types
|
38 |
|
39 | $SH -c '
|
40 | var x = /d+/
|
41 | x+=1
|
42 | '
|
43 | echo eggex $?
|
44 |
|
45 | $SH -c '
|
46 | var d = {}
|
47 | d+=1
|
48 | '
|
49 | echo Dict $?
|
50 |
|
51 | # This is unspecified for now, could try to match bash
|
52 | $SH -c '
|
53 | declare -A A=()
|
54 | A+=1
|
55 | declare -A
|
56 | '
|
57 | #echo AssocArray $?
|
58 |
|
59 | ## STDOUT:
|
60 | eggex 1
|
61 | Dict 1
|
62 | ## END
|
63 |
|
64 | #### Shell ${x:-default} with YSH List (issue #954)
|
65 |
|
66 | var mylist = [1, 2, 3]
|
67 |
|
68 | echo mylist ${mylist:-default}
|
69 |
|
70 | var myint = 42
|
71 |
|
72 | echo myint ${myint:-default}
|
73 |
|
74 | ## status: 3
|
75 | ## STDOUT:
|
76 | ## END
|
77 |
|
78 |
|
79 | #### Shell ${a[0]} with YSH List (issue #1092)
|
80 |
|
81 | var a = [1, 2, 3]
|
82 | echo first ${a[0]}
|
83 |
|
84 | ## status: 3
|
85 | ## STDOUT:
|
86 | ## END
|
87 |
|
88 |
|
89 | #### Can't splice nested List
|
90 |
|
91 | shopt --set parse_at
|
92 |
|
93 | var mylist = ["ls", {name: 42}]
|
94 |
|
95 | echo @mylist
|
96 |
|
97 | ## status: 3
|
98 | ## STDOUT:
|
99 | ## END
|
100 |
|
101 | #### Can't splice nested Dict
|
102 |
|
103 | declare -A A=([k]=v [k2]=v2)
|
104 | echo ${A[@]}
|
105 |
|
106 | var d ={name: [1, 2, 3]}
|
107 | echo ${d[@]}
|
108 |
|
109 | ## status: 3
|
110 | ## STDOUT:
|
111 | v v2
|
112 | ## END
|
113 |
|
114 | #### ${#x} on List and Dict
|
115 |
|
116 | var L = [1,2,3]
|
117 |
|
118 | echo List ${#L[@]}
|
119 | echo List ${#L}
|
120 | # Not supported. TODO: could be a problem
|
121 | #echo List ${#L[0]}
|
122 |
|
123 | declare -a a=(abc d)
|
124 |
|
125 | echo array ${#a[@]}
|
126 | echo array ${#a}
|
127 | echo array ${#a[0]}
|
128 |
|
129 | var d = {k: 'v', '0': 'abc'}
|
130 |
|
131 | echo Dict ${#d[@]}
|
132 | echo Dict ${#d}
|
133 | # Not supported. TODO: could be a problem
|
134 | #echo Dict ${#d[0]}
|
135 |
|
136 | declare -A d=([k]=v [0]=abc)
|
137 |
|
138 | echo Assoc ${#d[@]}
|
139 | echo Assoc ${#d}
|
140 | echo Assoc ${#d[0]}
|
141 |
|
142 | ## status: 3
|
143 | ## STDOUT:
|
144 | ## END
|
145 |
|
146 | #### Can't use $x on List and Dict
|
147 |
|
148 | declare -a a=(abc d)
|
149 | echo array $a
|
150 | echo array ${a[0]}
|
151 |
|
152 | var L = [1,2,3]
|
153 | echo List $L
|
154 |
|
155 | declare -A A=([k]=v [0]=abc)
|
156 | echo Assoc $A
|
157 | echo Assoc ${A[0]}
|
158 |
|
159 | var d = {k: 'v', '0': 'abc'}
|
160 | #echo Dict $d
|
161 |
|
162 | ## status: 3
|
163 | ## STDOUT:
|
164 | array abc
|
165 | array abc
|
166 | ## END
|
167 |
|
168 | #### Iterate over array with holes (bug fix)
|
169 |
|
170 | declare -a array=(a b)
|
171 | array[5]=c
|
172 | argv.py "${array[@]}"
|
173 |
|
174 | # TODO: Should print this like this bash, with value.BashArray
|
175 | declare -a
|
176 |
|
177 | for i, item in (array) {
|
178 | echo "$i $item"
|
179 | }
|
180 |
|
181 | ## status: 3
|
182 | ## STDOUT:
|
183 | ['a', 'b', 'c']
|
184 | array=(); array[0]=a array[1]=b array[5]=c
|
185 | ## END
|
186 |
|
187 | #### Slice bash array isn't allowed
|
188 |
|
189 | shopt --set parse_at
|
190 |
|
191 | var ysh = :| ysh 'c d' e f |
|
192 | var yslice = ysh[1:3]
|
193 | argv.py @yslice
|
194 |
|
195 | declare -a bash=(bash 'c d' e f)
|
196 |
|
197 | # You can copy it and then slice it
|
198 | var ysh2 = :| copy "${bash[@]}" |
|
199 | var yslice = ysh2[0:2]
|
200 | argv.py @yslice
|
201 |
|
202 | # Note this
|
203 | var sh_slice = bash[1:3]
|
204 | argv.py @sh_slice
|
205 |
|
206 | ## status: 3
|
207 | ## STDOUT:
|
208 | ['c d', 'e']
|
209 | ['copy', 'bash']
|
210 | ## END
|
211 |
|
212 | #### Concat ++ not defined on shell array
|
213 |
|
214 | declare -a a=(x y)
|
215 | declare -a b=(x y)
|
216 |
|
217 | = a ++ b
|
218 |
|
219 | ## status: 3
|
220 | ## STDOUT:
|
221 | ## END
|