summaryrefslogtreecommitdiff
path: root/test/ruby/test_sprintf.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/ruby/test_sprintf.rb')
-rw-r--r--test/ruby/test_sprintf.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index c453ecd350..1c7e89c265 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -227,6 +227,10 @@ class TestSprintf < Test::Unit::TestCase
bug11766 = '[ruby-core:71806] [Bug #11766]'
assert_equal("x"*10+" 1.0", sprintf("x"*10+"%8.1f", 1r), bug11766)
+
+ require 'rbconfig/sizeof'
+ fmin, fmax = RbConfig::LIMITS.values_at("FIXNUM_MIN", "FIXNUM_MAX")
+ assert_match(/\A-\d+\.\d+\z/, sprintf("%f", Rational(fmin, fmax)))
end
def test_rational_precision
@@ -235,7 +239,7 @@ class TestSprintf < Test::Unit::TestCase
def test_hash
options = {:capture=>/\d+/}
- assert_equal("with options {:capture=>/\\d+/}", sprintf("with options %p" % options))
+ assert_equal("with options #{options.inspect}", sprintf("with options %p" % options))
end
def test_inspect
@@ -266,8 +270,8 @@ class TestSprintf < Test::Unit::TestCase
# Specifying the precision multiple times with negative star arguments:
assert_raise(ArgumentError, "[ruby-core:11570]") {sprintf("%.*.*.*.*f", -1, -1, -1, 5, 1)}
- # Null bytes after percent signs are removed:
- assert_equal("%\0x hello", sprintf("%\0x hello"), "[ruby-core:11571]")
+ assert_raise(ArgumentError) {sprintf("%\0x hello")}
+ assert_raise(ArgumentError) {sprintf("%\nx hello")}
assert_raise(ArgumentError, "[ruby-core:11573]") {sprintf("%.25555555555555555555555555555555555555s", "hello")}
@@ -279,10 +283,9 @@ class TestSprintf < Test::Unit::TestCase
assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$*d", 3) }
assert_raise_with_message(ArgumentError, /unnumbered\(1\) mixed with numbered/) { sprintf("%1$.*d", 3) }
- verbose, $VERBOSE = $VERBOSE, nil
- assert_nothing_raised { sprintf("", 1) }
- ensure
- $VERBOSE = verbose
+ assert_warning(/too many arguments/) do
+ sprintf("", 1)
+ end
end
def test_float
@@ -543,4 +546,12 @@ class TestSprintf < Test::Unit::TestCase
sprintf("%*s", RbConfig::LIMITS["INT_MIN"], "")
end
end
+
+ def test_binary_format_coderange
+ 1.upto(500) do |i|
+ str = sprintf("%*s".b, i, "\xe2".b)
+ refute_predicate str, :ascii_only?
+ assert_equal i, str.bytesize
+ end
+ end
end