diff options
Diffstat (limited to 'mrbgems/mruby-io/test/io.rb')
| -rw-r--r-- | mrbgems/mruby-io/test/io.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/mrbgems/mruby-io/test/io.rb b/mrbgems/mruby-io/test/io.rb index e3024cf9a..458d2cdc2 100644 --- a/mrbgems/mruby-io/test/io.rb +++ b/mrbgems/mruby-io/test/io.rb @@ -564,6 +564,34 @@ assert('IO#sysseek') do end end +assert('IO#pread') do + skip "IO#pread is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE + + IO.open(IO.sysopen($mrbtest_io_rfname, 'r'), 'r') do |io| + assert_equal $mrbtest_io_msg.byteslice(5, 8), io.pread(8, 5) + assert_equal 0, io.pos + assert_equal $mrbtest_io_msg.byteslice(1, 5), io.pread(5, 1) + assert_equal 0, io.pos + assert_raise(RuntimeError) { io.pread(20, -9) } + end +end + +assert('IO#pwrite') do + skip "IO#pwrite is not implemented on this configuration" unless MRubyIOTestUtil::MRB_WITH_IO_PREAD_PWRITE + + IO.open(IO.sysopen($mrbtest_io_wfname, 'w+'), 'w+') do |io| + assert_equal 6, io.pwrite("Warld!", 7) + assert_equal 0, io.pos + assert_equal 7, io.pwrite("Hello, ", 0) + assert_equal 0, io.pos + assert_equal "Hello, Warld!", io.read + assert_equal 6, io.pwrite("world!", 7) + assert_equal 13, io.pos + io.pos = 0 + assert_equal "Hello, world!", io.read + end +end + assert('IO.pipe') do begin called = false |
