summaryrefslogtreecommitdiff
path: root/test/ruby/test_comparable.rb
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-25 22:09:38 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-10-25 23:30:47 +0900
commit42c652d1959564bc5fb5147c8c343d8c0589583c (patch)
tree4d5a3f1344d97f8e6f65e299e702bb7326f5dc49 /test/ruby/test_comparable.rb
parent88135845f10f4b8ea3b67584a2c899ad365fd6bb (diff)
downloadruby-42c652d1959564bc5fb5147c8c343d8c0589583c.tar.gz
Fixed range argument condition [Feature #14784]
Allows a beginless/endless range, and an end-exclusive range unless the receiver is smaller than its end.
Diffstat (limited to 'test/ruby/test_comparable.rb')
-rw-r--r--test/ruby/test_comparable.rb21
1 files changed, 14 insertions, 7 deletions
diff --git a/test/ruby/test_comparable.rb b/test/ruby/test_comparable.rb
index c363a03a64..e8a2ff1a7a 100644
--- a/test/ruby/test_comparable.rb
+++ b/test/ruby/test_comparable.rb
@@ -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)