Skip to content

Commit 2ef6421

Browse files
herwinweregon
authored andcommitted
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.
1 parent 5f9867c commit 2ef6421

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

core/io/shared/new.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@
208208
@io.internal_encoding.to_s.should == 'IBM866'
209209
end
210210

211+
it "does not use binmode argument when mode encoding is specified" do
212+
@io = IO.send(@method, @fd, 'w:iso-8859-1', binmode: true)
213+
@io.external_encoding.to_s.should == 'ISO-8859-1'
214+
end
215+
216+
it "does not use textmode argument when mode encoding is specified" do
217+
@io = IO.send(@method, @fd, 'w:ascii-8bit', textmode: true)
218+
@io.external_encoding.to_s.should == 'ASCII-8BIT'
219+
end
220+
221+
it "does not use binmode argument when external encoding is specified via the :external_encoding option" do
222+
@io = IO.send(@method, @fd, 'w', binmode: true, external_encoding: 'iso-8859-1')
223+
@io.external_encoding.to_s.should == 'ISO-8859-1'
224+
end
225+
226+
it "does not use textmode argument when external encoding is specified via the :external_encoding option" do
227+
@io = IO.send(@method, @fd, 'w', textmode: true, external_encoding: 'ascii-8bit')
228+
@io.external_encoding.to_s.should == 'ASCII-8BIT'
229+
end
230+
211231
it "raises ArgumentError for nil options" do
212232
-> {
213233
IO.send(@method, @fd, 'w', nil)

0 commit comments

Comments
 (0)