Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* 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...
commit 29e5699992c417e934f2b6ec0b559db454f9d0db 1 parent 8affdf7
akr authored March 28, 2013
6  ChangeLog
... ...
@@ -1,3 +1,9 @@
  1
+Thu Mar 28 18:22:21 2013  Tanaka Akira  <akr@fsij.org>
  2
+
  3
+	* test/-ext-/num2int/test_num2int.rb: extract
  4
+	  assert_num2i_success_internal and assert_num2i_error_internal and
  5
+	  provide assertion messages as "NUM2XXX(NNN)".
  6
+
1 7
 Thu Mar 28 07:05:25 2013  Tanaka Akira  <akr@fsij.org>
2 8
 
3 9
 	* include/ruby/intern.h: Delete redundant inclusions caused by
41  test/-ext-/num2int/test_num2int.rb
@@ -31,27 +31,37 @@ module Num2int
31 31
   FIXNUM_MAX = LONG_MAX/2
32 32
   FIXNUM_MIN = LONG_MIN/2
33 33
 
  34
+  def assert_num2i_success_internal(exp, func, arg)
  35
+    mesg = "#{func}(#{arg.inspect})"
  36
+    method = "print_#{func}".downcase
  37
+    out = err = nil
  38
+    assert_nothing_raised(mesg) {
  39
+      out, err = capture_io { Num2int.send(method, arg) }
  40
+    }
  41
+    STDERR.puts err if err && !err.empty?
  42
+    assert_equal(exp, out, mesg)
  43
+  end
  44
+
34 45
   def assert_num2i_success(type, num, result=num)
35  
-    method = "print_num2#{type}"
36  
-    assert_output(result.to_s) do
37  
-      Num2int.send(method, num)
38  
-    end
  46
+    func = "NUM2#{type}".upcase
  47
+    assert_num2i_success_internal(result.to_s, func, num)
39 48
     if num.to_f.to_i == num
40  
-      assert_output(result.to_s) do
41  
-	Num2int.send(method, num.to_f)
42  
-      end
  49
+      assert_num2i_success_internal(result.to_s, func, num.to_f)
43 50
     end
44 51
   end
45 52
 
  53
+  def assert_num2i_error_internal(func, arg)
  54
+    method = "print_#{func}".downcase
  55
+    assert_raise(RangeError, "#{func}(#{arg.inspect})") {
  56
+      Num2int.send(method, arg)
  57
+    }
  58
+  end
  59
+
46 60
   def assert_num2i_error(type, num)
47  
-    method = "print_num2#{type}"
48  
-    assert_raise(RangeError) do
49  
-      Num2int.send(method, num)
50  
-    end
  61
+    func = "NUM2#{type}".upcase
  62
+    assert_num2i_error_internal(func, num)
51 63
     if num.to_f.to_i == num
52  
-      assert_raise(RangeError) do
53  
-	Num2int.send(method, num)
54  
-      end
  64
+      assert_num2i_error_internal(func, num.to_f)
55 65
     end
56 66
   end
57 67
 
@@ -88,9 +98,6 @@ def test_num2uint
88 98
   end
89 99
 
90 100
   def test_num2long
91  
-    #assert_output(LONG_MIN.to_s) do
92  
-    #  Num2int.print_num2long(LONG_MIN.to_f)
93  
-    #end
94 101
     assert_num2i_success(:long, LONG_MIN)
95 102
     assert_num2i_success(:long, LONG_MAX)
96 103
     assert_num2i_error(:long, LONG_MIN-1)

0 notes on commit 29e5699

Please sign in to comment.
Something went wrong with that request. Please try again.