diff options
| author | Tomoyuki Sahara <[email protected]> | 2014-02-25 12:19:52 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2014-02-25 12:19:52 +0900 |
| commit | 56a8c592dd02cc603a57669b37035f4b8054c587 (patch) | |
| tree | 0b990167d2f95ba8285debb7df1e17a71d78a61e /test | |
| parent | 7fd585bae174751e69b3a5e3a65e18eabaf7b1bd (diff) | |
| download | mruby-56a8c592dd02cc603a57669b37035f4b8054c587.tar.gz mruby-56a8c592dd02cc603a57669b37035f4b8054c587.zip | |
add IO.read
Diffstat (limited to 'test')
| -rw-r--r-- | test/io.rb | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/test/io.rb b/test/io.rb index 49a2a3f97..02507a9d4 100644 --- a/test/io.rb +++ b/test/io.rb @@ -130,7 +130,7 @@ assert('IO#read') do io = IO.new fd assert_equal 'mruby', io.read(5) assert_equal $mrbtest_io_msg[5,100] + "\n", io.read - assert_equal nil, io.read + assert_equal "", io.read io.close io.closed? end @@ -251,6 +251,29 @@ assert('IO.popen') do io.closed? end +assert('IO.read') do + # empty file + fd = IO.sysopen $mrbtest_io_wfname, "w" + io = IO.new fd, "w" + io.close + assert_equal "", IO.read($mrbtest_io_wfname) + assert_equal nil, IO.read($mrbtest_io_wfname, 1) + + # one byte file + fd = IO.sysopen $mrbtest_io_wfname, "w" + io = IO.new fd, "w" + io.write "123" + io.close + assert_equal "123", IO.read($mrbtest_io_wfname) + assert_equal "", IO.read($mrbtest_io_wfname, 0) + assert_equal "1", IO.read($mrbtest_io_wfname, 1) + assert_equal "", IO.read($mrbtest_io_wfname, 0, 10) + assert_equal "23", IO.read($mrbtest_io_wfname, 2, 1) + assert_equal "23", IO.read($mrbtest_io_wfname, 10, 1) + assert_equal "", IO.read($mrbtest_io_wfname, nil, 10) + assert_equal nil, IO.read($mrbtest_io_wfname, 1, 10) +end + assert('IO#fileno') do fd = IO.sysopen $mrbtest_io_rfname io = IO.new fd |
