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
cdf5e396
Unverified
Commit
cdf5e396
authored
Jul 17, 2019
by
Yukihiro "Matz" Matsumoto
Committed by
GitHub
Jul 17, 2019
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix-range-min-with-mruby-range-ext
parents
1b7516a4
7172231b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
13 deletions
+21
-13
mrbgems/mruby-compiler/core/parse.y
mrbgems/mruby-compiler/core/parse.y
+1
-1
mrbgems/mruby-range-ext/mrblib/range.rb
mrbgems/mruby-range-ext/mrblib/range.rb
+2
-2
mrbgems/mruby-range-ext/test/range.rb
mrbgems/mruby-range-ext/test/range.rb
+18
-10
No files found.
mrbgems/mruby-compiler/core/parse.y
View file @
cdf5e396
...
@@ -5419,7 +5419,7 @@ parser_yylex(parser_state *p)
...
@@ -5419,7 +5419,7 @@ parser_yylex(parser_state *p)
tokfix(p);
tokfix(p);
if (is_float) {
if (is_float) {
#ifdef MRB_WITHOUT_FLOAT
#ifdef MRB_WITHOUT_FLOAT
yywarning
(p, "floating point numbers are not supported"
);
yywarning
_s(p, "floating point numbers are not supported", tok(p)
);
pylval.nd = new_int(p, "0", 10, 0);
pylval.nd = new_int(p, "0", 10, 0);
return tINTEGER;
return tINTEGER;
#else
#else
...
...
mrbgems/mruby-range-ext/mrblib/range.rb
View file @
cdf5e396
...
@@ -32,7 +32,7 @@ class Range
...
@@ -32,7 +32,7 @@ class Range
return
super
if
block
return
super
if
block
# fast path for numerics
# fast path for numerics
if
(
val
.
kind_of?
(
Fixnum
)
||
val
.
kind_of?
(
Float
))
&&
(
last
.
kind_of?
(
Fixnum
)
||
last
.
kind_of?
(
Float
)
)
if
val
.
kind_of?
(
Numeric
)
&&
last
.
kind_of?
(
Numeric
)
raise
TypeError
if
exclude_end?
&&
!
last
.
kind_of?
(
Fixnum
)
raise
TypeError
if
exclude_end?
&&
!
last
.
kind_of?
(
Fixnum
)
return
nil
if
val
>
last
return
nil
if
val
>
last
return
nil
if
val
==
last
&&
exclude_end?
return
nil
if
val
==
last
&&
exclude_end?
...
@@ -52,7 +52,7 @@ class Range
...
@@ -52,7 +52,7 @@ class Range
return
super
if
block
return
super
if
block
# fast path for numerics
# fast path for numerics
if
(
val
.
kind_of?
(
Fixnum
)
||
val
.
kind_of?
(
Float
))
&&
(
last
.
kind_of?
(
Fixnum
)
||
last
.
kind_of?
(
Float
)
)
if
val
.
kind_of?
(
Numeric
)
&&
last
.
kind_of?
(
Numeric
)
return
nil
if
val
>
last
return
nil
if
val
>
last
return
nil
if
val
==
last
&&
exclude_end?
return
nil
if
val
==
last
&&
exclude_end?
...
...
mrbgems/mruby-range-ext/test/range.rb
View file @
cdf5e396
...
@@ -10,6 +10,8 @@ end
...
@@ -10,6 +10,8 @@ end
assert
(
'Range#first'
)
do
assert
(
'Range#first'
)
do
assert_equal
10
,
(
10
..
20
).
first
assert_equal
10
,
(
10
..
20
).
first
assert_equal
[
10
,
11
,
12
],
(
10
..
20
).
first
(
3
)
assert_equal
[
10
,
11
,
12
],
(
10
..
20
).
first
(
3
)
skip
unless
Object
.
const_defined?
(
:Float
)
assert_equal
[
0
,
1
,
2
],
(
0
..
Float
::
INFINITY
).
first
(
3
)
assert_equal
[
0
,
1
,
2
],
(
0
..
Float
::
INFINITY
).
first
(
3
)
end
end
...
@@ -23,12 +25,14 @@ end
...
@@ -23,12 +25,14 @@ end
assert
(
'Range#size'
)
do
assert
(
'Range#size'
)
do
assert_equal
42
,
(
1
..
42
).
size
assert_equal
42
,
(
1
..
42
).
size
assert_equal
41
,
(
1
...
42
).
size
assert_equal
41
,
(
1
...
42
).
size
assert_nil
(
'a'
..
'z'
).
size
skip
unless
Object
.
const_defined?
(
:Float
)
assert_equal
6
,
(
1
...
6.3
).
size
assert_equal
6
,
(
1
...
6.3
).
size
assert_equal
5
,
(
1
...
6.0
).
size
assert_equal
5
,
(
1
...
6.0
).
size
assert_equal
5
,
(
1.1
...
6
).
size
assert_equal
5
,
(
1.1
...
6
).
size
assert_equal
15
,
(
1.0
..
15.9
).
size
assert_equal
15
,
(
1.0
..
15.9
).
size
assert_equal
Float
::
INFINITY
,
(
0
..
Float
::
INFINITY
).
size
assert_equal
Float
::
INFINITY
,
(
0
..
Float
::
INFINITY
).
size
assert_nil
(
'a'
..
'z'
).
size
end
end
assert
(
'Range#max'
)
do
assert
(
'Range#max'
)
do
...
@@ -37,12 +41,6 @@ assert('Range#max') do
...
@@ -37,12 +41,6 @@ assert('Range#max') do
assert_equal
9
,
(
1
...
10
).
max
assert_equal
9
,
(
1
...
10
).
max
assert_equal
4294967295
,
(
0
...
2
**
32
).
max
assert_equal
4294967295
,
(
0
...
2
**
32
).
max
# returns the maximum value in the Float range when called with no arguments
assert_equal
908.1111
,
(
303.20
..
908.1111
).
max
# raises TypeError when called on an exclusive range and a non Integer value
assert_raise
(
TypeError
)
{
(
303.20
...
908.1111
).
max
}
# returns nil when the endpoint is less than the start point
# returns nil when the endpoint is less than the start point
assert_equal
nil
,
(
100
..
10
).
max
assert_equal
nil
,
(
100
..
10
).
max
...
@@ -52,6 +50,14 @@ assert('Range#max') do
...
@@ -52,6 +50,14 @@ assert('Range#max') do
# returns the endpoint when the endpoint equals the start point and the range is inclusive
# returns the endpoint when the endpoint equals the start point and the range is inclusive
assert_equal
5
,
(
5
..
5
).
max
assert_equal
5
,
(
5
..
5
).
max
skip
unless
Object
.
const_defined?
(
:Float
)
# returns the maximum value in the Float range when called with no arguments
assert_equal
908.1111
,
(
303.20
..
908.1111
).
max
# raises TypeError when called on an exclusive range and a non Integer value
assert_raise
(
TypeError
)
{
(
303.20
...
908.1111
).
max
}
# returns nil when the endpoint is less than the start point in a Float range
# returns nil when the endpoint is less than the start point in a Float range
assert_equal
nil
,
(
3003.20
..
908.1111
).
max
assert_equal
nil
,
(
3003.20
..
908.1111
).
max
end
end
...
@@ -89,9 +95,6 @@ assert('Range#min') do
...
@@ -89,9 +95,6 @@ assert('Range#min') do
assert_equal
1
,
(
1
..
10
).
min
assert_equal
1
,
(
1
..
10
).
min
assert_equal
1
,
(
1
...
10
).
min
assert_equal
1
,
(
1
...
10
).
min
# returns the minimum value in the Float range when called with no arguments
assert_equal
303.20
,
(
303.20
..
908.1111
).
min
# returns nil when the start point is greater than the endpoint
# returns nil when the start point is greater than the endpoint
assert_equal
nil
,
(
100
..
10
).
min
assert_equal
nil
,
(
100
..
10
).
min
...
@@ -101,6 +104,11 @@ assert('Range#min') do
...
@@ -101,6 +104,11 @@ assert('Range#min') do
# returns the endpoint when the endpoint equals the start point and the range is inclusive
# returns the endpoint when the endpoint equals the start point and the range is inclusive
assert_equal
5
,
(
5
..
5
).
max
assert_equal
5
,
(
5
..
5
).
max
skip
unless
Object
.
const_defined?
(
:Float
)
# returns the minimum value in the Float range when called with no arguments
assert_equal
303.20
,
(
303.20
..
908.1111
).
min
# returns nil when the start point is greater than the endpoint in a Float range
# returns nil when the start point is greater than the endpoint in a Float range
assert_equal
nil
,
(
3003.20
..
908.1111
).
max
assert_equal
nil
,
(
3003.20
..
908.1111
).
max
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