shard-spectator/src/spectator/matchers/greater_than_equal_matcher.cr

59 lines
2.1 KiB
Crystal
Raw Normal View History

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.
# 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.
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.
private def match?(actual : Expression(T)) : Bool forall T
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`.
private def failure_message(actual) : String
2019-08-02 03:17:24 +00:00
"#{actual.label} is less than #{expected.label}"
end
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`.
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-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)
{
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)
{
expected: "< #{expected.value.inspect}",
actual: actual.value.inspect,
}
2019-01-24 03:37:33 +00:00
end
end
end