diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-28 09:23:51 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-03-28 09:23:51 +0000 |
commit | 29e5699992c417e934f2b6ec0b559db454f9d0db (patch) | |
tree | f1eb7ac577f54428488f50db9b9b5cc1df10bb2f /test | |
parent | 8affdf7859e505c6dcafdca6c1acdea470c00d2d (diff) | |
download | ruby-29e5699992c417e934f2b6ec0b559db454f9d0db.tar.gz |
* test/-ext-/num2int/test_num2int.rb: extract
assert_num2i_success_internal and assert_num2i_error_internal and
provide assertion messages as "NUM2XXX(NNN)".
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39981 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/-ext-/num2int/test_num2int.rb | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb index dfc334c786..2ec12c099d 100644 --- a/test/-ext-/num2int/test_num2int.rb +++ b/test/-ext-/num2int/test_num2int.rb @@ -31,27 +31,37 @@ class TestNum2int < Test::Unit::TestCase FIXNUM_MAX = LONG_MAX/2 FIXNUM_MIN = LONG_MIN/2 + def assert_num2i_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_num2i_success(type, num, result=num) - method = "print_num2#{type}" - assert_output(result.to_s) do - Num2int.send(method, num) - end + func = "NUM2#{type}".upcase + assert_num2i_success_internal(result.to_s, func, num) if num.to_f.to_i == num - assert_output(result.to_s) do - Num2int.send(method, num.to_f) - end + assert_num2i_success_internal(result.to_s, func, num.to_f) end end + def assert_num2i_error_internal(func, arg) + method = "print_#{func}".downcase + assert_raise(RangeError, "#{func}(#{arg.inspect})") { + Num2int.send(method, arg) + } + end + def assert_num2i_error(type, num) - method = "print_num2#{type}" - assert_raise(RangeError) do - Num2int.send(method, num) - end + func = "NUM2#{type}".upcase + assert_num2i_error_internal(func, num) if num.to_f.to_i == num - assert_raise(RangeError) do - Num2int.send(method, num) - end + assert_num2i_error_internal(func, num.to_f) end end @@ -88,9 +98,6 @@ class TestNum2int < Test::Unit::TestCase end def test_num2long - #assert_output(LONG_MIN.to_s) do - # Num2int.print_num2long(LONG_MIN.to_f) - #end assert_num2i_success(:long, LONG_MIN) assert_num2i_success(:long, LONG_MAX) assert_num2i_error(:long, LONG_MIN-1) |