diff options
author | Jean Boussier <byroot@ruby-lang.org> | 2023-11-09 10:17:46 +0100 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2023-11-09 11:45:02 +0100 |
commit | b013aae0c66fbef0faaab29ceeda18bae4fef608 (patch) | |
tree | 7cb11bccb5c5aa5473817a2612b25b0fa7d4d2b8 /spec | |
parent | 0f02fbd9ffc0c26fa160505872a6c0d0b0493028 (diff) | |
download | ruby-b013aae0c66fbef0faaab29ceeda18bae4fef608.tar.gz |
IO#read always check the provided buffer is mutable
Otherwise you can have work in some circumstance but not in others.
Diffstat (limited to 'spec')
-rw-r--r-- | spec/ruby/core/io/read_spec.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/spec/ruby/core/io/read_spec.rb b/spec/ruby/core/io/read_spec.rb index 996f70bf20..db11468ea4 100644 --- a/spec/ruby/core/io/read_spec.rb +++ b/spec/ruby/core/io/read_spec.rb @@ -299,6 +299,32 @@ describe "IO#read" do @io.read(10, buf).should == nil buf.should == '' + + buf = 'non-empty string' + + @io.read(nil, buf).should == "" + + buf.should == '' + + buf = 'non-empty string' + + @io.read(0, buf).should == "" + + buf.should == '' + end + + it "raise FrozenError if the output buffer is frozen" do + @io.read + -> { @io.read(0, 'frozen-string'.freeze) }.should raise_error(FrozenError) + -> { @io.read(1, 'frozen-string'.freeze) }.should raise_error(FrozenError) + -> { @io.read(nil, 'frozen-string'.freeze) }.should raise_error(FrozenError) + end + + ruby_bug "", ""..."3.3" do + it "raise FrozenError if the output buffer is frozen (2)" do + @io.read + -> { @io.read(1, ''.freeze) }.should raise_error(FrozenError) + end end it "consumes zero bytes when reading zero bytes" do |