Commit 78fe65ae authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

Merge branch 'master' of github.com:iij/mruby-io

parents 5fa3c391 71197d27
......@@ -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)
......
......@@ -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
......@@ -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) {
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment