* 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
This commit is contained in:
akr 2013-03-28 09:23:51 +00:00
Родитель 8affdf7859
Коммит 29e5699992
2 изменённых файлов: 30 добавлений и 17 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Thu Mar 28 18:22:21 2013 Tanaka Akira <akr@fsij.org>
* test/-ext-/num2int/test_num2int.rb: extract
assert_num2i_success_internal and assert_num2i_error_internal and
provide assertion messages as "NUM2XXX(NNN)".
Thu Mar 28 07:05:25 2013 Tanaka Akira <akr@fsij.org>
* include/ruby/intern.h: Delete redundant inclusions caused by

Просмотреть файл

@ -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)