Skip to content

Commit

Permalink
[spec/assoc] Add a couple more test cases, and implement "${!assoc[@]}".
Browse files Browse the repository at this point in the history
That gets the keys in an arbitrary order.
  • Loading branch information
Andy Chu committed Jul 11, 2019
1 parent 6181733 commit cc0455e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions spec/assoc.test.sh
Expand Up @@ -27,11 +27,18 @@ echo ${d['foo']}
#### retrieve indices with !
declare -A a
#a=([aa]=b [foo]=bar ['a+1']=c)
a[aa]=b
a[foo]=bar
var='x'
a["$var"]=b
a['foo']=bar
a['a+1']=c
argv.py "${!a[@]}"
## stdout: ['foo', 'aa', 'a+1']
for key in "${!a[@]}"; do
echo $key
done | sort
## STDOUT:
a+1
foo
x
## END

#### $a gives nothing
declare -A a
Expand Down
2 changes: 1 addition & 1 deletion test/spec.sh
Expand Up @@ -564,7 +564,7 @@ append() {

# associative array -- mksh and zsh implement different associative arrays.
assoc() {
sh-spec spec/assoc.test.sh --osh-failures-allowed 13 \
sh-spec spec/assoc.test.sh --osh-failures-allowed 12 \
$BASH $OSH_LIST "$@"
}

Expand Down

0 comments on commit cc0455e

Please sign in to comment.