diff options
Diffstat (limited to 'spec/ruby/optional/capi/string_spec.rb')
-rw-r--r-- | spec/ruby/optional/capi/string_spec.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/spec/ruby/optional/capi/string_spec.rb b/spec/ruby/optional/capi/string_spec.rb index 35a6fd1c92..7c33b79348 100644 --- a/spec/ruby/optional/capi/string_spec.rb +++ b/spec/ruby/optional/capi/string_spec.rb @@ -218,6 +218,20 @@ describe "C-API String function" do end end + describe "rb_usascii_str_new_lit" do + it "returns a US-ASCII string of the correct characters" do + str = @s.rb_usascii_str_new_lit + str.should == "nokogiri" + str.encoding.should == Encoding::US_ASCII + end + + it "returns US-ASCII string for non-US-ASCII string literal" do + str = @s.rb_usascii_str_new_lit_non_ascii + str.should == "r\xC3\xA9sum\xC3\xA9".force_encoding(Encoding::US_ASCII) + str.encoding.should == Encoding::US_ASCII + end + end + describe "rb_usascii_str_new_cstr" do it "creates a new String with US-ASCII Encoding" do str = "abc".force_encoding("us-ascii") @@ -392,6 +406,16 @@ describe "C-API String function" do end end + describe "rb_enc_str_buf_cat" do + it "concatenates a C string literal to a ruby string with the given encoding" do + input = "hello ".force_encoding(Encoding::US_ASCII) + result = @s.rb_enc_str_buf_cat(input, "résumé", Encoding::UTF_8) + result.should == "hello résumé" + result.encoding.should == Encoding::UTF_8 + result.object_id.should == input.object_id + end + end + describe "rb_str_cmp" do it "returns 0 if two strings are identical" do @s.rb_str_cmp("ppp", "ppp").should == 0 |