mirror of
https://github.com/ruby/ruby.git
synced 2025-08-28 15:36:16 +02:00
Fixed range argument condition [Feature #14784]
Allows a beginless/endless range, and an end-exclusive range unless the receiver is smaller than its end.
This commit is contained in:
parent
88135845f1
commit
42c652d195
Notes:
git
2019-10-25 23:31:12 +09:00
2 changed files with 51 additions and 26 deletions
|
@ -99,14 +99,21 @@ class TestComparable < Test::Unit::TestCase
|
|||
assert_equal(1, @o.clamp(1..1))
|
||||
assert_equal(@o, @o.clamp(0..0))
|
||||
|
||||
assert_equal(1, @o.clamp(1...2))
|
||||
assert_equal(1, @o.clamp(1..))
|
||||
assert_equal(1, @o.clamp(1...))
|
||||
assert_equal(@o, @o.clamp(0...2))
|
||||
assert_equal(@o, @o.clamp(0..))
|
||||
assert_equal(@o, @o.clamp(0...))
|
||||
assert_equal(@o, @o.clamp(..2))
|
||||
assert_equal(@o, @o.clamp(...2))
|
||||
assert_equal(-1, @o.clamp(-2..-1))
|
||||
assert_equal(@o, @o.clamp(-2..0))
|
||||
assert_equal(@o, @o.clamp(-2..))
|
||||
assert_equal(@o, @o.clamp(-2...))
|
||||
|
||||
assert_raise_with_message(ArgumentError, 'cannot clamp with an exclusive range') {
|
||||
@o.clamp(1...2)
|
||||
}
|
||||
assert_raise_with_message(ArgumentError, 'cannot clamp with an exclusive range') {
|
||||
@o.clamp(1...)
|
||||
}
|
||||
assert_raise_with_message(ArgumentError, 'cannot clamp with an exclusive range') {
|
||||
@o.clamp(...2)
|
||||
@o.clamp(-1...0)
|
||||
}
|
||||
assert_raise_with_message(ArgumentError, 'min argument must be smaller than max argument') {
|
||||
@o.clamp(2..1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue