diff options
author | Benoit Daloze <[email protected]> | 2023-04-25 17:04:25 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2023-04-25 17:09:53 +0200 |
commit | d562663e4098801c1d7fa7c64a335ea71231a598 (patch) | |
tree | 5b2ab2c9fbb86b4223263485fc5a3224562ae78d /spec/ruby/library/stringio/shared | |
parent | d3da01cd110ca99dd0249ee9af92e12cf845998c (diff) |
Update to ruby/spec@7f69c86
Diffstat (limited to 'spec/ruby/library/stringio/shared')
-rw-r--r-- | spec/ruby/library/stringio/shared/write.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/library/stringio/shared/write.rb b/spec/ruby/library/stringio/shared/write.rb index d9c21028e0..b91e6ecec1 100644 --- a/spec/ruby/library/stringio/shared/write.rb +++ b/spec/ruby/library/stringio/shared/write.rb @@ -88,6 +88,27 @@ describe :stringio_write_string, shared: true do @io.write "fghi" @io.string.should == "12fghi" end + + it "transcodes the given string when the external encoding is set and neither is BINARY" do + utf8_str = "hello" + io = StringIO.new.set_encoding(Encoding::UTF_16BE) + io.external_encoding.should == Encoding::UTF_16BE + + io.send(@method, utf8_str) + + expected = [0, 104, 0, 101, 0, 108, 0, 108, 0, 111] # UTF-16BE bytes for "hello" + io.string.bytes.should == expected + end + + it "does not transcode the given string when the external encoding is set and the string encoding is BINARY" do + str = "été".b + io = StringIO.new.set_encoding(Encoding::UTF_16BE) + io.external_encoding.should == Encoding::UTF_16BE + + io.send(@method, str) + + io.string.bytes.should == str.bytes + end end describe :stringio_write_not_writable, shared: true do |