2012-04-25 22:27:19 -04:00
|
|
|
#!/bin/bash
|
|
|
|
|
2014-12-23 16:09:58 -05:00
|
|
|
source "$(dirname "$0")"/../tap.sh || exit 1
|
2013-07-18 03:41:08 -04:00
|
|
|
|
2012-04-25 22:27:19 -04:00
|
|
|
# source the library function
|
2013-07-29 14:57:59 -04:00
|
|
|
lib=${1:-${PMTEST_SCRIPTLIB_DIR}human_to_size.sh}
|
|
|
|
if [[ -z $lib || ! -f $lib ]]; then
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_bail "human_to_size library (%s) could not be located" "${lib}"
|
2013-11-08 00:44:40 -05:00
|
|
|
exit 1
|
2012-04-25 22:27:19 -04:00
|
|
|
fi
|
2013-07-29 14:57:59 -04:00
|
|
|
. "$lib"
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2013-11-05 08:50:44 -05:00
|
|
|
if ! type -t human_to_size &>/dev/null; then
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_bail "human_to_size function not found"
|
2013-11-08 00:44:40 -05:00
|
|
|
exit 1
|
2012-04-25 22:27:19 -04:00
|
|
|
fi
|
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts() {
|
2014-12-23 16:09:58 -05:00
|
|
|
local input=$1 expected=$2
|
|
|
|
tap_is_str "$(human_to_size "$input")" "$expected" "$input"
|
2012-04-25 22:27:19 -04:00
|
|
|
}
|
|
|
|
|
2014-12-23 16:09:58 -05:00
|
|
|
tap_plan 15
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
# tap_parse_hts <input> <expected output>
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '1MiB' 1048576
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '10XiB' ''
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '10 MiB' 10485760
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '10 XiB' ''
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '.1 TiB' 109951162778
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts ' -3 KiB ' -3072
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts 'foo3KiB' ''
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '3KiBfoo' ''
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '3kib' ''
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '+1KiB' 1024
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '+1.0 KiB' 1024
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '1MB' 1000000
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '1M' 1048576
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts ' 1 G ' 1073741824
|
2012-04-25 22:27:19 -04:00
|
|
|
|
2014-12-23 16:16:08 -05:00
|
|
|
tap_parse_hts '1Q' ''
|
2014-12-23 16:53:10 -05:00
|
|
|
|
|
|
|
# vim: set noet:
|