summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--range.c9
-rw-r--r--test/ruby/test_range.rb23
2 files changed, 32 insertions, 0 deletions
diff --git a/range.c b/range.c
index a6ef8c9835..7c116d78c7 100644
--- a/range.c
+++ b/range.c
@@ -1820,6 +1820,7 @@ range_string_cover_internal(VALUE range, VALUE val)
return r_cover_p(range, beg, end, val);
}
if (NIL_P(beg)) {
+unbounded_begin:;
VALUE r = rb_funcall(val, id_cmp, 1, end);
if (NIL_P(r)) return Qfalse;
if (RANGE_EXCL(range)) {
@@ -1828,12 +1829,20 @@ range_string_cover_internal(VALUE range, VALUE val)
return RBOOL(rb_cmpint(r, val, end) <= 0);
}
else if (NIL_P(end)) {
+unbounded_end:;
VALUE r = rb_funcall(beg, id_cmp, 1, val);
if (NIL_P(r)) return Qfalse;
return RBOOL(rb_cmpint(r, beg, val) <= 0);
}
}
+ if (!NIL_P(beg) && NIL_P(end)) {
+ goto unbounded_end;
+ }
+ if (NIL_P(beg) && !NIL_P(end)) {
+ goto unbounded_begin;
+ }
+
return range_include_fallback(beg, end, val);
}
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 8c01254d19..8c310b0bae 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -2,6 +2,7 @@
require 'test/unit'
require 'delegate'
require 'timeout'
+require 'date'
require 'rbconfig/sizeof'
class TestRange < Test::Unit::TestCase
@@ -624,6 +625,28 @@ class TestRange < Test::Unit::TestCase
assert_operator(c.new(0)..c.new(10), :===, c.new(5), bug12003)
end
+ def test_eqq_unbounded_ruby_bug_19864
+ t1 = Date.today
+ t2 = t1 + 1
+ assert_equal(true, (..t1) === t1)
+ assert_equal(false, (..t1) === t2)
+ assert_equal(true, (..t2) === t1)
+ assert_equal(true, (..t2) === t2)
+ assert_equal(false, (...t1) === t1)
+ assert_equal(false, (...t1) === t2)
+ assert_equal(true, (...t2) === t1)
+ assert_equal(false, (...t2) === t2)
+
+ assert_equal(true, (t1..) === t1)
+ assert_equal(true, (t1..) === t2)
+ assert_equal(false, (t2..) === t1)
+ assert_equal(true, (t2..) === t2)
+ assert_equal(true, (t1...) === t1)
+ assert_equal(true, (t1...) === t2)
+ assert_equal(false, (t2...) === t1)
+ assert_equal(true, (t2...) === t2)
+ end
+
def test_eqq_non_iteratable
k = Class.new do
include Comparable