ruby-changes:27929
From: akr <ko1@a...>
Date: Thu, 28 Mar 2013 18:24:00 +0900 (JST)
Subject: [ruby-changes:27929] akr:r39981 (trunk): * test/-ext-/num2int/test_num2int.rb: extract
akr 2013-03-28 18:23:51 +0900 (Thu, 28 Mar 2013) New Revision: 39981 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=39981 Log: * test/-ext-/num2int/test_num2int.rb: extract assert_num2i_success_internal and assert_num2i_error_internal and provide assertion messages as "NUM2XXX(NNN)". Modified files: trunk/ChangeLog trunk/test/-ext-/num2int/test_num2int.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 39980) +++ ChangeLog (revision 39981) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu Mar 28 18:22:21 2013 Tanaka Akira <akr@f...> + + * 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@f...> * include/ruby/intern.h: Delete redundant inclusions caused by Index: test/-ext-/num2int/test_num2int.rb =================================================================== --- test/-ext-/num2int/test_num2int.rb (revision 39980) +++ test/-ext-/num2int/test_num2int.rb (revision 39981) @@ -31,27 +31,37 @@ class TestNum2int < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L31 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 https://github.com/ruby/ruby/blob/trunk/test/-ext-/num2int/test_num2int.rb#L98 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/