range.c: covered for linear objects
* range.c (linear_object_p, range_include): test if covered for linear objects. [ruby-core:69052] [Bug #11113] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
06cb32001f
commit
b0616346f8
@ -1,3 +1,8 @@
|
|||||||
|
Sun May 3 10:02:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* range.c (linear_object_p, range_include): test if covered for
|
||||||
|
linear objects. [ruby-core:69052] [Bug #11113]
|
||||||
|
|
||||||
Fri May 1 13:30:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri May 1 13:30:24 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* dln.c (dln_load): check if a different libruby is loaded by the
|
* dln.c (dln_load): check if a different libruby is loaded by the
|
||||||
|
18
range.c
18
range.c
@ -331,6 +331,21 @@ discrete_object_p(VALUE obj)
|
|||||||
return rb_respond_to(obj, id_succ);
|
return rb_respond_to(obj, id_succ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
linear_object_p(VALUE obj)
|
||||||
|
{
|
||||||
|
if (FIXNUM_P(obj) || FLONUM_P(obj)) return TRUE;
|
||||||
|
if (SPECIAL_CONST_P(obj)) return FALSE;
|
||||||
|
switch (BUILTIN_TYPE(obj)) {
|
||||||
|
case T_FLOAT:
|
||||||
|
case T_BIGNUM:
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
if (rb_obj_is_kind_of(obj, rb_cNumeric)) return TRUE;
|
||||||
|
if (rb_obj_is_kind_of(obj, rb_cTime)) return TRUE;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
range_step_size(VALUE range, VALUE args, VALUE eobj)
|
range_step_size(VALUE range, VALUE args, VALUE eobj)
|
||||||
{
|
{
|
||||||
@ -1156,8 +1171,7 @@ range_include(VALUE range, VALUE val)
|
|||||||
VALUE beg = RANGE_BEG(range);
|
VALUE beg = RANGE_BEG(range);
|
||||||
VALUE end = RANGE_END(range);
|
VALUE end = RANGE_END(range);
|
||||||
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
|
int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
|
||||||
rb_obj_is_kind_of(beg, rb_cNumeric) ||
|
linear_object_p(beg) || linear_object_p(end);
|
||||||
rb_obj_is_kind_of(end, rb_cNumeric);
|
|
||||||
|
|
||||||
if (nv ||
|
if (nv ||
|
||||||
!NIL_P(rb_check_to_integer(beg, "to_int")) ||
|
!NIL_P(rb_check_to_integer(beg, "to_int")) ||
|
||||||
|
@ -283,6 +283,14 @@ class TestRange < Test::Unit::TestCase
|
|||||||
assert_not_operator(0..10, :===, 11)
|
assert_not_operator(0..10, :===, 11)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_eqq_time
|
||||||
|
bug11113 = '[ruby-core:69052] [Bug #11113]'
|
||||||
|
t = Time.now
|
||||||
|
assert_nothing_raised(TypeError, bug11113) {
|
||||||
|
assert_operator(t..(t+10), :===, t+5)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_include
|
def test_include
|
||||||
assert_include("a".."z", "c")
|
assert_include("a".."z", "c")
|
||||||
assert_not_include("a".."z", "5")
|
assert_not_include("a".."z", "5")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user