summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-19 09:44:26 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-06-19 09:44:26 +0900
commit28678997e40869f5591eae60edd9757334426ffb (patch)
tree76f6c6d8993e2b21cef090f1dcd030154bd1e018 /test
parentd009e321a08d2ca401fceefa638e7e50872f5f54 (diff)
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')
-rw-r--r--test/ruby/test_string.rb9
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