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.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/test/ruby/test_sprintf.rb b/test/ruby/test_sprintf.rb
index 595bf6d..c80f88b 100644
--- a/test/ruby/test_sprintf.rb
+++ b/test/ruby/test_sprintf.rb
@@ -451,4 +451,14 @@ class TestSprintf < Test::Unit::TestCase
bug = 'https://github.com/mruby/mruby/issues/3347'
assert_equal("!", sprintf("%*c", 0, ?!.ord), bug)
end
+
+ def test_no_hidden_garbage
+ fmt = [4, 2, 2].map { |x| "%0#{x}d" }.join('-') # defeats optimization
+ ObjectSpace.count_objects(res = {}) # creates strings on first call
+ before = ObjectSpace.count_objects(res)[:T_STRING]
+ val = sprintf(fmt, 1970, 1, 1)
+ after = ObjectSpace.count_objects(res)[:T_STRING]
+ assert_equal before + 1, after, 'only new string is the created one'
+ assert_equal '1970-01-01', val
+ end
end