Skip to content

Commit

Permalink
Add spec for modifying a copied string with String#setbyte
Browse files Browse the repository at this point in the history
  • Loading branch information
dbussink committed Apr 30, 2012
1 parent cb3843b commit 981ab2c
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion spec/ruby/core/string/setbyte_spec.rb
Expand Up @@ -18,7 +18,7 @@
str = "a"
str.setbyte(0,98)
str.should == 'b'

# copy-on-write case
str1, str2 = "fooXbar".split("X")
str2.setbyte(0, 50)
Expand Down Expand Up @@ -66,6 +66,16 @@
chr.should == "\xe0\xa6\x96"
end

it "does not modify the original string when using String.new" do
str1 = "hedgehog"
str2 = String.new(str1)
str2.setbyte(0, 108)
str2.should == "ledgehog"
str2.should_not == "hedgehog"
str1.should == "hedgehog"
str1.should_not == "ledgehog"
end

it "raises a RuntimeError if self is frozen" do
str = "cold".freeze
str.frozen?.should be_true
Expand Down

0 comments on commit 981ab2c

Please sign in to comment.