1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* range.c (range_max, range_min): return nil for empty set as well as

1.8 and Enumerable.  [ruby-dev:31198]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12754 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2007-07-13 02:33:11 +00:00
parent 608545ced0
commit 113a709cce
3 changed files with 13 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Fri Jul 13 11:33:09 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* range.c (range_max, range_min): return nil for empty set as well as
1.8 and Enumerable. [ruby-dev:31198]
Fri Jul 13 11:28:37 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* parse.y (bvar): semicolon was lost for ripper description.

View file

@ -468,7 +468,7 @@ range_min(VALUE range)
VALUE e = rb_ivar_get(range, id_end);
int c = rb_cmpint(rb_funcall(b, id_cmp, 1, e), b, e);
if (c > 0)
if (c > 0 || (c == 0 && EXCL(range)))
return Qnil;
return b;
}
@ -502,6 +502,7 @@ range_max(VALUE range)
if (c > 0)
return Qnil;
if (EXCL(range)) {
if (c == 0) return Qnil;
if (FIXNUM_P(e)) {
return LONG2NUM(FIX2LONG(e) - 1);
}

View file

@ -40,6 +40,9 @@ class TestRange < Test::Unit::TestCase
assert_equal(1.0, (1.0..2.0).min)
assert_equal(nil, (2.0..1.0).min)
assert_equal(1, (1.0...2.0).min)
assert_equal(0, (0..0).min)
assert_equal(nil, (0...0).min)
end
def test_max
@ -52,5 +55,8 @@ class TestRange < Test::Unit::TestCase
assert_raise(TypeError) { (1.0...2.0).max }
assert_equal(-0x80000002, ((-0x80000002)...(-0x80000001)).max)
assert_equal(0, (0..0).max)
assert_equal(nil, (0...0).max)
end
end