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): fix behavior with excluded end value.

[Bug #4591]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32482 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tarui 2011-07-10 00:47:31 +00:00
parent b1d647c809
commit d22e08f937
3 changed files with 10 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Sun Jul 10 09:46:14 2011 Masaya Tarui <tarui@ruby-lnag.org>
* range.c (range_max): fix behavior with excluded end value.
[Bug #4591]
Sun Jul 10 09:13:18 2011 Eric Hodel <drbrain@segment7.net>
* NEWS: Fix RubyGems version. [Ruby 1.9 - Bug #5004]

View file

@ -665,6 +665,9 @@ range_max(VALUE range)
rb_raise(rb_eTypeError, "cannot exclude non Integer end value");
}
if (c == 0) return Qnil;
if (!FIXNUM_P(b) && !rb_obj_is_kind_of(b,rb_cInteger)) {
rb_raise(rb_eTypeError, "cannot exclude end value with non Integer begin value");
}
if (FIXNUM_P(e)) {
return LONG2NUM(FIX2LONG(e) - 1);
}

View file

@ -68,6 +68,8 @@ class TestRange < Test::Unit::TestCase
assert_equal(2.0, (1.0..2.0).max)
assert_equal(nil, (2.0..1.0).max)
assert_raise(TypeError) { (1.0...2.0).max }
assert_raise(TypeError) { (1...1.5).max }
assert_raise(TypeError) { (1.5...2).max }
assert_equal(-0x80000002, ((-0x80000002)...(-0x80000001)).max)