summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-12-20 12:11:58 +1300
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2021-12-21 12:25:42 +1300
commitc3d8d26ad744d2a2dada135196e7d694d2966008 (patch)
treeed4c6d35bc773fea77bb9ab7e04a102fd1e2b709
parent71bbc40ffa4bb16ef0fc31f8015f61709fac36ce (diff)
Add tests for `IO::Buffer` `get`/`set`.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5303
-rw-r--r--test/ruby/test_io_buffer.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb
index 45aab318f9..0a8685d9d5 100644
--- a/test/ruby/test_io_buffer.rb
+++ b/test/ruby/test_io_buffer.rb
@@ -201,6 +201,42 @@ class TestIOBuffer < Test::Unit::TestCase
chunk = buffer.get_string(0, message.bytesize, Encoding::BINARY)
assert_equal Encoding::BINARY, chunk.encoding
end
+
+ # We check that values are correctly round tripped.
+ RANGES = {
+ :U8 => [0, 2**8-1],
+ :S8 => [-2**7, 0, 2**7-1],
+
+ :U16 => [0, 2**16-1],
+ :S16 => [-2**15, 0, 2**15-1],
+ :u16 => [0, 2**16-1],
+ :s16 => [-2**15, 0, 2**15-1],
+
+ :U32 => [0, 2**32-1],
+ :S32 => [-2**31, 0, 2**31-1],
+ :u32 => [0, 2**32-1],
+ :s32 => [-2**31, 0, 2**31-1],
+
+ :U64 => [0, 2**64-1],
+ :S64 => [-2**63, 0, 2**63-1],
+ :u64 => [0, 2**64-1],
+ :s64 => [-2**63, 0, 2**63-1],
+
+ :F32 => [-1.0, 0.0, 0.5, 1.0, 128.0],
+ :F64 => [-1.0, 0.0, 0.5, 1.0, 128.0],
+ }
+
+ def test_get_set
+ buffer = IO::Buffer.new(128)
+
+ RANGES.each do |type, values|
+ values.each do |value|
+ buffer.set(type, 0, value)
+ assert_equal value, buffer.get(type, 0), "Converting #{value} as #{type}."
+ end
+ end
+ end
+
def test_invalidation
input, output = IO.pipe