diff options
Diffstat (limited to 'test/-ext-/string')
| -rw-r--r-- | test/-ext-/string/test_capacity.rb | 13 | ||||
| -rw-r--r-- | test/-ext-/string/test_interned_str.rb | 5 | ||||
| -rw-r--r-- | test/-ext-/string/test_set_len.rb | 2 |
3 files changed, 15 insertions, 5 deletions
diff --git a/test/-ext-/string/test_capacity.rb b/test/-ext-/string/test_capacity.rb index bcca64d85a..a23892142a 100644 --- a/test/-ext-/string/test_capacity.rb +++ b/test/-ext-/string/test_capacity.rb @@ -2,16 +2,17 @@ require 'test/unit' require '-test-/string' require 'rbconfig/sizeof' +require 'objspace' class Test_StringCapacity < Test::Unit::TestCase def test_capacity_embedded - assert_equal GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] - embed_header_size - 1, capa('foo') + assert_equal pool_slot_size(0) - embed_header_size - 1, capa('foo') assert_equal max_embed_len, capa('1' * max_embed_len) assert_equal max_embed_len, capa('1' * (max_embed_len - 1)) end def test_capacity_shared - sym = ("a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).to_sym + sym = ("a" * pool_slot_size(0)).to_sym assert_equal 0, capa(sym.to_s) end @@ -47,7 +48,7 @@ class Test_StringCapacity < Test::Unit::TestCase def test_capacity_frozen s = String.new("I am testing", capacity: 1000) - s << "a" * GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE] + s << "a" * pool_slot_size(0) s.freeze assert_equal(s.length, capa(s)) end @@ -66,7 +67,11 @@ class Test_StringCapacity < Test::Unit::TestCase end def embed_header_size - 3 * RbConfig::SIZEOF['void*'] + GC::INTERNAL_CONSTANTS[:RBASIC_SIZE] + RbConfig::SIZEOF['void*'] + end + + def pool_slot_size(_idx = 0) + Integer(ObjectSpace.dump("")[/"slot_size":(\d+)/, 1]) end def max_embed_len diff --git a/test/-ext-/string/test_interned_str.rb b/test/-ext-/string/test_interned_str.rb index 340dba41e8..a81cb59aa5 100644 --- a/test/-ext-/string/test_interned_str.rb +++ b/test/-ext-/string/test_interned_str.rb @@ -9,4 +9,9 @@ class Test_RbInternedStr < Test::Unit::TestCase src << "b" * 20 assert_equal "a" * 20, interned_str end + + def test_interned_str_encoding + src = :ascii.name + assert_equal Encoding::US_ASCII, Bug::String.rb_interned_str_dup(src).encoding + end end diff --git a/test/-ext-/string/test_set_len.rb b/test/-ext-/string/test_set_len.rb index 1531d76167..41e14a293a 100644 --- a/test/-ext-/string/test_set_len.rb +++ b/test/-ext-/string/test_set_len.rb @@ -5,7 +5,7 @@ require "-test-/string" class Test_StrSetLen < Test::Unit::TestCase def setup # Make string long enough so that it is not embedded - @range_end = ("0".ord + GC::INTERNAL_CONSTANTS[:BASE_SLOT_SIZE]).chr + @range_end = ("0".ord + GC.stat_heap(0, :slot_size)).chr @s0 = [*"0"..@range_end].join("").freeze @s1 = Bug::String.new(@s0) end |
