1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
This commit is contained in:
Benoit Daloze 2020-09-30 12:21:48 +02:00
parent ce986b41ca
commit 201d501640
17 changed files with 209 additions and 6 deletions

View file

@ -19,13 +19,17 @@ describe "String#encode" do
it "returns a copy when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = ""
str.encode.should_not equal(str)
encoded = str.encode
encoded.should_not equal(str)
encoded.should == str
end
it "returns a copy for a ASCII-only String when Encoding.default_internal is nil" do
Encoding.default_internal = nil
str = "abc"
str.encode.should_not equal(str)
encoded = str.encode
encoded.should_not equal(str)
encoded.should == str
end
it "encodes an ascii substring of a binary string to UTF-8" do
@ -39,7 +43,9 @@ describe "String#encode" do
describe "when passed to encoding" do
it "returns a copy when passed the same encoding as the String" do
str = ""
str.encode(Encoding::UTF_8).should_not equal(str)
encoded = str.encode(Encoding::UTF_8)
encoded.should_not equal(str)
encoded.should == str
end
it "round trips a String" do
@ -75,6 +81,7 @@ describe "String#encode" do
encoded = str.encode("utf-8", "utf-8")
encoded.should_not equal(str)
encoded.should == str.force_encoding("utf-8")
encoded.encoding.should == Encoding::UTF_8
end
@ -87,14 +94,28 @@ describe "String#encode" do
describe "when passed to, options" do
it "returns a copy when the destination encoding is the same as the String encoding" do
str = ""
str.encode(Encoding::UTF_8, undef: :replace).should_not equal(str)
encoded = str.encode(Encoding::UTF_8, undef: :replace)
encoded.should_not equal(str)
encoded.should == str
end
end
describe "when passed to, from, options" do
it "returns a copy when both encodings are the same" do
str = ""
str.encode("utf-8", "utf-8", invalid: :replace).should_not equal(str)
encoded = str.encode("utf-8", "utf-8", invalid: :replace)
encoded.should_not equal(str)
encoded.should == str
end
it "returns a copy in the destination encoding when both encodings are the same" do
str = ""
str.force_encoding("binary")
encoded = str.encode("utf-8", "utf-8", invalid: :replace)
encoded.should_not equal(str)
encoded.should == str.force_encoding("utf-8")
encoded.encoding.should == Encoding::UTF_8
end
end
end