aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/string
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-09-30 12:21:48 +0200
committerBenoit Daloze <eregontp@gmail.com>2020-09-30 12:21:48 +0200
commit201d50164016bc519041af302f47d92f314abac5 (patch)
tree688544ac063d8a3825d96474055f5c11ad471972 /spec/ruby/core/string
parentce986b41caa1f23b6d07914b8eca62fdff24e034 (diff)
downloadruby-201d50164016bc519041af302f47d92f314abac5.tar.gz
Update to ruby/spec@9277d27
Diffstat (limited to 'spec/ruby/core/string')
-rw-r--r--spec/ruby/core/string/encode_spec.rb31
1 files changed, 26 insertions, 5 deletions
diff --git a/spec/ruby/core/string/encode_spec.rb b/spec/ruby/core/string/encode_spec.rb
index 04d9db855a..ae641b2110 100644
--- a/spec/ruby/core/string/encode_spec.rb
+++ b/spec/ruby/core/string/encode_spec.rb
@@ -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