Project

General

Profile

Feature #6317 » range_cover.diff

masaakiaoyagi (Masaaki Aoyagi), 04/18/2012 08:51 PM

View differences:

range.c
static VALUE
range_cover(VALUE range, VALUE val)
{
VALUE beg, end;
VALUE beg, end, val_beg, val_end;
VALUE range_p = rb_obj_is_kind_of(val, rb_cRange);
int c;
beg = RANGE_BEG(range);
end = RANGE_END(range);
if (r_le(beg, val)) {
if (EXCL(range)) {
if (r_lt(val, end))
return Qtrue;
}
else {
if (r_le(val, end))
return Qtrue;
}
if (range_p) {
val_beg = RANGE_BEG(val);
val_end = RANGE_END(val);
c = r_le(val_beg, val_end);
if (c == Qfalse)
return Qfalse;
if ((c == (int)INT2FIX(0)) && EXCL(val))
return Qfalse;
}
else {
val_beg = val;
val_end = val;
}
if (r_le(beg, val_beg)) {
c = r_le(val_end, end);
if (c == Qtrue)
return Qtrue;
if (c == (int)INT2FIX(0)) {
if (EXCL(range)) {
if (range_p && EXCL(val))
return Qtrue;
}
else {
return Qtrue;
}
}
}
return Qfalse;
}
test/ruby/test_range.rb
assert(("a"..."z").cover?("y"))
assert(!(("a"..."z").cover?("z")))
assert(("a".."z").cover?("cc"))
assert(!(("z".."a").cover?("c")))
assert(("e".."r").cover?("e".."r"))
assert(("e".."r").cover?("e"..."r"))
assert(!(("e".."r").cover?("d".."r")))
assert(!(("e".."r").cover?("e".."s")))
assert(!(("e".."r").cover?("e"..."s")))
assert(!(("e".."r").cover?("a".."d")))
assert(!(("e".."r").cover?("s".."z")))
assert(!(("e"..."r").cover?("e".."r")))
assert(("e"..."r").cover?("e"..."r"))
assert(!(("r".."e").cover?("e".."r")))
assert(!(("e".."r").cover?("r".."e")))
assert(("e".."r").cover?("g".."g"))
assert(!(("e".."r").cover?("g"..."g")))
end
def test_beg_len
    (1-1/1)