Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mruby
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
mruby
Commits
fbfe519b
Commit
fbfe519b
authored
Aug 13, 2018
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify `mruby-inline-struct` tests.
`gcc -O3` raises error on truncation using `snprintf`.
parent
b3a1d379
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
59 deletions
+26
-59
mrbgems/mruby-inline-struct/test/inline.c
mrbgems/mruby-inline-struct/test/inline.c
+9
-9
mrbgems/mruby-inline-struct/test/inline.rb
mrbgems/mruby-inline-struct/test/inline.rb
+17
-50
No files found.
mrbgems/mruby-inline-struct/test/inline.c
View file @
fbfe519b
...
...
@@ -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
...
...
mrbgems/mruby-inline-struct/test/inline.rb
View file @
fbfe519b
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment