Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
103 changes: 9 additions & 94 deletions core/io/buffer/external_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,103 +6,18 @@
@buffer = nil
end

context "with a buffer created with .new" do
it "is false for an internal buffer" do
@buffer = IO::Buffer.new(4)
@buffer.external?.should be_false
end

it "is false for a mapped buffer" do
@buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
@buffer.external?.should be_false
end
end

context "with a file-backed buffer created with .map" do
it "is true for a regular mapping" do
File.open(__FILE__, "r") do |file|
@buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
@buffer.external?.should be_true
end
end

ruby_version_is "3.3" do
it "is false for a private mapping" do
File.open(__FILE__, "r") do |file|
@buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY | IO::Buffer::PRIVATE)
@buffer.external?.should be_false
end
end
end
end

context "with a String-backed buffer created with .for" do
it "is true for a buffer created without a block" do
@buffer = IO::Buffer.for("test")
@buffer.external?.should be_true
end

it "is true for a buffer created with a block" do
IO::Buffer.for(+"test") do |buffer|
buffer.external?.should be_true
end
end
it "is true for a buffer with externally-managed memory" do
@buffer = IO::Buffer.for("string")
@buffer.external?.should be_true
end

ruby_version_is "3.3" do
context "with a String-backed buffer created with .string" do
it "is true" do
IO::Buffer.string(4) do |buffer|
buffer.external?.should be_true
end
end
end
it "is false for a buffer with self-managed memory" do
@buffer = IO::Buffer.new(12, IO::Buffer::MAPPED)
@buffer.external?.should be_false
end

# Always false for slices
context "with a slice of a buffer" do
context "created with .new" do
it "is false when slicing an internal buffer" do
@buffer = IO::Buffer.new(4)
@buffer.slice.external?.should be_false
end

it "is false when slicing a mapped buffer" do
@buffer = IO::Buffer.new(4, IO::Buffer::MAPPED)
@buffer.slice.external?.should be_false
end
end

context "created with .map" do
it "is false" do
File.open(__FILE__, "r") do |file|
@buffer = IO::Buffer.map(file, nil, 0, IO::Buffer::READONLY)
@buffer.slice.external?.should be_false
end
end
end

context "created with .for" do
it "is false when slicing a buffer created without a block" do
@buffer = IO::Buffer.for("test")
@buffer.slice.external?.should be_false
end

it "is false when slicing a buffer created with a block" do
IO::Buffer.for(+"test") do |buffer|
buffer.slice.external?.should be_false
end
end
end

ruby_version_is "3.3" do
context "created with .string" do
it "is false" do
IO::Buffer.string(4) do |buffer|
buffer.slice.external?.should be_false
end
end
end
end
it "is false for a null buffer" do
@buffer = IO::Buffer.new(0)
@buffer.external?.should be_false
end
end
Loading