2019-01-24 03:37:33 +00:00
|
|
|
require "./value_matcher"
|
|
|
|
|
|
|
|
module Spectator::Matchers
|
|
|
|
# Matcher that tests whether one value is greater than or equal to another.
|
2019-02-18 06:01:43 +00:00
|
|
|
# The values are compared with the >= operator.
|
2019-01-24 03:37:33 +00:00
|
|
|
struct GreaterThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
2019-08-10 16:50:48 +00:00
|
|
|
# Short text about the matcher's purpose.
|
|
|
|
# This explains what condition satisfies the matcher.
|
|
|
|
# The description is used when the one-liner syntax is used.
|
2019-09-24 02:32:21 +00:00
|
|
|
def description : String
|
2019-08-02 03:17:24 +00:00
|
|
|
"greater than or equal to #{expected.label}"
|
2019-02-24 05:33:33 +00:00
|
|
|
end
|
|
|
|
|
2021-11-28 22:45:17 +00:00
|
|
|
# Checks whether the matcher is satisfied with the expression given to it.
|
2021-01-16 18:02:29 +00:00
|
|
|
private def match?(actual : Expression(T)) : Bool forall T
|
2019-08-10 17:10:48 +00:00
|
|
|
actual.value >= expected.value
|
|
|
|
end
|
|
|
|
|
2021-11-28 22:45:17 +00:00
|
|
|
# Message displayed when the matcher isn't satisfied.
|
2019-08-10 16:50:48 +00:00
|
|
|
#
|
|
|
|
# This is only called when `#match?` returns false.
|
|
|
|
#
|
|
|
|
# The message should typically only contain the test expression labels.
|
|
|
|
# Actual values should be returned by `#values`.
|
2019-09-24 02:32:21 +00:00
|
|
|
private def failure_message(actual) : String
|
2019-08-02 03:17:24 +00:00
|
|
|
"#{actual.label} is less than #{expected.label}"
|
|
|
|
end
|
2019-03-05 22:39:30 +00:00
|
|
|
|
2021-11-28 22:45:17 +00:00
|
|
|
# Message displayed when the matcher isn't satisfied and is negated.
|
2019-08-10 16:50:48 +00:00
|
|
|
# This is essentially what would satisfy the matcher if it wasn't negated.
|
|
|
|
#
|
|
|
|
# This is only called when `#does_not_match?` returns false.
|
|
|
|
#
|
|
|
|
# The message should typically only contain the test expression labels.
|
|
|
|
# Actual values should be returned by `#values`.
|
2019-09-24 02:32:21 +00:00
|
|
|
private def failure_message_when_negated(actual) : String
|
2019-08-02 03:17:24 +00:00
|
|
|
"#{actual.label} is greater than or equal to #{expected.label}"
|
|
|
|
end
|
2019-03-05 22:39:30 +00:00
|
|
|
|
2019-08-10 16:50:48 +00:00
|
|
|
# Additional information about the match failure.
|
|
|
|
# The return value is a NamedTuple with Strings for each value.
|
2019-08-02 03:17:24 +00:00
|
|
|
private def values(actual)
|
2019-08-07 05:13:33 +00:00
|
|
|
{
|
|
|
|
expected: ">= #{expected.value.inspect}",
|
|
|
|
actual: actual.value.inspect,
|
|
|
|
}
|
2019-08-02 03:17:24 +00:00
|
|
|
end
|
2019-01-24 03:37:33 +00:00
|
|
|
|
2019-08-10 16:50:48 +00:00
|
|
|
# Additional information about the match failure when negated.
|
|
|
|
# The return value is a NamedTuple with Strings for each value.
|
2019-08-02 03:17:24 +00:00
|
|
|
private def negated_values(actual)
|
2019-08-07 05:13:33 +00:00
|
|
|
{
|
|
|
|
expected: "< #{expected.value.inspect}",
|
|
|
|
actual: actual.value.inspect,
|
|
|
|
}
|
2019-01-24 03:37:33 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|