diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-21 15:38:59 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-21 15:38:59 +0000 |
commit | da7976235fbc2986925969646071bebe3702e49f (patch) | |
tree | 83bbf6a8e03cf990369feabe6c1c9d45c69f4c85 /spec/ruby/optional/capi | |
parent | b8e389a0f3226c90e96e02e6396686a3bef6a456 (diff) | |
download | ruby-da7976235fbc2986925969646071bebe3702e49f.tar.gz |
Update to ruby/spec@7a16e01
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67112 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi')
-rw-r--r-- | spec/ruby/optional/capi/ext/string_spec.c | 6 | ||||
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/ext/string_spec.c b/spec/ruby/optional/capi/ext/string_spec.c index 2b0ea5dd9c..3eeceae743 100644 --- a/spec/ruby/optional/capi/ext/string_spec.c +++ b/spec/ruby/optional/capi/ext/string_spec.c @@ -232,6 +232,11 @@ VALUE string_spec_rb_str_times(VALUE self, VALUE str, VALUE times) { return rb_str_times(str, times); } +VALUE string_spec_rb_str_modify_expand(VALUE self, VALUE str, VALUE size) { + rb_str_modify_expand(str, FIX2LONG(size)); + return str; +} + VALUE string_spec_rb_str_resize(VALUE self, VALUE str, VALUE size) { return rb_str_resize(str, FIX2INT(size)); } @@ -435,6 +440,7 @@ void Init_string_spec(void) { rb_define_method(cls, "rb_tainted_str_new2", string_spec_rb_tainted_str_new2, 1); rb_define_method(cls, "rb_str_plus", string_spec_rb_str_plus, 2); rb_define_method(cls, "rb_str_times", string_spec_rb_str_times, 2); + rb_define_method(cls, "rb_str_modify_expand", string_spec_rb_str_modify_expand, 2); rb_define_method(cls, "rb_str_resize", string_spec_rb_str_resize, 2); rb_define_method(cls, "rb_str_resize_RSTRING_LEN", string_spec_rb_str_resize_RSTRING_LEN, 2); rb_define_method(cls, "rb_str_set_len", string_spec_rb_str_set_len, 2); 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 |