diff --git a/spec/assoc.test.sh b/spec/assoc.test.sh index 98196410fc..3581a61c8f 100644 --- a/spec/assoc.test.sh +++ b/spec/assoc.test.sh @@ -470,3 +470,82 @@ len=1 unset len=0 ## END +#### unset -v and assoc array +show-len() { + echo len=${#A[@]} +} + +declare -A A=(['K']=val) +show-len + +unset -v 'A["K"]' +show-len + +declare -A A=(['K']=val) +show-len +key=K +unset -v 'A[$key]' +show-len + +## STDOUT: +len=1 +len=0 +len=1 +len=0 +## END + +#### nameref and assoc array +show-values() { + echo values: ${A[@]} +} + +declare -A A=(['K']=val) +show-values + +declare -n ref='A["K"]' +echo before $ref +ref='val2' +echo after $ref +show-values + +echo --- + +key=K +declare -n ref='A[$key]' +echo before $ref +ref='val3' +echo after $ref +show-values + +## STDOUT: +values: val +before val +after val2 +values: val2 +--- +before val2 +after val3 +values: val3 +## END + +#### ${!ref} and assoc array +show-values() { + echo values: ${A[@]} +} + +declare -A A=(['K']=val) +show-values + +declare ref='A["K"]' +echo ref ${!ref} + +key=K +declare ref='A[$key]' +echo ref ${!ref} + +## STDOUT: +values: val +ref val +ref val +## END + diff --git a/stdlib/README.md b/stdlib/README.md new file mode 100644 index 0000000000..b17a5c356d --- /dev/null +++ b/stdlib/README.md @@ -0,0 +1,19 @@ +stdlib/ +======= + +Ideas for shell functions that could be in here: + +- Version comparison: https://github.com/oilshell/oil/issues/683 +- An automated way to download the latest version of Oil: https://github.com/oilshell/oil/issues/463 + - Maybe functions to lazily download documentation too? +- `errexit` utilities: https://github.com/oilshell/oil/issues/474 + +Already have: + +- `log` and `die` + +Note: The file `oil-polyfill.sh` is POSIX shell for functions that should be +portable, e.g. like updating Oil, which may be done from the system shell. + +Other functions can be written in Oil. + diff --git a/test/spec.sh b/test/spec.sh index 9e25a1d60c..073d9b8e66 100755 --- a/test/spec.sh +++ b/test/spec.sh @@ -658,7 +658,7 @@ append() { # associative array -- mksh and zsh implement different associative arrays. assoc() { - sh-spec spec/assoc.test.sh --osh-failures-allowed 1 \ + sh-spec spec/assoc.test.sh --osh-failures-allowed 4 \ $BASH $OSH_LIST "$@" }