ruby-changes:70394
From: Samuel <ko1@a...>
Date: Tue, 21 Dec 2021 08:26:06 +0900 (JST)
Subject: [ruby-changes:70394] c3d8d26ad7 (master): Add tests for `IO::Buffer` `get`/`set`.
https://git.ruby-lang.org/ruby.git/commit/?id=c3d8d26ad7 From c3d8d26ad744d2a2dada135196e7d694d2966008 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Mon, 20 Dec 2021 12:11:58 +1300 Subject: Add tests for `IO::Buffer` `get`/`set`. --- test/ruby/test_io_buffer.rb | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/ruby/test_io_buffer.rb b/test/ruby/test_io_buffer.rb index 45aab318f99..0a8685d9d53 100644 --- a/test/ruby/test_io_buffer.rb +++ b/test/ruby/test_io_buffer.rb @@ -201,6 +201,42 @@ class TestIOBuffer < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io_buffer.rb#L201 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 -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/