lib: more helper functions

This commit is contained in:
Andrew Dunham 2021-07-12 22:54:25 -04:00
parent dafb44313c
commit a519746560
2 changed files with 68 additions and 0 deletions

View file

@ -67,5 +67,33 @@ testSubstituteInPlace() {
assertEquals "hi hi hi" "$(cat "$TEST_TMPDIR/sub.txt")"
}
testQuote() {
local input expected
{ input="$(cat)"; } <<EOF
foo'bar"baz'
EOF
{ expected="$(cat)"; } <<EOF
'foo'\\''bar"baz'\\'''
EOF
assertEquals "$expected" "$(quote "$input")"
}
testFnmatch() {
assertTrue 'fnmatch "f??*" "foobar"'
assertFalse 'fnmatch "f??*" "fo"'
assertFalse 'fnmatch "f??*" "loob"'
}
testEpochseconds() {
# TODO(andrew-d): better test
# Assert that it's numeric by deleting all numbers and verifying that
# there's nothing left.
assertEquals "" "$(epochseconds | tr -d '[0-9]')"
}
# Load shUnit2
. ./shunit2