summaryrefslogtreecommitdiff
path: root/test/-ext-/num2int
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:54:34 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:54:34 +0000
commitb2a2ba119104b0ff2b6c20611d76de924596ca5b (patch)
tree198f6b99ec7f609a64e199a9efbc6dcb1e542b1e /test/-ext-/num2int
parentd3437b7c1a496143c2bff2698082af143f5e1dc0 (diff)
* include/ruby/ruby.h: add NUM2SHORT(), NUM2USHORT() macros.
* numeric.c: ditto. * test/-ext-/num2int/test_num2int.rb: add testcases for NUM2SHORT(). * ext/-test-/num2int/num2int.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33743 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/num2int')
-rw-r--r--test/-ext-/num2int/test_num2int.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb
index b276062..6cdfc4c 100644
--- a/test/-ext-/num2int/test_num2int.rb
+++ b/test/-ext-/num2int/test_num2int.rb
@@ -5,6 +5,10 @@ class TestNum2int < Test::Unit::TestCase
end
require '-test-/num2int/num2int'
+ SHRT_MIN = -32768
+ SHRT_MAX = 32767
+ USHRT_MAX = 65535
+
INT_MIN = -2147483648
INT_MAX = 2147483647
UINT_MAX = 4294967295
@@ -29,6 +33,42 @@ class TestNum2int < Test::Unit::TestCase
FIXNUM_MAX = LONG_MAX/2
FIXNUM_MIN = LONG_MIN/2
+ def test_num2short
+ assert_output(SHRT_MIN.to_s) do
+ Num2int.print_num2short(SHRT_MIN)
+ end
+ assert_output(SHRT_MAX.to_s) do
+ Num2int.print_num2short(SHRT_MAX)
+ end
+ assert_raise(RangeError) do
+ Num2int.print_num2short(SHRT_MIN-1)
+ end
+ assert_raise(RangeError) do
+ Num2int.print_num2short(SHRT_MAX+1)
+ end
+ end
+
+ def test_num2ushort
+ assert_output("0") do
+ Num2int.print_num2ushort(0)
+ end
+ assert_output(USHRT_MAX.to_s) do
+ Num2int.print_num2ushort(USHRT_MAX)
+ end
+ assert_output(USHRT_MAX.to_s) do
+ Num2int.print_num2ushort(-1)
+ end
+ assert_output((SHRT_MAX+1).to_s) do
+ Num2int.print_num2ushort(SHRT_MIN)
+ end
+ assert_raise(RangeError) do
+ Num2int.print_num2ushort(SHRT_MIN-1)
+ end
+ assert_raise(RangeError) do
+ Num2int.print_num2ushort(USHRT_MAX+1)
+ end
+ end
+
def test_num2int
assert_output(INT_MIN.to_s) do
Num2int.print_num2int(INT_MIN)