From c26f998ed5976c453afc4ba68aa24aaa9d0c0d4e Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 27 Sep 2015 00:29:17 +0900 Subject: support IO#<< --- test/io.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test') diff --git a/test/io.rb b/test/io.rb index b828fef49..a5ce7e049 100644 --- a/test/io.rb +++ b/test/io.rb @@ -150,6 +150,14 @@ assert('IO#write', '15.2.20.5.20') do true end +assert('IO#<<') do + io = IO.open(IO.sysopen($mrbtest_io_wfname)) + io << "" << "" + assert_equal 0, io.pos + io.close + true +end + assert('IO.for_fd') do fd = IO.sysopen($mrbtest_io_rfname) io = IO.for_fd(fd) -- cgit v1.2.3 From 9bbfc38bb4ee3a5f66f82a68542518f397bb9897 Mon Sep 17 00:00:00 2001 From: takahashim Date: Sun, 27 Sep 2015 21:25:06 +0900 Subject: add IO#rewind --- mrblib/io.rb | 4 ++++ test/io.rb | 11 +++++++++++ 2 files changed, 15 insertions(+) (limited to 'test') diff --git a/mrblib/io.rb b/mrblib/io.rb index 30eb47404..4d2fda5f3 100644 --- a/mrblib/io.rb +++ b/mrblib/io.rb @@ -141,6 +141,10 @@ class IO seek(i, SEEK_SET) end + def rewind + seek(0, SEEK_SET) + end + def seek(i, whence = SEEK_SET) raise IOError if closed? @pos = sysseek(i, whence) diff --git a/test/io.rb b/test/io.rb index a5ce7e049..a9bdc3e4f 100644 --- a/test/io.rb +++ b/test/io.rb @@ -256,6 +256,17 @@ assert('IO#pos=, IO#seek') do io.closed? end +assert('IO#rewind') do + fd = IO.sysopen $mrbtest_io_rfname + io = IO.new fd + assert_equal 'm', io.getc + assert_equal 1, io.pos + assert_equal 0, io.rewind + assert_equal 0, io.pos + io.close + io.closed? +end + assert('IO#gets') do fd = IO.sysopen $mrbtest_io_rfname io = IO.new fd -- cgit v1.2.3