From 6204e0804b24f1675b49d5880da014411bcfb831 Mon Sep 17 00:00:00 2001 From: eregon Date: Sun, 20 Jan 2019 20:38:57 +0000 Subject: Update to ruby/spec@35a9fba git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/optional/capi/string_spec.rb | 75 +++++++++++++++++++--------------- 1 file changed, 43 insertions(+), 32 deletions(-) (limited to 'spec/ruby/optional/capi/string_spec.rb') diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index cfd60c2593..06b0c9cbf7 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -32,45 +32,56 @@ describe "C-API String function" do end end - describe "rb_str_set_len" do - before :each do - # Make a completely new copy of the string - # for every example (#dup doesn't cut it). - @str = "abcdefghij" - @s.rb_str_modify(@str) - end + [Encoding::BINARY, Encoding::UTF_8].each do |enc| + describe "rb_str_set_len on a #{enc.name} String" do + before :each do + @str = "abcdefghij".force_encoding(enc) + # Make sure to unshare the string + @s.rb_str_modify(@str) + end - it "reduces the size of the string" do - @s.rb_str_set_len(@str, 5).should == "abcde" - end + it "reduces the size of the string" do + @s.rb_str_set_len(@str, 5).should == "abcde" + end - it "inserts a NULL byte at the length" do - @s.rb_str_set_len(@str, 5).should == "abcde" - @s.rb_str_set_len(@str, 8).should == "abcde\x00gh" - end + it "inserts a NULL byte at the length" do + @s.rb_str_set_len(@str, 5).should == "abcde" + @s.rb_str_set_len(@str, 8).should == "abcde\x00gh" + end - it "updates the byte size and character size" do - @s.rb_str_set_len(@str, 4) - @str.bytesize.should == 4 - @str.size.should == 4 - @str.should == "abcd" - end + it "updates the byte size" do + @s.rb_str_set_len(@str, 4) + @str.bytesize.should == 4 + @str.should == "abcd" + end - it "updates the string's attributes visible in C code" do - @s.rb_str_set_len_RSTRING_LEN(@str, 4).should == 4 - end + it "invalidates the character size" do + @str.size.should == 10 + @s.rb_str_set_len(@str, 4) + @str.size.should == 4 + @str.should == "abcd" + end - it "can reveal characters written from C with RSTRING_PTR" do - @s.rb_str_set_len(@str, 1) - @str.should == "a" + it "invalidates the code range" do + @s.rb_str_set_len(@str, 4) + @str.ascii_only?.should == true + end - @str.force_encoding(Encoding::UTF_8) - @s.RSTRING_PTR_set(@str, 1, 'B'.ord) - @s.RSTRING_PTR_set(@str, 2, 'C'.ord) - @s.rb_str_set_len(@str, 3) + it "updates the string's attributes visible in C code" do + @s.rb_str_set_len_RSTRING_LEN(@str, 4).should == 4 + end + + it "can reveal characters written from C with RSTRING_PTR" do + @s.rb_str_set_len(@str, 1) + @str.should == "a" - @str.bytesize.should == 3 - @str.should == "aBC" + @s.RSTRING_PTR_set(@str, 1, 'B'.ord) + @s.RSTRING_PTR_set(@str, 2, 'C'.ord) + @s.rb_str_set_len(@str, 3) + + @str.bytesize.should == 3 + @str.should == "aBC" + end end end -- cgit v1.2.3