summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/string_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-20 20:38:57 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2019-01-20 20:38:57 +0000
commit6204e0804b24f1675b49d5880da014411bcfb831 (patch)
treece6c00bf078fc416936ca3cdc972b9b3c1c78dae /spec/ruby/optional/capi/string_spec.rb
parent58573c33e4720315ed27491e31dcc22892e1ce95 (diff)
Update to ruby/spec@35a9fba
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi/string_spec.rb')
-rw-r--r--spec/ruby/optional/capi/string_spec.rb75
1 files changed, 43 insertions, 32 deletions
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