diff options
Diffstat (limited to 'spec/ruby/optional/capi/string_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 06b0c9cbf7..5ad8169e8e 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -558,10 +558,33 @@ describe "C-API String function" do it_behaves_like :string_value_macro, :SafeStringValue end + describe "rb_str_modify_expand" do + it "grows the capacity to bytesize + expand, not changing the bytesize" do + str = @s.rb_str_buf_new(256, "abcd") + @s.rb_str_capacity(str).should == 256 + + @s.rb_str_set_len(str, 3) + str.bytesize.should == 3 + @s.RSTRING_LEN(str).should == 3 + @s.rb_str_capacity(str).should == 256 + + @s.rb_str_modify_expand(str, 4) + str.bytesize.should == 3 + @s.RSTRING_LEN(str).should == 3 + @s.rb_str_capacity(str).should == 7 + + @s.rb_str_modify_expand(str, 1024) + str.bytesize.should == 3 + @s.RSTRING_LEN(str).should == 3 + @s.rb_str_capacity(str).should == 1027 + end + end + describe "rb_str_resize" do it "reduces the size of the string" do str = @s.rb_str_resize("test", 2) str.size.should == 2 + str.bytesize.should == 2 @s.RSTRING_LEN(str).should == 2 str.should == "te" end @@ -574,6 +597,7 @@ describe "C-API String function" do expected = "test".force_encoding("US-ASCII") str = @s.rb_str_resize(expected.dup, 12) str.size.should == 12 + str.bytesize.should == 12 @s.RSTRING_LEN(str).should == 12 str[0, 4].should == expected end |