Skip to content

Commit 0efdc8f

Browse files
authored
[spec] Move similar tests for Bash{Array,Assoc} init into array-literal.test.sh (#2282)
* [spec] Rename "spec/{ble => array}-sparse.test.sh" * [spec] Rename "spec/{ => array-}assoc.test.sh" * [spec] Rename "spec/{assoc-zsh => zsh-assoc}.test.sh"
1 parent 4991783 commit 0efdc8f

5 files changed

+58
-61
lines changed

spec/assoc.test.sh spec/array-assoc.test.sh

-18
Original file line numberDiff line numberDiff line change
@@ -425,24 +425,6 @@ v
425425
-{a,b}-
426426
## END
427427
428-
#### bash mangles indexed array #1 (associative array is OK)
429-
declare -A a
430-
a=([k1]=v1 [k2]=v2)
431-
echo ${a["k1"]}
432-
echo ${a["k2"]}
433-
## STDOUT:
434-
v1
435-
v2
436-
## END
437-
438-
#### bash mangles indexed array #2 (associative array is OK)
439-
declare -A a
440-
a=([k2]=-{a,b}-)
441-
echo ${a["k2"]}
442-
## STDOUT:
443-
-{a,b}-
444-
## END
445-
446428
#### declare -A A=() allowed
447429
set -o nounset
448430
shopt -s strict_arith || true

spec/array-literal.test.sh

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## compare_shells: bash
2+
3+
#### [k1]=v1 (BashArray)
4+
# Note: This and next tests have originally been in "spec/assign.test.sh" and
5+
# compared the behavior of OSH's BashAssoc and Bash's indexed array. After
6+
# supporting "arr=([index]=value)" for indexed arrays, the test was adjusted
7+
# and copied here. See also the corresponding tests in "spec/assign.test.sh"
8+
a=([k1]=v1 [k2]=v2)
9+
echo ${a["k1"]}
10+
echo ${a["k2"]}
11+
## STDOUT:
12+
v2
13+
v2
14+
## END
15+
16+
#### [k1]=v1 (BashAssoc)
17+
declare -A a
18+
a=([k1]=v1 [k2]=v2)
19+
echo ${a["k1"]}
20+
echo ${a["k2"]}
21+
## STDOUT:
22+
v1
23+
v2
24+
## END
25+
26+
#### [k1]=v1 looking like brace expansions (BashArray)
27+
declare -A a
28+
a=([k2]=-{a,b}-)
29+
echo ${a["k2"]}
30+
## STDOUT:
31+
-{a,b}-
32+
## END
33+
34+
#### [k1]=v1 looking like brace expansions (BashAssoc)
35+
a=([k2]=-{a,b}-)
36+
echo ${a["k2"]}
37+
## STDOUT:
38+
-{a,b}-
39+
## END
40+
## BUG bash STDOUT:
41+
[k2]=-a-
42+
## END

spec/ble-sparse.test.sh spec/array-sparse.test.sh

-31
Original file line numberDiff line numberDiff line change
@@ -1215,34 +1215,3 @@ status=0
12151215
## END
12161216
## N-I mksh status: 99
12171217
## N-I mksh stdout-json: ""
1218-
1219-
1220-
#### bash mangles indexed array #1 (keys undergoes arithmetic evaluation)
1221-
case $SH in mksh) exit 99;; esac
1222-
# Note: This and next tests have originally been in "spec/assign.test.sh" and
1223-
# compared the behavior of OSH's BashAssoc and Bash's indexed array. After
1224-
# supporting "arr=([index]=value)" for indexed arrays, the test was adjusted
1225-
# and copied here. See also the corresponding tests in "spec/assign.test.sh"
1226-
a=([k1]=v1 [k2]=v2)
1227-
echo ${a["k1"]}
1228-
echo ${a["k2"]}
1229-
## STDOUT:
1230-
v2
1231-
v2
1232-
## END
1233-
## N-I mksh status: 99
1234-
## N-I mksh stdout-json: ""
1235-
1236-
1237-
#### bash mangles indexed array #2 (Bash does not recognize [index]=brace-expansion)
1238-
case $SH in mksh) exit 99;; esac
1239-
a=([k2]=-{a,b}-)
1240-
echo ${a["k2"]}
1241-
## STDOUT:
1242-
-{a,b}-
1243-
## END
1244-
## BUG bash STDOUT:
1245-
[k2]=-a-
1246-
## END
1247-
## N-I mksh status: 99
1248-
## N-I mksh stdout-json: ""
File renamed without changes.

test/spec.sh

+16-12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ arith() {
3434
test/spec-py.sh run-file arith "$@"
3535
}
3636

37+
array-assoc() {
38+
test/spec-py.sh run-file array-assoc "$@"
39+
}
40+
3741
array-basic() {
3842
test/spec-py.sh run-file array-basic "$@"
3943
}
@@ -42,6 +46,14 @@ array-compat() {
4246
test/spec-py.sh run-file array-compat "$@"
4347
}
4448

49+
array-literal() {
50+
test/spec-py.sh run-file array-literal "$@"
51+
}
52+
53+
array-sparse() {
54+
test/spec-py.sh run-file array-sparse "$@"
55+
}
56+
4557
array() {
4658
test/spec-py.sh run-file array "$@"
4759
}
@@ -62,14 +74,6 @@ assign() {
6274
test/spec-py.sh run-file assign "$@"
6375
}
6476

65-
assoc() {
66-
test/spec-py.sh run-file assoc "$@"
67-
}
68-
69-
assoc-zsh() {
70-
test/spec-py.sh run-file assoc-zsh "$@"
71-
}
72-
7377
background() {
7478
test/spec-py.sh run-file background "$@"
7579
}
@@ -82,10 +86,6 @@ ble-idioms() {
8286
test/spec-py.sh run-file ble-idioms "$@"
8387
}
8488

85-
ble-sparse() {
86-
test/spec-py.sh run-file ble-sparse "$@"
87-
}
88-
8989
blog1() {
9090
test/spec-py.sh run-file blog1 "$@"
9191
}
@@ -786,6 +786,10 @@ ysh-xtrace() {
786786
test/spec-py.sh run-file ysh-xtrace "$@"
787787
}
788788

789+
zsh-assoc() {
790+
test/spec-py.sh run-file zsh-assoc "$@"
791+
}
792+
789793
zsh-idioms() {
790794
test/spec-py.sh run-file zsh-idioms "$@"
791795
}

0 commit comments

Comments
 (0)