Skip to content
This repository was archived by the owner on May 20, 2024. It is now read-only.

Commit 94f9a4a

Browse files
CodingMarkusCodingMarkus
CodingMarkus
authored and
CodingMarkus
committed
Split int test into int & uint test
1 parent 3940b04 commit 94f9a4a

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

lib/psst/basic/test.inc.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,40 @@ test_is_int_psst()
5959
{
6060
# value=$1
6161

62+
assert_argc_psst 'test_is_int_psst' 1 $#
63+
64+
# We could use a subshell here but that would only make this test rather
65+
# slow for no reason, so we go for speed.
66+
case $1 in
67+
'' | '-' | *[!0-9-]* | *[0-9]-*) return 2
68+
esac
69+
}
70+
71+
72+
##
73+
# FUNCTION
74+
# test_is_uint_psst <value>
75+
#
76+
# SUMMARY
77+
# Tests if a value is a natural number (unsigned integer)
78+
#
79+
# PARAMETERS
80+
# value: The value to test for being a natural.
81+
#
82+
# RETURNS
83+
# 0: Yes, it is a natural..
84+
# 2: No, it isn't.
85+
#
86+
# SAMPLE
87+
# test_is_uint_psst "abc" || echo "Not an int"
88+
# test_is_uint_psst "123" && echo "It is an int"
89+
#
90+
test_is_uint_psst()
91+
{
92+
# value=$1
93+
94+
assert_argc_psst 'test_is_uint_psst' 1 $#
95+
6296
# We could use a subshell here but that would only make this test rather
6397
# slow for no reason, so we go for speed.
6498
case $1 in

0 commit comments

Comments
 (0)