summaryrefslogtreecommitdiff
path: root/test/-ext-/num2int
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-31 16:14:15 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-31 16:14:15 +0000
commita7526797a65a2f51bc93561c9545fddcd3c3e012 (patch)
treec25677641e922369956efed52af691bb053904a1 /test/-ext-/num2int
parentc68234f7d1fa9f2e9a1874b547f1f3e48eff5ae1 (diff)
* include/ruby/ruby.h (FIX2ULONG): Make it consistent with NUM2ULONG.
* ext/-test-/num2int/num2int.c: Add utility methods for FIX2XXX tests. * test/-ext-/num2int/test_num2int.rb: Add tests for FIX2XXX. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40023 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/num2int')
-rw-r--r--test/-ext-/num2int/test_num2int.rb74
1 files changed, 74 insertions, 0 deletions
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb
index df1c302..f32d2a1 100644
--- a/test/-ext-/num2int/test_num2int.rb
+++ b/test/-ext-/num2int/test_num2int.rb
@@ -83,6 +83,36 @@ class TestNum2int < Test::Unit::TestCase
end
end
+ def assert_fix2i_success_internal(exp, func, arg)
+ mesg = "#{func}(#{arg.inspect})"
+ method = "print_#{func}".downcase
+ out = err = nil
+ assert_nothing_raised(mesg) {
+ out, err = capture_io { Num2int.send(method, arg) }
+ }
+ STDERR.puts err if err && !err.empty?
+ assert_equal(exp, out, mesg)
+ end
+
+ def assert_fix2i_success(type, num, result=num)
+ return if !num.kind_of?(Fixnum)
+ func = "FIX2#{type}".upcase
+ assert_fix2i_success_internal(result.to_s, func, num)
+ end
+
+ def assert_fix2i_error_internal(func, arg)
+ method = "print_#{func}".downcase
+ assert_raise(RangeError, "#{func}(#{arg.inspect})") {
+ Num2int.send(method, arg)
+ }
+ end
+
+ def assert_fix2i_error(type, num)
+ return if !num.kind_of?(Fixnum)
+ func = "FIX2#{type}".upcase
+ assert_num2i_error_internal(func, num)
+ end
+
def test_num2short
assert_num2i_success(:short, SHRT_MIN)
assert_num2i_success(:short, SHRT_MAX)
@@ -162,6 +192,50 @@ class TestNum2int < Test::Unit::TestCase
assert_num2i_success(:ull, FIXNUM_MAX)
assert_num2i_success(:ull, FIXNUM_MAX+1)
end if defined?(Num2int.print_num2ull)
+
+ def test_fix2short
+ assert_fix2i_success(:short, 0)
+ assert_fix2i_success(:short, SHRT_MAX)
+ assert_fix2i_success(:short, SHRT_MIN)
+ assert_fix2i_error(:short, SHRT_MAX+1)
+ assert_fix2i_error(:short, SHRT_MIN-1)
+ assert_fix2i_error(:short, FIXNUM_MAX)
+ assert_fix2i_error(:short, FIXNUM_MIN)
+ end
+
+ def test_fix2int
+ assert_fix2i_success(:int, 0)
+ assert_fix2i_success(:int, INT_MAX)
+ assert_fix2i_success(:int, INT_MIN)
+ assert_fix2i_error(:int, INT_MAX+1)
+ assert_fix2i_error(:int, INT_MIN-1)
+ assert_fix2i_error(:int, FIXNUM_MAX) if INT_MAX < FIXNUM_MAX
+ assert_fix2i_error(:int, FIXNUM_MIN) if FIXNUM_MIN < INT_MIN
+ end
+
+ def test_fix2uint
+ assert_fix2i_success(:uint, 0)
+ assert_fix2i_success(:uint, UINT_MAX)
+ assert_fix2i_success(:uint, INT_MAX)
+ assert_fix2i_success(:uint, INT_MIN, INT_MAX+1)
+ assert_fix2i_error(:uint, UINT_MAX+1)
+ assert_fix2i_error(:uint, INT_MIN-1)
+ assert_fix2i_error(:uint, FIXNUM_MAX) if UINT_MAX < FIXNUM_MAX
+ assert_fix2i_error(:uint, FIXNUM_MIN) if FIXNUM_MIN < INT_MIN
+ end
+
+ def test_fix2long
+ assert_fix2i_success(:long, 0)
+ assert_fix2i_success(:long, FIXNUM_MAX)
+ assert_fix2i_success(:long, FIXNUM_MIN)
+ end
+
+ def test_fix2ulong
+ assert_fix2i_success(:ulong, 0)
+ assert_fix2i_success(:ulong, FIXNUM_MAX)
+ assert_fix2i_success(:ulong, -1, ULONG_MAX)
+ end
+
end