summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-15 13:51:27 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-09-15 13:51:27 +0000
commit64eeb5f3029e85e5edfefa0957547501b7417c12 (patch)
treeb994acf63f253b7054c027c199ec304d7e974bf4 /test
parentb3571b55971e92458cba6c13177bae7a9d9b6ffd (diff)
merge revision(s) 42908,42918: [Backport #8864]
test_sprintf_comb.rb: split tests * test/ruby/test_sprintf_comb.rb (test_format_integer), (test_format_float): split huge tests by the formats. * vsnprintf.c (MAXEXP, MAXFRACT): calculate depending on constants in float.h. * vsnprintf.c (BSD_vfprintf): limit length for cvt() to get rid of buffer overflow. [ruby-core:57023] [Bug #8864] * vsnprintf.c (exponent): make expbuf size more precise. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@42944 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_sprintf_comb.rb46
1 files changed, 23 insertions, 23 deletions
diff --git a/test/ruby/test_sprintf_comb.rb b/test/ruby/test_sprintf_comb.rb
index 261732bcbc..c58ddf4f15 100644
--- a/test/ruby/test_sprintf_comb.rb
+++ b/test/ruby/test_sprintf_comb.rb
@@ -107,7 +107,9 @@ class TestSprintfComb < Test::Unit::TestCase
]
VS.reverse!
- def combination(*args, &b)
+ FLAGS = [['', ' '], ['', '#'], ['', '+'], ['', '-'], ['', '0']]
+
+ def self.combination(*args, &b)
#AllPairs.exhaustive_each(*args, &b)
AllPairs.each(*args, &b)
end
@@ -268,17 +270,8 @@ class TestSprintfComb < Test::Unit::TestCase
str
end
- def test_format_integer
- combination(
- %w[B b d o X x],
- [nil, 0, 5, 20],
- ["", ".", ".0", ".8", ".20"],
- ['', ' '],
- ['', '#'],
- ['', '+'],
- ['', '-'],
- ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr|
- format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ def self.assertions_format_integer(format)
+ proc {
VS.each {|v|
r = sprintf format, v
e = emu_int format, v
@@ -293,6 +286,14 @@ class TestSprintfComb < Test::Unit::TestCase
}
end
+ combination(%w[B b d o X x],
+ [nil, 0, 5, 20],
+ ["", ".", ".0", ".8", ".20"],
+ *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr|
+ format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ define_method("test_format_integer(#{format})", assertions_format_integer(format))
+ }
+
FLOAT_VALUES = [
-1e100,
-123456789.0,
@@ -526,17 +527,8 @@ class TestSprintfComb < Test::Unit::TestCase
end
- def test_format_float
- combination(
- %w[e E f g G],
- [nil, 0, 5, 20],
- ["", ".", ".0", ".8", ".20", ".200"],
- ['', ' '],
- ['', '#'],
- ['', '+'],
- ['', '-'],
- ['', '0']) {|type, width, precision, sp, hs, pl, mi, zr|
- format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ def self.assertions_format_float(format)
+ proc {
FLOAT_VALUES.each {|v|
r = sprintf format, v
e = emu_float format, v
@@ -550,4 +542,12 @@ class TestSprintfComb < Test::Unit::TestCase
}
}
end
+
+ combination(%w[e E f g G],
+ [nil, 0, 5, 20],
+ ["", ".", ".0", ".8", ".20", ".200", ".9999"],
+ *FLAGS) {|type, width, precision, sp, hs, pl, mi, zr|
+ format = "%#{sp}#{hs}#{pl}#{mi}#{zr}#{width}#{precision}#{type}"
+ define_method("test_format_float(#{format})", assertions_format_float(format))
+ }
end