From e56b791d5798fad402cf4cee0fdba50e7d987774 Mon Sep 17 00:00:00 2001 From: Asmod4n <791770+Asmod4n@users.noreply.github.com> Date: Mon, 25 Mar 2024 18:04:01 +0100 Subject: [PATCH] fix tests when mruby was build with UTF-8 Support --- test/msgpack.c | 10 ++++++++++ test/msgpack.rb | 23 +++++++++++------------ 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/test/msgpack.c b/test/msgpack.c index f874eea..9ac2b11 100644 --- a/test/msgpack.c +++ b/test/msgpack.c @@ -1,4 +1,5 @@ #include +#include static mrb_value mrb_msgpack_test_pack(mrb_state *mrb, mrb_value self) @@ -23,4 +24,13 @@ mrb_mruby_simplemsgpack_gem_test(mrb_state *mrb) mrb_define_module_function(mrb, msgpack_test, "test_unpack", mrb_msgpack_test_unpack, MRB_ARGS_REQ(1)); mrb_define_const(mrb, msgpack_test, "FIXNUM_MAX", mrb_int_value(mrb, MRB_INT_MAX)); mrb_define_const(mrb, msgpack_test, "FIXNUM_MIN", mrb_int_value(mrb, MRB_INT_MIN)); +#ifndef MRB_WITHOUT_FLOAT +#ifdef MRB_USE_FLOAT + mrb_define_const(mrb, msgpack_test, "FLOAT_MAX", mrb_float_value(mrb, FLT_MAX)); + mrb_define_const(mrb, msgpack_test, "FLOAT_MIN", mrb_float_value(mrb, FLT_MIN)); +#else + mrb_define_const(mrb, msgpack_test, "FLOAT_MAX", mrb_float_value(mrb, DBL_MAX)); + mrb_define_const(mrb, msgpack_test, "FLOAT_MIN", mrb_float_value(mrb, DBL_MIN)); +#endif +#endif } diff --git a/test/msgpack.rb b/test/msgpack.rb index 24e5e02..73001b1 100644 --- a/test/msgpack.rb +++ b/test/msgpack.rb @@ -22,8 +22,7 @@ if Object.const_defined? "Float" assert("Float#to_msgpack") do - floats = [2.2250738585072014e-308, -1.7976931348623157e+308, 1.192092896e-07, 3.402823466e+38, 1.175494351e-38, 1.7976931348623157e+308, -2.2250738585072014e-308] - floats.each do |float| + [MessagePackTest::FLOAT_MIN, -1.0, 0.0, 1.0, MessagePackTest::FLOAT_MAX].each do |float| assert_equal(float, MessagePack.unpack(float.to_msgpack)) assert_equal(float, MessagePack.unpack(MessagePack.pack(float))) end @@ -73,29 +72,29 @@ packed3 = value3.to_msgpack packed = packed1 + packed2 + packed3 - chunk1 = packed[0..packed1.length+5] - chunk2 = packed[packed1.length+5..-1] + chunk1 = packed.byteslice(0..packed1.bytesize+5) + chunk2 = packed.byteslice(packed1.bytesize+5..-1) unpacked = [] # unpack everything possible from chunk1 - unpacked_length = MessagePack.unpack(chunk1) { |value| unpacked << value } - unpacked_length -= 1 + unpacked_bytesize = MessagePack.unpack(chunk1) { |value| unpacked << value } + unpacked_bytesize -= 1 # only value1 can be unpacked - assert_equal(unpacked_length, packed1.length) + assert_equal(unpacked_bytesize, packed1.bytesize) assert_equal(unpacked, [value1]) # remove unpacked bytes from chunk1 - slice_start = unpacked_length - slice_length = chunk1.length - (unpacked_length+1) - chunk1 = chunk1.slice(slice_start, slice_length) + slice_start = unpacked_bytesize + slice_bytesize = chunk1.bytesize - (unpacked_bytesize+1) + chunk1 = chunk1.byteslice(slice_start, slice_bytesize) # continue unpacking with rest of chunk1 and chunk2 - unpacked_length = MessagePack.unpack(chunk1 + chunk2) { |value| unpacked << value } + unpacked_bytesize = MessagePack.unpack(chunk1 + chunk2) { |value| unpacked << value } # now, everything is unpacked - assert_equal(unpacked_length, chunk1.length + chunk2.length) + assert_equal(unpacked_bytesize, chunk1.bytesize + chunk2.bytesize) assert_equal(unpacked, [value1, value2, value3]) end