From 5d7af9d9c089ee7fd85b195a929ea5964ca27d5c Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 10 Sep 2023 13:10:48 +0200 Subject: [PATCH] Add tests for combination of {bin,text}mode and external_encoding in IO.new The encoding option takes precedence over the binmode/textmode options. There are similar tests for passing the binmode argument in the mode argument. --- core/io/shared/new.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/core/io/shared/new.rb b/core/io/shared/new.rb index cba5f33eb..cb7b50838 100644 --- a/core/io/shared/new.rb +++ b/core/io/shared/new.rb @@ -208,6 +208,26 @@ @io.internal_encoding.to_s.should == 'IBM866' end + it "does not use binmode argument when mode encoding is specified" do + @io = IO.send(@method, @fd, 'w:iso-8859-1', binmode: true) + @io.external_encoding.to_s.should == 'ISO-8859-1' + end + + it "does not use textmode argument when mode encoding is specified" do + @io = IO.send(@method, @fd, 'w:ascii-8bit', textmode: true) + @io.external_encoding.to_s.should == 'ASCII-8BIT' + end + + it "does not use binmode argument when external encoding is specified via the :external_encoding option" do + @io = IO.send(@method, @fd, 'w', binmode: true, external_encoding: 'iso-8859-1') + @io.external_encoding.to_s.should == 'ISO-8859-1' + end + + it "does not use textmode argument when external encoding is specified via the :external_encoding option" do + @io = IO.send(@method, @fd, 'w', textmode: true, external_encoding: 'ascii-8bit') + @io.external_encoding.to_s.should == 'ASCII-8BIT' + end + it "raises ArgumentError for nil options" do -> { IO.send(@method, @fd, 'w', nil)