summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 2d0eec02fd..0d14c9c932 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -181,6 +181,37 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_redefine_method('Hash', 'empty?', 'assert_nil({}.empty?); assert_nil({1=>1}.empty?)')
end
+ def test_hash_reuse_fstring
+ embed = -'h e l l o'
+ shared = -'this string is too long to be embedded and should be shared'
+ assert_not_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE],
+ ObjectSpace.memsize_of(shared),
+ 'update this test if string embedding changed'
+
+ [ embed, shared ].each do |exp|
+ key = exp.split(' ').join(' ')
+ h = {}
+ h[key] = true
+ assert_not_same key, h.keys[0]
+ assert_predicate h.keys[0], :frozen?
+ assert_same exp, h.keys[0]
+
+ h1 = {}
+ h2 = {}
+ key.taint
+ h1[key] = true
+ h2[key] = true
+ k1 = h1.keys[0]
+ k2 = h2.keys[0]
+ assert_same k1, k2
+ assert_predicate k1, :tainted?
+
+ assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE],
+ ObjectSpace.memsize_of(k1),
+ 'tainted string should share with untainted fstring'
+ end
+ end
+
def test_hash_aref_with
h = { "foo" => 1 }
assert_equal 1, h["foo"]