Permalink
Browse files

* 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
  • Loading branch information...
1 parent 8affdf7 commit 29e5699992c417e934f2b6ec0b559db454f9d0db @akr akr committed Mar 28, 2013
Showing with 30 additions and 17 deletions.
  1. +6 −0 ChangeLog
  2. +24 −17 test/-ext-/num2int/test_num2int.rb
View
@@ -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 @@ module Num2int
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 @@ def test_num2uint
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)

0 comments on commit 29e5699

Please sign in to comment.