diff options
Diffstat (limited to 'spec/ruby/optional/capi/string_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index ac23198662..79cdb524ad 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -167,6 +167,10 @@ describe "C-API String function" do @s.rb_str_new("hello", 3).should == "hel" end + it "returns a non-tainted string" do + @s.rb_str_new("hello", 5).tainted?.should == false + end + it "returns an empty string if len is 0" do @s.rb_str_new("hello", 0).should == "" end @@ -877,6 +881,27 @@ describe "C-API String function" do end end + describe "rb_str_export_to_enc" do + it "returns a copy of an ascii string converted to the new encoding" do + source = "A simple string".encode(Encoding::US_ASCII) + result = @s.rb_str_export_to_enc(source, Encoding::UTF_8) + result.should == source.encode(Encoding::UTF_8) + result.encoding.should == Encoding::UTF_8 + end + + it "returns the source string if it can not be converted" do + source = ["00ff"].pack("H*"); + result = @s.rb_str_export_to_enc(source, Encoding::UTF_8) + result.should equal(source) + end + + it "does not alter the source string if it can not be converted" do + source = ["00ff"].pack("H*"); + result = @s.rb_str_export_to_enc(source, Encoding::UTF_8) + source.bytes.should == [0, 255] + end +end + describe "rb_sprintf" do it "replaces the parts like sprintf" do @s.rb_sprintf1("Awesome %s is replaced", "string").should == "Awesome string is replaced" |