diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-19 09:44:26 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-06-19 09:44:26 +0900 |
commit | 28678997e40869f5591eae60edd9757334426ffb (patch) | |
tree | 76f6c6d8993e2b21cef090f1dcd030154bd1e018 /test/ruby/test_string.rb | |
parent | d009e321a08d2ca401fceefa638e7e50872f5f54 (diff) | |
download | ruby-28678997e40869f5591eae60edd9757334426ffb.tar.gz |
Preserve the string content at self-copying
* string.c (rb_str_init): preserve the embedded content when
self-copying with a capacity. [Bug #15937]
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r-- | test/ruby/test_string.rb | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb index 35f27c8b75..1d81d24dba 100644 --- a/test/ruby/test_string.rb +++ b/test/ruby/test_string.rb @@ -68,6 +68,15 @@ class TestString < Test::Unit::TestCase assert_raise(FrozenError){ str.__send__(:initialize, encoding: 'euc-jp') } assert_raise(FrozenError){ str.__send__(:initialize, 'abc', encoding: 'euc-jp') } assert_raise(FrozenError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') } + + str = S("") + assert_equal("mystring", str.__send__(:initialize, "mystring")) + str = S("mystring") + assert_equal("mystring", str.__send__(:initialize, str)) + str = S("") + assert_equal("mystring", str.__send__(:initialize, "mystring", capacity: 1000)) + str = S("mystring") + assert_equal("mystring", str.__send__(:initialize, str, capacity: 1000)) end def test_initialize_nonstring |