mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
0a4fc3d71b
[ruby-dev:22334] * io.c (argf_read): do not depend on nil at eof behavior of IO#read(). * eval.c (rb_thread_join): dup exception before re-raising it. * io.c (rb_io_eof): call clearerr() to prevent side effect. this patch is supplied by Masahiro Sakai <sakai@tom.sfc.keio.ac.jp>. [ruby-dev:22234] * pack.c (OFF16): get offset for big endian machines. * pack.c (pack_pack): use OFF16 instead of OFF16B. [ruby-dev:22344] * pack.c (pack_unpack): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5266 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
95 lines
2.1 KiB
Ruby
95 lines
2.1 KiB
Ruby
require 'test/unit'
|
|
|
|
module TestEOF
|
|
def test_eof_0
|
|
open_file("") {|f|
|
|
assert_equal("", f.read(0))
|
|
assert_equal("", f.read(0))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(0))
|
|
assert_nil(f.read(0))
|
|
}
|
|
open_file("") {|f|
|
|
assert_nil(f.read(1))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(1))
|
|
}
|
|
end
|
|
|
|
def test_eof_0_rw
|
|
return unless respond_to? :open_file_rw
|
|
open_file_rw("") {|f|
|
|
assert_equal("", f.read)
|
|
assert_equal("", f.read)
|
|
assert_equal(0, f.syswrite(""))
|
|
assert_equal("", f.read)
|
|
}
|
|
end
|
|
|
|
def test_eof_1
|
|
open_file("a") {|f|
|
|
assert_equal("", f.read(0))
|
|
assert_equal("a", f.read(1))
|
|
assert_equal("" , f.read(0))
|
|
assert_equal("" , f.read(0))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(0))
|
|
assert_nil(f.read(0))
|
|
}
|
|
open_file("a") {|f|
|
|
assert_equal("a", f.read(1))
|
|
assert_nil(f.read(1))
|
|
}
|
|
open_file("a") {|f|
|
|
assert_equal("a", f.read(2))
|
|
assert_nil(f.read(1))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(1))
|
|
}
|
|
open_file("a") {|f|
|
|
assert_equal("a", f.read)
|
|
assert_nil(f.read(1))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(1))
|
|
}
|
|
open_file("a") {|f|
|
|
assert_equal("a", f.read(2))
|
|
assert_equal("", f.read)
|
|
assert_equal("", f.read)
|
|
}
|
|
open_file("a") {|f|
|
|
assert_equal("a", f.read)
|
|
assert_nil(f.read(0))
|
|
}
|
|
end
|
|
|
|
module Seek
|
|
def open_file_seek(content, pos)
|
|
open_file(content) do |f|
|
|
f.seek(pos)
|
|
yield f
|
|
end
|
|
end
|
|
|
|
def test_eof_0_seek
|
|
open_file_seek("", 10) {|f|
|
|
assert_equal(10, f.pos)
|
|
assert_equal("", f.read(0))
|
|
assert_equal("", f.read)
|
|
assert_nil(f.read(0))
|
|
assert_equal("", f.read)
|
|
}
|
|
end
|
|
|
|
def test_eof_1_seek
|
|
open_file_seek("a", 10) {|f|
|
|
assert_equal("", f.read)
|
|
assert_equal("", f.read)
|
|
}
|
|
open_file_seek("a", 1) {|f|
|
|
assert_equal("", f.read)
|
|
assert_equal("", f.read)
|
|
}
|
|
end
|
|
end
|
|
end
|