summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2018-08-13 15:24:51 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2018-08-13 23:15:52 +0900
commit1e52d47bc3e0d287e5d2cf5c61df60f8613db2aa (patch)
tree50a1240278a5d845c2cb5654e2a68c5385745dbf
parentfee9ec61bb9808b5235a78b923a2b8baeebbea8c (diff)
downloadmruby-1e52d47bc3e0d287e5d2cf5c61df60f8613db2aa.tar.gz
mruby-1e52d47bc3e0d287e5d2cf5c61df60f8613db2aa.zip
Simplify `mruby-inline-struct` tests.
`gcc -O3` raises error on truncation using `snprintf`.
-rw-r--r--mrbgems/mruby-inline-struct/test/inline.c18
-rw-r--r--mrbgems/mruby-inline-struct/test/inline.rb67
2 files changed, 26 insertions, 59 deletions
diff --git a/mrbgems/mruby-inline-struct/test/inline.c b/mrbgems/mruby-inline-struct/test/inline.c
index 95341d348..91c767f30 100644
--- a/mrbgems/mruby-inline-struct/test/inline.c
+++ b/mrbgems/mruby-inline-struct/test/inline.c
@@ -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
diff --git a/mrbgems/mruby-inline-struct/test/inline.rb b/mrbgems/mruby-inline-struct/test/inline.rb
index 495859232..f959a17c4 100644
--- a/mrbgems/mruby-inline-struct/test/inline.rb
+++ b/mrbgems/mruby-inline-struct/test/inline.rb
@@ -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