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
15a2003a
Commit
15a2003a
authored
May 13, 2014
by
Yukihiro "Matz" Matsumoto
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2190 from cremno/mrbtest-mrb_int-constants
test fixnum overflow for add, sub and mul
parents
a38f8fe6
964ce6e3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
0 deletions
+37
-0
test/driver.c
test/driver.c
+13
-0
test/t/integer.rb
test/t/integer.rb
+24
-0
No files found.
test/driver.c
View file @
15a2003a
...
...
@@ -87,6 +87,7 @@ main(int argc, char **argv)
{
mrb_state
*
mrb
;
struct
RClass
*
krn
;
struct
RClass
*
mrbtest
;
int
ret
;
print_hint
();
...
...
@@ -106,6 +107,18 @@ main(int argc, char **argv)
krn
=
mrb
->
kernel_module
;
mrb_define_method
(
mrb
,
krn
,
"__t_printstr__"
,
mrb_t_printstr
,
MRB_ARGS_REQ
(
1
));
mrbtest
=
mrb_define_module
(
mrb
,
"Mrbtest"
);
#ifdef MRB_WORD_BOXING
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MAX"
,
mrb_fixnum_value
(
MRB_INT_MAX
>>
MRB_FIXNUM_SHIFT
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MIN"
,
mrb_fixnum_value
(
MRB_INT_MIN
>>
MRB_FIXNUM_SHIFT
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_BIT"
,
mrb_fixnum_value
(
MRB_INT_BIT
>>
MRB_FIXNUM_SHIFT
));
#else
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MAX"
,
mrb_fixnum_value
(
MRB_INT_MAX
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_MIN"
,
mrb_fixnum_value
(
MRB_INT_MIN
));
mrb_define_const
(
mrb
,
mrbtest
,
"FIXNUM_BIT"
,
mrb_fixnum_value
(
MRB_INT_BIT
));
#endif
mrb_init_mrbtest
(
mrb
);
ret
=
eval_test
(
mrb
);
mrb_close
(
mrb
);
...
...
test/t/integer.rb
View file @
15a2003a
...
...
@@ -18,6 +18,14 @@ assert('Integer#+', '15.2.8.3.1') do
assert_raise
(
TypeError
){
0
+
nil
}
assert_raise
(
TypeError
){
1
+
nil
}
c
=
Mrbtest
::
FIXNUM_MAX
+
1
d
=
Mrbtest
::
FIXNUM_MAX
.
__send__
(:
+
,
1
)
e
=
Mrbtest
::
FIXNUM_MAX
+
1.0
assert_equal
Float
,
c
.
class
assert_equal
Float
,
d
.
class
assert_float
e
,
c
assert_float
e
,
d
end
assert
(
'Integer#-'
,
'15.2.8.3.2'
)
do
...
...
@@ -26,6 +34,14 @@ assert('Integer#-', '15.2.8.3.2') do
assert_equal
1
,
a
assert_equal
1.0
,
b
c
=
Mrbtest
::
FIXNUM_MIN
-
1
d
=
Mrbtest
::
FIXNUM_MIN
.
__send__
(:
-
,
1
)
e
=
Mrbtest
::
FIXNUM_MIN
-
1.0
assert_equal
Float
,
c
.
class
assert_equal
Float
,
d
.
class
assert_float
e
,
c
assert_float
e
,
d
end
assert
(
'Integer#*'
,
'15.2.8.3.3'
)
do
...
...
@@ -37,6 +53,14 @@ assert('Integer#*', '15.2.8.3.3') do
assert_raise
(
TypeError
){
0
*
nil
}
assert_raise
(
TypeError
){
1
*
nil
}
c
=
Mrbtest
::
FIXNUM_MAX
*
2
d
=
Mrbtest
::
FIXNUM_MAX
.
__send__
(:
*
,
2
)
e
=
Mrbtest
::
FIXNUM_MAX
*
2.0
assert_equal
Float
,
c
.
class
assert_equal
Float
,
d
.
class
assert_float
e
,
c
assert_float
e
,
d
end
assert
(
'Integer#/'
,
'15.2.8.3.4'
)
do
...
...
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