[前][次][番号順一覧][スレッド一覧]

ruby-changes:55216

From: mame <ko1@a...>
Date: Wed, 3 Apr 2019 17:36:02 +0900 (JST)
Subject: [ruby-changes:55216] mame:r67423 (trunk): range.c (r_cover_range_p): support beginless range

mame	2019-04-03 17:35:57 +0900 (Wed, 03 Apr 2019)

  New Revision: 67423

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67423

  Log:
    range.c (r_cover_range_p): support beginless range
    
    `(..2).cover?(..1)` should return true.

  Modified files:
    trunk/range.c
    trunk/test/ruby/test_range.rb
Index: range.c
===================================================================
--- range.c	(revision 67422)
+++ range.c	(revision 67423)
@@ -1484,8 +1484,9 @@ r_cover_range_p(VALUE range, VALUE beg, https://github.com/ruby/ruby/blob/trunk/range.c#L1484
     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);
 
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 67422)
+++ test/ruby/test_range.rb	(revision 67423)
@@ -581,6 +581,9 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L581
     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 https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L607
     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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]