Skip to content

Commit 740780d

Browse files
committed
Add spec for String#initialize_copy not sharing bytes after #setbyte
1 parent eab51d1 commit 740780d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

spec/ruby/core/string/dup_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,13 @@ class << @obj
4949
orig.should == "xtring"
5050
dup.should == "string"
5151
end
52+
53+
it "does not modify the original setbyte-mutated string when changing dupped string" do
54+
orig = "a"
55+
orig.setbyte 0, "b".ord
56+
copy = orig.dup
57+
orig.setbyte 0, "c".ord
58+
orig.should == "c"
59+
copy.should == "b"
60+
end
5261
end

0 commit comments

Comments
 (0)