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) ...@@ -11,17 +11,17 @@ istruct_test_initialize(mrb_state *mrb, mrb_value self)
mrb_value object; mrb_value object;
mrb_get_args(mrb, "o", &object); mrb_get_args(mrb, "o", &object);
if (mrb_float_p(object)) if (mrb_float_p(object)) {
{ strncpy(string, "float", size-1);
snprintf(string, size, "float(%.3f)", mrb_float(object));
} }
else if (mrb_fixnum_p(object)) else if (mrb_fixnum_p(object)) {
{ strncpy(string, "fixnum", size-1);
snprintf(string, size, "fixnum(%" MRB_PRId ")", mrb_fixnum(object));
} }
else if (mrb_string_p(object)) else if (mrb_string_p(object)) {
{ strncpy(string, "string", size-1);
snprintf(string, size, "string(%s)", mrb_string_value_cstr(mrb, &object)); }
else {
strncpy(string, "anything", size-1);
} }
string[size - 1] = 0; // force NULL at the end string[size - 1] = 0; // force NULL at the end
......
...@@ -17,14 +17,14 @@ end ...@@ -17,14 +17,14 @@ end
assert('InlineStructTest#dup') do assert('InlineStructTest#dup') do
obj = InlineStructTest.new(1) obj = InlineStructTest.new(1)
assert_equal obj.to_s, 'fixnum(1)' assert_equal obj.to_s, 'fixnum'
assert_equal obj.dup.to_s, 'fixnum(1)' assert_equal obj.dup.to_s, 'fixnum'
end end
assert('InlineStructTest#clone') do assert('InlineStructTest#clone') do
obj = InlineStructTest.new(1) obj = InlineStructTest.new(1)
assert_equal obj.to_s, 'fixnum(1)' assert_equal obj.to_s, 'fixnum'
assert_equal obj.clone.to_s, 'fixnum(1)' assert_equal obj.clone.to_s, 'fixnum'
end end
assert('InlineStruct#object_id') do assert('InlineStruct#object_id') do
...@@ -38,22 +38,22 @@ end ...@@ -38,22 +38,22 @@ end
assert('InlineStructTest#mutate (dup)') do assert('InlineStructTest#mutate (dup)') do
obj1 = InlineStructTest.new("foo") obj1 = InlineStructTest.new("foo")
assert_equal obj1.to_s, "string(foo)" assert_equal obj1.to_s, "string"
obj2 = obj1.dup obj2 = obj1.dup
assert_equal obj2.to_s, "string(foo)" assert_equal obj2.to_s, "string"
obj1.mutate obj1.mutate
assert_equal obj1.to_s, "mutate(foo)" assert_equal obj1.to_s, "mutate"
assert_equal obj2.to_s, "string(foo)" assert_equal obj2.to_s, "string"
end end
assert('InlineStructTest#mutate (clone)') do assert('InlineStructTest#mutate (clone)') do
obj1 = InlineStructTest.new("foo") obj1 = InlineStructTest.new("foo")
assert_equal obj1.to_s, "string(foo)" assert_equal obj1.to_s, "string"
obj2 = obj1.clone obj2 = obj1.clone
assert_equal obj2.to_s, "string(foo)" assert_equal obj2.to_s, "string"
obj1.mutate obj1.mutate
assert_equal obj1.to_s, "mutate(foo)" assert_equal obj1.to_s, "mutate"
assert_equal obj2.to_s, "string(foo)" assert_equal obj2.to_s, "string"
end end
assert('InlineStructTest#test_receive(string)') do assert('InlineStructTest#test_receive(string)') do
...@@ -101,26 +101,6 @@ if InlineStructTest.length == 24 ...@@ -101,26 +101,6 @@ if InlineStructTest.length == 24
assert('InlineStructTest length [64 bit]') do assert('InlineStructTest length [64 bit]') do
assert_equal InlineStructTest.length, 3 * 8 assert_equal InlineStructTest.length, 3 * 8
end 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 end
# 32-bit mode # 32-bit mode
...@@ -128,24 +108,11 @@ if InlineStructTest.length == 12 ...@@ -128,24 +108,11 @@ if InlineStructTest.length == 12
assert('InlineStructTest length [32 bit]') do assert('InlineStructTest length [32 bit]') do
assert_equal InlineStructTest.length, 3 * 4 assert_equal InlineStructTest.length, 3 * 4
end end
end
assert('InlineStructTest w/float [32 bit]') do # 16-bit mode
obj = InlineStructTest.new(1.25) if InlineStructTest.length == 6
assert_equal obj.to_s, "float(1.250" assert('InlineStructTest length [16 bit]') do
end assert_equal InlineStructTest.length, 3 * 2
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"
end end
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