diff options
| author | dearblue <[email protected]> | 2020-02-01 16:25:39 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2020-02-02 21:20:25 +0900 |
| commit | 4c6d524c473ebb9174d0183dc1d1ac0530337314 (patch) | |
| tree | 1aec9457c2862557440a3d718f459020334e0383 /mrbgems/mruby-io/test/io.rb | |
| parent | 3c67d9b1c0e4970db1d88fccdf7f26c781aa2c5f (diff) | |
| download | mruby-4c6d524c473ebb9174d0183dc1d1ac0530337314.tar.gz mruby-4c6d524c473ebb9174d0183dc1d1ac0530337314.zip | |
Implement `IO#pread` and `IO#pwrite`
It is available by default in environments where `__unix__` is defined.
Other environments are enabled by defining `MRB_WITH_IO_PREAD_PWRITE`
(requires an implementation of `pread()` and `pwrite()` functions).
In any case, you can disable it by defining
`MRB_WITHOUT_IO_PREAD_PWRITE`.
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 |
