зеркало из https://github.com/github/ruby.git
Make Range#reverse_each raise TypeError if endless
This commit is contained in:
Родитель
0164da68c1
Коммит
1a16b6ffc2
5
range.c
5
range.c
|
@ -1133,6 +1133,11 @@ range_reverse_each(VALUE range)
|
|||
VALUE end = RANGE_END(range);
|
||||
int excl = EXCL(range);
|
||||
|
||||
if (NIL_P(end)) {
|
||||
rb_raise(rb_eTypeError, "can't iterate from %s",
|
||||
rb_obj_classname(end));
|
||||
}
|
||||
|
||||
if (FIXNUM_P(beg) && FIXNUM_P(end)) {
|
||||
if (excl) {
|
||||
if (end == LONG2FIX(FIXNUM_MIN)) return range;
|
||||
|
|
|
@ -582,6 +582,14 @@ class TestRange < Test::Unit::TestCase
|
|||
assert_equal([fmin-2, fmin-3], a)
|
||||
end
|
||||
|
||||
def test_reverse_each_for_endless_range
|
||||
assert_raise(TypeError) { (1..).reverse_each {} }
|
||||
|
||||
enum = nil
|
||||
assert_nothing_raised { enum = (1..).reverse_each }
|
||||
assert_raise(TypeError) { enum.each {} }
|
||||
end
|
||||
|
||||
def test_reverse_each_for_single_point_range
|
||||
fmin = RbConfig::LIMITS['FIXNUM_MIN']
|
||||
fmax = RbConfig::LIMITS['FIXNUM_MAX']
|
||||
|
|
Загрузка…
Ссылка в новой задаче