Change ArgumentError message when Comparable#clamp receives min value higher than max value
This commit is contained in:
parent
5ce3855d90
commit
46066d0b96
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
compar.c
2
compar.c
@ -229,7 +229,7 @@ cmp_clamp(int argc, VALUE *argv, VALUE x)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!NIL_P(min) && !NIL_P(max) && cmpint(min, max) > 0) {
|
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)) {
|
if (!NIL_P(min)) {
|
||||||
|
@ -85,7 +85,7 @@ class TestComparable < Test::Unit::TestCase
|
|||||||
assert_equal(1, @o.clamp(1, 1))
|
assert_equal(1, @o.clamp(1, 1))
|
||||||
assert_equal(@o, @o.clamp(0, 0))
|
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)
|
@o.clamp(2, 1)
|
||||||
}
|
}
|
||||||
end
|
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(-1...0)}
|
||||||
assert_raise_with_message(*exc) {@o.clamp(...2)}
|
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)
|
@o.clamp(2..1)
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user