Simplify `mruby-inline-struct` tests.

`gcc -O3` raises error on truncation using `snprintf`.
parent b3a1d379
......@@ -11,17 +11,17 @@ istruct_test_initialize(mrb_state *mrb, mrb_value self)
mrb_value object;
mrb_get_args(mrb, "o", &object);
if (mrb_float_p(object))
{
snprintf(string, size, "float(%.3f)", mrb_float(object));
if (mrb_float_p(object)) {
strncpy(string, "float", size-1);
}
else if (mrb_fixnum_p(object))
{
snprintf(string, size, "fixnum(%" MRB_PRId ")", mrb_fixnum(object));
else if (mrb_fixnum_p(object)) {
strncpy(string, "fixnum", size-1);
}
else if (mrb_string_p(object))
{
snprintf(string, size, "string(%s)", mrb_string_value_cstr(mrb, &object));
else if (mrb_string_p(object)) {
strncpy(string, "string", size-1);
}
else {
strncpy(string, "anything", size-1);
}
string[size - 1] = 0; // force NULL at the end
......
......@@ -17,14 +17,14 @@ end
assert('InlineStructTest#dup') do
obj = InlineStructTest.new(1)
assert_equal obj.to_s, 'fixnum(1)'
assert_equal obj.dup.to_s, 'fixnum(1)'
assert_equal obj.to_s, 'fixnum'
assert_equal obj.dup.to_s, 'fixnum'
end
assert('InlineStructTest#clone') do
obj = InlineStructTest.new(1)
assert_equal obj.to_s, 'fixnum(1)'
assert_equal obj.clone.to_s, 'fixnum(1)'
assert_equal obj.to_s, 'fixnum'
assert_equal obj.clone.to_s, 'fixnum'
end
assert('InlineStruct#object_id') do
......@@ -38,22 +38,22 @@ end
assert('InlineStructTest#mutate (dup)') do
obj1 = InlineStructTest.new("foo")
assert_equal obj1.to_s, "string(foo)"
assert_equal obj1.to_s, "string"
obj2 = obj1.dup
assert_equal obj2.to_s, "string(foo)"
assert_equal obj2.to_s, "string"
obj1.mutate
assert_equal obj1.to_s, "mutate(foo)"
assert_equal obj2.to_s, "string(foo)"
assert_equal obj1.to_s, "mutate"
assert_equal obj2.to_s, "string"
end
assert('InlineStructTest#mutate (clone)') do
obj1 = InlineStructTest.new("foo")
assert_equal obj1.to_s, "string(foo)"
assert_equal obj1.to_s, "string"
obj2 = obj1.clone
assert_equal obj2.to_s, "string(foo)"
assert_equal obj2.to_s, "string"
obj1.mutate
assert_equal obj1.to_s, "mutate(foo)"
assert_equal obj2.to_s, "string(foo)"
assert_equal obj1.to_s, "mutate"
assert_equal obj2.to_s, "string"
end
assert('InlineStructTest#test_receive(string)') do
......@@ -101,26 +101,6 @@ if InlineStructTest.length == 24
assert('InlineStructTest length [64 bit]') do
assert_equal InlineStructTest.length, 3 * 8
end
assert('InlineStructTest w/float [64 bit]') do
obj = InlineStructTest.new(1.25)
assert_equal obj.to_s, "float(1.250)"
end
assert('InlineStructTest w/fixnum [64 bit]') do
obj = InlineStructTest.new(42)
assert_equal obj.to_s, "fixnum(42)"
end
assert('InlineStructTest w/string [64 bit]') do
obj = InlineStructTest.new("hello")
assert_equal obj.to_s, "string(hello)"
end
assert('InlineStructTest w/long string [64 bit]') do
obj = InlineStructTest.new("this won't fit in 3 * 8 bytes available for the structure")
assert_equal obj.to_s, "string(this won't fit i"
end
end
# 32-bit mode
......@@ -128,24 +108,11 @@ if InlineStructTest.length == 12
assert('InlineStructTest length [32 bit]') do
assert_equal InlineStructTest.length, 3 * 4
end
end
assert('InlineStructTest w/float [32 bit]') do
obj = InlineStructTest.new(1.25)
assert_equal obj.to_s, "float(1.250"
end
assert('InlineStructTest w/fixnum [32 bit]') do
obj = InlineStructTest.new(42)
assert_equal obj.to_s, "fixnum(42)"
end
assert('InlineStructTest w/string [32 bit]') do
obj = InlineStructTest.new("hello")
assert_equal obj.to_s, "string(hell"
end
assert('InlineStructTest w/long string [32 bit]') do
obj = InlineStructTest.new("this won't fit in 3 * 4 bytes available for the structure")
assert_equal obj.to_s, "string(this"
# 16-bit mode
if InlineStructTest.length == 6
assert('InlineStructTest length [16 bit]') do
assert_equal InlineStructTest.length, 3 * 2
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment