1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

More immutability and locking tests.

This commit is contained in:
Samuel Williams 2021-10-22 15:04:22 +13:00
parent e73197dff5
commit 98b442e013
Notes: git 2021-11-12 12:46:30 +09:00
2 changed files with 36 additions and 4 deletions

View file

@ -44,6 +44,19 @@ class TestIOBuffer < Test::Unit::TestCase
assert buffer.mapped?
end
def test_new_immutable
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::IMMUTABLE)
assert buffer.immutable?
assert_raise RuntimeError do
buffer.copy("", 0)
end
assert_raise RuntimeError do
buffer.copy("!", 1)
end
end
def test_file_mapped
buffer = File.open(__FILE__) {|file| IO::Buffer.map(file)}
assert_include buffer.to_str, "Hello World"
@ -103,6 +116,22 @@ class TestIOBuffer < Test::Unit::TestCase
# end
end
def test_locked
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
assert_raise RuntimeError do
buffer.resize(256, 0)
end
assert_equal 128, buffer.size
assert_raise RuntimeError do
buffer.free
end
assert_equal 128, buffer.size
end
def test_invalidation
input, output = IO.pipe