summaryrefslogtreecommitdiff
path: root/spec/ruby/core/io/buffer/string_spec.rb
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2026-01-28 22:30:21 +0100
committerBenoit Daloze <eregontp@gmail.com>2026-01-28 23:01:22 +0100
commitdbd2ff7adca9b49e4bfa7bc3ec8b83bd437f8cb7 (patch)
tree5f4f1609d2015fde92c25b175b84078dfcf1c92f /spec/ruby/core/io/buffer/string_spec.rb
parenta8b877a843643fbdccd1a42efaf94ad27705dd55 (diff)
Update to ruby/spec@83e26c9
Diffstat (limited to 'spec/ruby/core/io/buffer/string_spec.rb')
-rw-r--r--spec/ruby/core/io/buffer/string_spec.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/spec/ruby/core/io/buffer/string_spec.rb b/spec/ruby/core/io/buffer/string_spec.rb
new file mode 100644
index 0000000000..bc7a73075e
--- /dev/null
+++ b/spec/ruby/core/io/buffer/string_spec.rb
@@ -0,0 +1,62 @@
+require_relative '../../../spec_helper'
+
+describe "IO::Buffer.string" do
+ it "creates a modifiable buffer for the duration of the block" do
+ IO::Buffer.string(7) do |buffer|
+ @buffer = buffer
+
+ buffer.size.should == 7
+ buffer.get_string.should == "\0\0\0\0\0\0\0".b
+
+ buffer.set_string("test")
+ buffer.get_string.should == "test\0\0\0"
+ end
+ @buffer.should.null?
+ end
+
+ it "returns contents of the buffer as a binary string" do
+ string =
+ IO::Buffer.string(7) do |buffer|
+ buffer.set_string("รค test")
+ end
+ string.should == "\xC3\xA4 test".b
+ end
+
+ it "creates an external buffer" do
+ IO::Buffer.string(8) do |buffer|
+ buffer.should_not.internal?
+ buffer.should_not.mapped?
+ buffer.should.external?
+
+ buffer.should_not.empty?
+ buffer.should_not.null?
+
+ buffer.should_not.shared?
+ buffer.should_not.private?
+ buffer.should_not.readonly?
+
+ buffer.should_not.locked?
+ buffer.should.valid?
+ end
+ end
+
+ it "returns an empty string if size is 0" do
+ string =
+ IO::Buffer.string(0) do |buffer|
+ buffer.size.should == 0
+ end
+ string.should == ""
+ end
+
+ it "raises ArgumentError if size is negative" do
+ -> { IO::Buffer.string(-1) {} }.should raise_error(ArgumentError, "negative string size (or size too big)")
+ end
+
+ it "raises RangeError if size is too large" do
+ -> { IO::Buffer.string(2 ** 232) {} }.should raise_error(RangeError, /\Abignum too big to convert into [`']long'\z/)
+ end
+
+ it "raises LocalJumpError if no block is given" do
+ -> { IO::Buffer.string(7) }.should raise_error(LocalJumpError, "no block given")
+ end
+end