summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--range.c5
-rw-r--r--test/ruby/test_range.rb5
2 files changed, 8 insertions, 2 deletions
diff --git a/range.c b/range.c
index 6895511e59d..acf4a5cd742 100644
--- a/range.c
+++ b/range.c
@@ -1484,8 +1484,9 @@ r_cover_range_p(VALUE range, VALUE beg, VALUE end, VALUE val)
val_end = RANGE_END(val);
if (!NIL_P(end) && NIL_P(val_end)) return FALSE;
- if (!NIL_P(val_end) && r_less(val_beg, val_end) > -EXCL(val)) return FALSE;
- if (!r_cover_p(range, beg, end, val_beg)) return FALSE;
+ if (!NIL_P(beg) && NIL_P(val_beg)) return FALSE;
+ if (!NIL_P(val_beg) && !NIL_P(val_end) && r_less(val_beg, val_end) > -EXCL(val)) return FALSE;
+ if (!NIL_P(val_beg) && !r_cover_p(range, beg, end, val_beg)) return FALSE;
cmp_end = r_less(end, val_end);
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index 6c1761f3b0e..b631c7d2b9a 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -581,6 +581,9 @@ class TestRange < Test::Unit::TestCase
assert_operator(2.., :cover?, 2..)
assert_operator(2.., :cover?, 3..)
assert_operator(1.., :cover?, 1..10)
+ assert_operator(..2, :cover?, ..2)
+ assert_operator(..2, :cover?, ..1)
+ assert_operator(..2, :cover?, 0..1)
assert_operator(2.0..5.0, :cover?, 2..3)
assert_operator(2..5, :cover?, 2.0..3.0)
assert_operator(2..5, :cover?, 2.0...3.0)
@@ -604,7 +607,9 @@ class TestRange < Test::Unit::TestCase
assert_not_operator(1...2, :cover?, 1...3)
assert_not_operator(2.., :cover?, 1..)
assert_not_operator(2.., :cover?, 1..10)
+ assert_not_operator(2.., :cover?, ..10)
assert_not_operator(1..10, :cover?, 1..)
+ assert_not_operator(1..10, :cover?, ..1)
assert_not_operator(1..5, :cover?, 3..2)
assert_not_operator(1..10, :cover?, 3...2)
assert_not_operator(1..10, :cover?, 3...3)