Skip to content

Commit 787577f

Browse files
javanthropuseregon
authored andcommitted
Add tests for IO#read_nonblock following IO#ungetc with character convertion en/dis-abled
1 parent 90d461b commit 787577f

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

core/io/read_nonblock_spec.rb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,25 @@
5555
@read.read_nonblock(4).should == "hell"
5656
end
5757

58-
platform_is_not :windows do # https://bugs.ruby-lang.org/issues/18881
59-
it "reads after ungetc with data in the buffer" do
60-
@write.write("foobar")
61-
c = @read.getc
62-
@read.ungetc(c)
63-
@read.read_nonblock(3).should == "foo"
64-
@read.read_nonblock(3).should == "bar"
65-
end
58+
it "reads after ungetc with data in the buffer" do
59+
@write.write("foobar")
60+
@read.set_encoding(
61+
'utf-8', universal_newline: false
62+
)
63+
c = @read.getc
64+
@read.ungetc(c)
65+
@read.read_nonblock(3).should == "foo"
66+
@read.read_nonblock(3).should == "bar"
67+
end
68+
69+
it "raises an exception after ungetc with data in the buffer and character conversion enabled" do
70+
@write.write("foobar")
71+
@read.set_encoding(
72+
'utf-8', universal_newline: true
73+
)
74+
c = @read.getc
75+
@read.ungetc(c)
76+
-> { @read.read_nonblock(3).should == "foo" }.should raise_error(IOError)
6677
end
6778

6879
it "returns less data if that is all that is available" do

0 commit comments

Comments
 (0)