Change ArgumentError message when Comparable#clamp receives min value higher than max value

This commit is contained in:
Kaíque Kandy Koga 2023-01-18 02:25:11 -03:00 committed by GitHub
parent 5ce3855d90
commit 46066d0b96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
Notes: git 2023-01-18 05:25:32 +00:00
Merged: https://github.com/ruby/ruby/pull/6802

Merged-By: jeremyevans <code@jeremyevans.net>
2 changed files with 3 additions and 3 deletions

View File

@ -229,7 +229,7 @@ cmp_clamp(int argc, VALUE *argv, VALUE x)
}
}
if (!NIL_P(min) && !NIL_P(max) && cmpint(min, max) > 0) {
rb_raise(rb_eArgError, "min argument must be smaller than max argument");
rb_raise(rb_eArgError, "min argument must be less than or equal to max argument");
}
if (!NIL_P(min)) {

View File

@ -85,7 +85,7 @@ class TestComparable < Test::Unit::TestCase
assert_equal(1, @o.clamp(1, 1))
assert_equal(@o, @o.clamp(0, 0))
assert_raise_with_message(ArgumentError, 'min argument must be smaller than max argument') {
assert_raise_with_message(ArgumentError, 'min argument must be less than or equal to max argument') {
@o.clamp(2, 1)
}
end
@ -115,7 +115,7 @@ class TestComparable < Test::Unit::TestCase
assert_raise_with_message(*exc) {@o.clamp(-1...0)}
assert_raise_with_message(*exc) {@o.clamp(...2)}
assert_raise_with_message(ArgumentError, 'min argument must be smaller than max argument') {
assert_raise_with_message(ArgumentError, 'min argument must be less than or equal to max argument') {
@o.clamp(2..1)
}
end