summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrblib/io.rb9
-rw-r--r--run_test.rb1
-rw-r--r--src/io.c3
-rw-r--r--test/io.rb19
4 files changed, 30 insertions, 2 deletions
diff --git a/mrblib/io.rb b/mrblib/io.rb
index c838b96e5..4d2fda5f3 100644
--- a/mrblib/io.rb
+++ b/mrblib/io.rb
@@ -108,6 +108,11 @@ class IO
raise IOError
end
+ def <<(str)
+ write(str)
+ self
+ end
+
def eof?
return true if @buf && @buf.size > 0
@@ -136,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/run_test.rb b/run_test.rb
index 444d18fda..83d80294a 100644
--- a/run_test.rb
+++ b/run_test.rb
@@ -20,6 +20,7 @@ MRuby::Build.new do |conf|
conf.gembox 'default'
conf.gem :git => 'https://github.com/iij/mruby-env.git'
+ conf.enable_test
conf.gem File.expand_path(File.dirname(__FILE__))
end
diff --git a/src/io.c b/src/io.c
index 64403a75a..515c93edb 100644
--- a/src/io.c
+++ b/src/io.c
@@ -525,8 +525,7 @@ mrb_value
mrb_io_sysseek(mrb_state *mrb, mrb_value io)
{
struct mrb_io *fptr;
- int pos;
- mrb_int offset, whence = -1;
+ mrb_int pos, offset, whence = -1;
mrb_get_args(mrb, "i|i", &offset, &whence);
if (whence < 0) {
diff --git a/test/io.rb b/test/io.rb
index b828fef49..a9bdc3e4f 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)
@@ -248,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