summaryrefslogtreecommitdiff
path: root/test/-ext-/num2int
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-28 09:23:51 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-03-28 09:23:51 +0000
commit29e5699992c417e934f2b6ec0b559db454f9d0db (patch)
treef1eb7ac577f54428488f50db9b9b5cc1df10bb2f /test/-ext-/num2int
parent8affdf7859e505c6dcafdca6c1acdea470c00d2d (diff)
* 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/-ext-/num2int')
-rw-r--r--test/-ext-/num2int/test_num2int.rb41
1 files changed, 24 insertions, 17 deletions
diff --git a/test/-ext-/num2int/test_num2int.rb b/test/-ext-/num2int/test_num2int.rb
index dfc334c..2ec12c0 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)