summaryrefslogtreecommitdiff
path: root/test/-ext-/test_printf.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-19 07:25:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-19 07:25:09 +0000
commit170344b20ec9e3340d9bb41e9f7434ccd2ae6365 (patch)
tree38d111015f600d013efb72d035108ebe33e8c518 /test/-ext-/test_printf.rb
parent3145683203c5673da67676fecb4b7efdfec72653 (diff)
vsnprintf.c: initialize cp
* vsnprintf.c (BSD_vfprintf): initialize cp so that size is 0 in the commented case. fix an accidental bug at r16716. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42977 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/-ext-/test_printf.rb')
-rw-r--r--test/-ext-/test_printf.rb138
1 files changed, 138 insertions, 0 deletions
diff --git a/test/-ext-/test_printf.rb b/test/-ext-/test_printf.rb
index 4532c371b4..609af7ca7a 100644
--- a/test/-ext-/test_printf.rb
+++ b/test/-ext-/test_printf.rb
@@ -1,5 +1,6 @@
require 'test/unit'
require "-test-/printf"
+require_relative '../ruby/allpairs'
class Test_SPrintf < Test::Unit::TestCase
def to_s
@@ -43,4 +44,141 @@ class Test_SPrintf < Test::Unit::TestCase
inspect: Bug::Printf.v(obj).tainted?,
})
end
+
+ VS = [
+ #-0x1000000000000000000000000000000000000000000000002,
+ #-0x1000000000000000000000000000000000000000000000001,
+ #-0x1000000000000000000000000000000000000000000000000,
+ #-0xffffffffffffffffffffffffffffffffffffffffffffffff,
+ #-0x1000000000000000000000002,
+ #-0x1000000000000000000000001,
+ #-0x1000000000000000000000000,
+ #-0xffffffffffffffffffffffff,
+ -0x10000000000000002,
+ -0x10000000000000001,
+ -0x10000000000000000,
+ -0xffffffffffffffff,
+ -0x4000000000000002,
+ -0x4000000000000001,
+ -0x4000000000000000,
+ -0x3fffffffffffffff,
+ -0x100000002,
+ -0x100000001,
+ -0x100000000,
+ -0xffffffff,
+ #-0xc717a08d, # 0xc717a08d * 0x524b2245 = 0x4000000000000001
+ -0x80000002,
+ -0x80000001,
+ -0x80000000,
+ -0x7fffffff,
+ #-0x524b2245,
+ -0x40000002,
+ -0x40000001,
+ -0x40000000,
+ -0x3fffffff,
+ #-0x10002,
+ #-0x10001,
+ #-0x10000,
+ #-0xffff,
+ #-0x8101, # 0x8101 * 0x7f01 = 0x40000001
+ #-0x8002,
+ #-0x8001,
+ #-0x8000,
+ #-0x7fff,
+ #-0x7f01,
+ #-65,
+ #-64,
+ #-63,
+ #-62,
+ #-33,
+ #-32,
+ #-31,
+ #-30,
+ -3,
+ -2,
+ -1,
+ 0,
+ 1,
+ 2,
+ 3,
+ #30,
+ #31,
+ #32,
+ #33,
+ #62,
+ #63,
+ #64,
+ #65,
+ #0x7f01,
+ #0x7ffe,
+ #0x7fff,
+ #0x8000,
+ #0x8001,
+ #0x8101,
+ #0xfffe,
+ #0xffff,
+ #0x10000,
+ #0x10001,
+ 0x3ffffffe,
+ 0x3fffffff,
+ 0x40000000,
+ 0x40000001,
+ #0x524b2245,
+ 0x7ffffffe,
+ 0x7fffffff,
+ 0x80000000,
+ 0x80000001,
+ #0xc717a08d,
+ 0xfffffffe,
+ 0xffffffff,
+ 0x100000000,
+ 0x100000001,
+ 0x3ffffffffffffffe,
+ 0x3fffffffffffffff,
+ 0x4000000000000000,
+ 0x4000000000000001,
+ 0xfffffffffffffffe,
+ 0xffffffffffffffff,
+ 0x10000000000000000,
+ 0x10000000000000001,
+ #0xffffffffffffffffffffffff,
+ #0x1000000000000000000000000,
+ #0x1000000000000000000000001,
+ #0xffffffffffffffffffffffffffffffffffffffffffffffff,
+ #0x1000000000000000000000000000000000000000000000000,
+ #0x1000000000000000000000000000000000000000000000001
+ ]
+ VS.reverse!
+
+ FLAGS = [[nil, ' '], [nil, '#'], [nil, '+'], [nil, '-'], [nil, '0']]
+
+ def self.assertions_format_integer(format, type, **opts)
+ proc {
+ VS.each {|v|
+ begin
+ r = Bug::Printf.(type, v, **opts)
+ rescue RangeError
+ else
+ e = sprintf format, v
+ assert_equal([e, format], r, "rb_sprintf(#{format.dump}, #{v})")
+ end
+ }
+ }
+ end
+
+ AllPairs.each(%w[d],
+ # octal and hexadecimal deal with negative values differently
+ [nil, 0, 5, 20],
+ [nil, true, 0], # 8, 20
+ *FLAGS) {
+ |type, width, prec, sp, hs, pl, mi, zr|
+ precision = ".#{prec unless prec == true}" if prec
+ format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ define_method("test_format_integer(#{format})",
+ assertions_format_integer(format, type,
+ space: sp, hash: hs,
+ plus: pl, minus: mi,
+ zero: zr, width: width,
+ prec: prec))
+ }
end