mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
parent
e72c5044ce
commit
e026368061
Notes:
git
2022-10-21 07:36:07 +00:00
3 changed files with 28 additions and 6 deletions
2
range.c
2
range.c
|
@ -816,8 +816,10 @@ range_size(VALUE range)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (NIL_P(b)) {
|
else if (NIL_P(b)) {
|
||||||
|
if (rb_obj_is_kind_of(e, rb_cNumeric)) {
|
||||||
return DBL2NUM(HUGE_VAL);
|
return DBL2NUM(HUGE_VAL);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,29 @@ describe "Range#size" do
|
||||||
eval("([]...)").size.should == nil
|
eval("([]...)").size.should == nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
ruby_version_is ""..."3.2" do
|
||||||
it 'returns Float::INFINITY for all beginless ranges' do
|
it 'returns Float::INFINITY for all beginless ranges' do
|
||||||
(..1).size.should == Float::INFINITY
|
(..1).size.should == Float::INFINITY
|
||||||
(...0.5).size.should == Float::INFINITY
|
(...0.5).size.should == Float::INFINITY
|
||||||
(..nil).size.should == Float::INFINITY
|
(..nil).size.should == Float::INFINITY
|
||||||
(...'o').size.should == Float::INFINITY
|
(...'o').size.should == Float::INFINITY
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
ruby_version_is "3.2" do
|
||||||
|
it 'returns Float::INFINITY for all beginless ranges if the start is numeric' do
|
||||||
|
(..1).size.should == Float::INFINITY
|
||||||
|
(...0.5).size.should == Float::INFINITY
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil for all beginless ranges if the start is numeric' do
|
||||||
|
(...'o').size.should == nil
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns nil if the start and the end is both nil' do
|
||||||
|
(nil..nil).size.should == nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "returns nil if first and last are not Numeric" do
|
it "returns nil if first and last are not Numeric" do
|
||||||
(:a..:z).size.should be_nil
|
(:a..:z).size.should be_nil
|
||||||
|
|
|
@ -777,6 +777,9 @@ class TestRange < Test::Unit::TestCase
|
||||||
assert_equal 5, (1.1...6).size
|
assert_equal 5, (1.1...6).size
|
||||||
assert_equal 42, (1..42).each.size
|
assert_equal 42, (1..42).each.size
|
||||||
assert_nil ("a"..."z").size
|
assert_nil ("a"..."z").size
|
||||||
|
assert_nil ("a"...).size
|
||||||
|
assert_nil (..."z").size # [Bug #18983]
|
||||||
|
assert_nil (nil...nil).size # [Bug #18983]
|
||||||
|
|
||||||
assert_equal Float::INFINITY, (1...).size
|
assert_equal Float::INFINITY, (1...).size
|
||||||
assert_equal Float::INFINITY, (1.0...).size
|
assert_equal Float::INFINITY, (1.0...).size
|
||||||
|
|
Loading…
Reference in a new issue