summaryrefslogtreecommitdiff
path: root/test/ruby/test_io_buffer.rb
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-12-23 12:20:09 +1300
committerGitHub <noreply@github.com>2021-12-23 12:20:09 +1300
commitbed920f0731a1a89a0e5fc7a7428d21be3ffb8a0 (patch)
tree928abd45556a6f2380211ef347ce0df9c0858db9 /test/ruby/test_io_buffer.rb
parent91c5c1c132994c9ca4540125d462988d83e37a6b (diff)
Add fiber scheduler hooks for `pread`/`pwrite`, and add support to `IO::Buffer`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5249 Merged-By: ioquatix <samuel@codeotaku.com>
Diffstat (limited to 'test/ruby/test_io_buffer.rb')
-rw-r--r--test/ruby/test_io_buffer.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
index 362845ec2a..7e3b467ed5 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -1,5 +1,7 @@
# frozen_string_literal: false
+require 'tempfile'
+
class TestIOBuffer < Test::Unit::TestCase
experimental = Warning[:experimental]
begin
@@ -270,4 +272,59 @@ class TestIOBuffer < Test::Unit::TestCase
input.close
end
+
+ def test_read
+ io = Tempfile.new
+ io.write("Hello World")
+ io.seek(0)
+
+ buffer = IO::Buffer.new(128)
+ buffer.read(io, 5)
+
+ assert_equal "Hello", buffer.get_string(0, 5)
+ ensure
+ io.close!
+ end
+
+ def test_write
+ io = Tempfile.new
+
+ buffer = IO::Buffer.new(128)
+ buffer.set_string("Hello")
+ buffer.write(io, 5)
+
+ io.seek(0)
+ assert_equal "Hello", io.read(5)
+ ensure
+ io.close!
+ end
+
+ def test_pread
+ io = Tempfile.new
+ io.write("Hello World")
+ io.seek(0)
+
+ buffer = IO::Buffer.new(128)
+ buffer.pread(io, 5, 6)
+
+ assert_equal "World", buffer.get_string(0, 5)
+ assert_equal 0, io.tell
+ ensure
+ io.close!
+ end
+
+ def test_pwrite
+ io = Tempfile.new
+
+ buffer = IO::Buffer.new(128)
+ buffer.set_string("World")
+ buffer.pwrite(io, 5, 6)
+
+ assert_equal 0, io.tell
+
+ io.seek(6)
+ assert_equal "World", io.read(5)
+ ensure
+ io.close!
+ end
end