diff options
author | Kerin Millar <kfm@plushkava.net> | 2023-02-10 05:59:45 +0000 |
---|---|---|
committer | Sam James <sam@gentoo.org> | 2023-02-10 06:07:36 +0000 |
commit | 027ffe6fa60995f2c18c66e992644a9d3092edb1 (patch) | |
tree | eea2f5cedb0c9c024c354b845b7d51dad500493a /test-functions | |
parent | Improve the means by which the number of terminal columns is detected (diff) | |
download | gentoo-functions-027ffe6fa60995f2c18c66e992644a9d3092edb1.tar.gz gentoo-functions-027ffe6fa60995f2c18c66e992644a9d3092edb1.tar.bz2 gentoo-functions-027ffe6fa60995f2c18c66e992644a9d3092edb1.zip |
test-functions: Add a test for the is_int() function
Signed-off-by: Sam James <sam@gentoo.org>
Diffstat (limited to 'test-functions')
-rwxr-xr-x | test-functions | 38 |
1 files changed, 33 insertions, 5 deletions
diff --git a/test-functions b/test-functions index 8db2191..9f4dfc5 100755 --- a/test-functions +++ b/test-functions @@ -156,6 +156,31 @@ test_esyslog() { iterate_tests 5 "$@" } +test_is_int() { + set -- \ + 1 N/A \ + 1 ' ' \ + 1 ' 1 ' \ + 1 '' \ + 1 +1 \ + 1 +008 \ + 1 -008 \ + 1 008 \ + 1 x \ + 0 0 \ + 0 1 \ + 0 -1 \ + 0 123456789 + + callback() { + shift + test_description="is_int $(print_args "$@")" + is_int "$@" + } + + iterate_tests 2 "$@" +} + iterate_tests() { slice_width=$1 shift @@ -192,11 +217,13 @@ print_args() { if [ "$((i += 1))" -eq 1 ]; then set -- fi - if [ -n "${arg}" ]; then - set -- "$@" "${arg}" - else - set -- "$@" "''" - fi + case ${arg} in + ''|*[[:space:]]*) + set -- "$@" "'${arg}'" + ;; + *) + set -- "$@" "${arg}" + esac done printf '%s\n' "$*" } @@ -218,5 +245,6 @@ rc=0 test_is_older_than || rc=1 test_get_bootparam || rc=1 test_esyslog || rc=1 +test_is_int || rc=1 cleanup_tmpdir exit "${rc}" |