test_io.rb: test with holes
* test/ruby/test_io.rb (test_seek, test_seek_symwhence): add tests of SEEK_DATA and SEEK_HOLE with holes. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45659 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
28747c6720
commit
c37ac198fc
@ -1696,12 +1696,22 @@ class TestIO < Test::Unit::TestCase
|
||||
f.seek(0, IO::SEEK_DATA)
|
||||
assert_equal("foo\nbar\nbaz\n", f.read)
|
||||
}
|
||||
open(t.path, 'r+') { |f|
|
||||
pos = f.pos
|
||||
f.seek(100*1024, IO::SEEK_SET)
|
||||
f.print("zot\n")
|
||||
f.seek(50*1024, IO::SEEK_DATA)
|
||||
assert_operator(f.pos, :>=, 50*1024)
|
||||
assert_match(/\A\0*zot\n\z/, f.read)
|
||||
}
|
||||
end
|
||||
|
||||
if defined?(IO::SEEK_HOLE)
|
||||
open(t.path) { |f|
|
||||
assert_equal("foo\n", f.gets)
|
||||
f.seek(0, IO::SEEK_HOLE)
|
||||
assert_operator(f.pos, :>, 20)
|
||||
f.seek(100*1024, IO::SEEK_HOLE)
|
||||
assert_equal("", f.read)
|
||||
}
|
||||
end
|
||||
@ -1732,12 +1742,22 @@ class TestIO < Test::Unit::TestCase
|
||||
f.seek(0, :DATA)
|
||||
assert_equal("foo\nbar\nbaz\n", f.read)
|
||||
}
|
||||
open(t.path, 'r+') { |f|
|
||||
pos = f.pos
|
||||
f.seek(100*1024, :SET)
|
||||
f.print("zot\n")
|
||||
f.seek(50*1024, :DATA)
|
||||
assert_operator(f.pos, :>=, 50*1024)
|
||||
assert_match(/\A\0*zot\n\z/, f.read)
|
||||
}
|
||||
end
|
||||
|
||||
if defined?(IO::SEEK_HOLE)
|
||||
open(t.path) { |f|
|
||||
assert_equal("foo\n", f.gets)
|
||||
f.seek(0, :HOLE)
|
||||
assert_operator(f.pos, :>, 20)
|
||||
f.seek(100*1024, :HOLE)
|
||||
assert_equal("", f.read)
|
||||
}
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user