2003-12-04 21:54:48 -05:00
|
|
|
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_equal(nil, f.read(0))
|
|
|
|
assert_equal(nil, f.read(0))
|
|
|
|
}
|
|
|
|
open_file("") {|f|
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2003-12-09 00:33:32 -05:00
|
|
|
def test_eof_0_rw
|
|
|
|
return unless respond_to? :open_file_rw
|
|
|
|
open_file_rw("") {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
assert_equal(0, f.syswrite(""))
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2003-12-04 21:54:48 -05:00
|
|
|
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_equal(nil, f.read(0))
|
|
|
|
assert_equal(nil, f.read(0))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read(1))
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read(2))
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
}
|
|
|
|
open_file("a") {|f|
|
|
|
|
assert_equal("a", f.read)
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
assert_equal(nil, f.read(1))
|
|
|
|
}
|
|
|
|
end
|
2003-12-10 03:16:14 -05:00
|
|
|
|
|
|
|
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("", f.read)
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eof_1_seek
|
|
|
|
open_file_seek("a", 10) {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
}
|
|
|
|
open_file_seek("a", 1) {|f|
|
|
|
|
assert_equal("", f.read)
|
|
|
|
assert_equal(nil, f.read)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2003-12-04 21:54:48 -05:00
|
|
|
end
|