mirror of
https://github.com/zunit-zsh/zunit.git
synced 2026-09-10 06:36:15 -04:00
Add is_key_in assertion method
This commit is contained in:
parent
c0b8b46ca3
commit
c46c149ebf
13
README.md
13
README.md
|
|
@ -137,6 +137,19 @@ Asserts that a value is not included in the comparison array.
|
|||
assert 'a' not_in 'x' 'y' 'z'
|
||||
```
|
||||
|
||||
#### is_key_in
|
||||
|
||||
Asserts that a value is a key in a hash.
|
||||
|
||||
```sh
|
||||
typeset -A hash; hash=(
|
||||
'a' 1
|
||||
'b' 2
|
||||
'c' 3
|
||||
)
|
||||
assert 'a' is_key_in ${(@kv)hash}
|
||||
```
|
||||
|
||||
#### exists
|
||||
|
||||
Asserts that the given path exists
|
||||
|
|
|
|||
18
zunit
18
zunit
|
|
@ -147,6 +147,24 @@ function _zunit_assert_not_in() {
|
|||
exit 1
|
||||
}
|
||||
|
||||
###
|
||||
# Assert that a value is a key in a hash
|
||||
###
|
||||
function _zunit_assert_is_key_in() {
|
||||
local i found=0 value=$1
|
||||
local -A hash
|
||||
hash=(${(@)@:2})
|
||||
|
||||
for k v in ${(@kv)hash}; do
|
||||
[[ $k = $value ]] && found=1
|
||||
done
|
||||
|
||||
[[ $found -eq 1 ]] && return 0
|
||||
|
||||
echo "'$value' is not a key in (${(@kv)hash})"
|
||||
exit 1
|
||||
}
|
||||
|
||||
###
|
||||
# Assert the a path exists
|
||||
###
|
||||
|
|
|
|||
Loading…
Reference in a new issue