Commit ddfc4eb5 authored by Tomoyuki Sahara's avatar Tomoyuki Sahara

IO#read(0) should return "" immediately. fixes iij/mruby-socket#13.

parent d894de86
......@@ -171,11 +171,16 @@ class IO
end
def read(length = nil)
unless length.nil? or length.class == Fixnum
raise TypeError.new "can't convert #{length.class} into Integer"
end
if length && length < 0
raise ArgumentError.new "negative length: #{length} given"
unless length.nil?
unless length.is_a? Fixnum
raise TypeError.new "can't convert #{length.class} into Integer"
end
if length < 0
raise ArgumentError.new "negative length: #{length} given"
end
if length == 0
return "" # easy case
end
end
str = ''
......
......@@ -93,6 +93,7 @@ assert('IO#read', '15.2.20.5.14') do
assert_raise(TypeError) { io.read("str") }
len = $mrbtest_io_msg.length
assert_equal '', io.read(0)
assert_equal 'mruby', io.read(5)
assert_equal $mrbtest_io_msg[5,len], io.read(len)
......
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