Skip to content

Commit

Permalink
[GR-18163] StringIO: add :exception option for the #write_nonblock me…
Browse files Browse the repository at this point in the history
…thod (#2247)

PullRequest: truffleruby/3466
  • Loading branch information
eregon committed Aug 23, 2022
2 parents 1db71db + 5c64992 commit 00454d0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/truffle/stringio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def puts(*args)
Truffle::IOOperations.puts(self, *args)
end

def write_nonblock(str)
def write_nonblock(str, exception: true)
write(str)
end

Expand Down
11 changes: 11 additions & 0 deletions spec/ruby/library/stringio/read_nonblock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,21 @@

describe "StringIO#read_nonblock when passed length, buffer" do
it_behaves_like :stringio_read, :read_nonblock

it "accepts :exception option" do
io = StringIO.new("example")
io.read_nonblock(3, buffer = "", exception: true)
buffer.should == "exa"
end
end

describe "StringIO#read_nonblock when passed length" do
it_behaves_like :stringio_read_length, :read_nonblock

it "accepts :exception option" do
io = StringIO.new("example")
io.read_nonblock(3, exception: true).should == "exa"
end
end

describe "StringIO#read_nonblock when passed nil" do
Expand Down
6 changes: 6 additions & 0 deletions spec/ruby/library/stringio/write_nonblock_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@

describe "StringIO#write_nonblock when passed [String]" do
it_behaves_like :stringio_write_string, :write_nonblock

it "accepts :exception option" do
io = StringIO.new("12345", "a")
io.write_nonblock("67890", exception: true)
io.string.should == "1234567890"
end
end

describe "StringIO#write_nonblock when self is not writable" do
Expand Down

0 comments on commit 00454d0

Please sign in to comment.