3 # source the library function
4 if [[ -z $1 ||
! -f $1 ]]; then
5 printf "error: path to human_to_size library not provided or does not exist\n"
10 if ! type -t human_to_size
>/dev
/null
; then
11 printf 'human_to_size function not found\n'
16 local input
=$1 expected
=$2 result
20 result
=$
(human_to_size
"$1")
21 if [[ $result = "$expected" ]]; then
25 printf '[TEST %3s]: FAIL\n' "$testcount"
26 printf ' input: %s\n' "$input"
27 printf ' output: %s\n' "$result"
28 printf ' expected: %s\n' "$expected"
34 printf 'All %s tests successful\n\n' "$testcount"
37 printf '%s of %s tests failed\n\n' "$fail" "$testcount"
43 printf 'Beginning human_to_size tests\n'
45 # parse_hts <input> <expected output>
47 parse_hts
'1MiB' 1048576
51 parse_hts
'10 MiB' 10485760
55 parse_hts
'.1 TiB' 109951162778
57 parse_hts
' -3 KiB ' -3072
59 parse_hts
'foo3KiB' ''
61 parse_hts
'3KiBfoo' ''
65 parse_hts
'+1KiB' 1024
67 parse_hts
'+1.0 KiB' 1024
69 parse_hts
'1MB' 1000000
71 parse_hts
'1M' 1048576
73 parse_hts
' 1 G ' 1073741824