summaryrefslogtreecommitdiff
path: root/spec/ruby/optional/capi/string_spec.rb
diff options
context:
space:
mode:
authoreregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
committereregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-10-28 15:15:48 +0000
commit8c5b60eb22d6d661e87992a65d54e3a5bc0aeed4 (patch)
tree7905b284cb5b3d62c17ad8a939e339621a498a2c /spec/ruby/optional/capi/string_spec.rb
parent6530b14cee76e2512424d225e64d3c61dd1f6511 (diff)
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/optional/capi/string_spec.rb')
-rw-r--r--spec/ruby/optional/capi/string_spec.rb35
1 files changed, 30 insertions, 5 deletions
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb
index 25ef10b6f6..73e6deb498 100644
--- a/spec/ruby/optional/capi/string_spec.rb
+++ b/spec/ruby/optional/capi/string_spec.rb
@@ -100,6 +100,10 @@ describe "C-API String function" do
it "returns an empty string if len is 0" do
@s.rb_str_new("hello", 0).should == ""
end
+
+ it "returns a string from an offset char buffer" do
+ @s.rb_str_new_offset("hello", 1, 3).should == "ell"
+ end
end
describe "rb_str_new2" do
@@ -439,32 +443,53 @@ describe "C-API String function" do
end
end
- describe "StringValue" do
+ describe :string_value_macro, shared: true do
+ before :each do
+ @s = CApiStringSpecs.new
+ end
+
it "does not call #to_str on a String" do
str = "genuine"
str.should_not_receive(:to_str)
- @s.StringValue(str)
+ @s.send(@method, str)
end
it "does not call #to_s on a String" do
str = "genuine"
str.should_not_receive(:to_str)
- @s.StringValue(str)
+ @s.send(@method, str)
end
it "calls #to_str on non-String objects" do
str = mock("fake")
str.should_receive(:to_str).and_return("wannabe")
- @s.StringValue(str)
+ @s.send(@method, str).should == "wannabe"
end
it "does not call #to_s on non-String objects" do
str = mock("fake")
str.should_not_receive(:to_s)
- lambda { @s.StringValue(str) }.should raise_error(TypeError)
+ lambda { @s.send(@method, str) }.should raise_error(TypeError)
end
end
+ describe "StringValue" do
+ it_behaves_like :string_value_macro, :StringValue
+ end
+
+ describe "SafeStringValue" do
+ it "raises for tained string when $SAFE is 1" do
+ Thread.new {
+ $SAFE = 1
+ lambda {
+ @s.SafeStringValue("str".taint)
+ }.should raise_error(SecurityError)
+ }.join
+ end
+
+ it_behaves_like :string_value_macro, :SafeStringValue
+ end
+
describe "rb_str_resize" do
it "reduces the size of the string" do
str = @s.rb_str_resize("test", 2)