Update comparison matchers

This commit is contained in:
Michael Miller 2019-08-01 21:17:24 -06:00
parent 42b8fe471f
commit 5cc735368c
4 changed files with 80 additions and 116 deletions

View file

@ -4,43 +4,34 @@ module Spectator::Matchers
# Matcher that tests whether one value is greater than or equal to another. # Matcher that tests whether one value is greater than or equal to another.
# The values are compared with the >= operator. # The values are compared with the >= operator.
struct GreaterThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType) struct GreaterThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Determines whether the matcher is satisfied with the value given to it.
private def match?(actual) private def match?(actual)
actual >= expected actual.value >= expected.value
end end
# Determines whether the matcher is satisfied with the partial given to it. def description
def match(partial, negated = false) "greater than or equal to #{expected.label}"
values = ExpectedActual.new(partial, self)
MatchData.new(match?(values.actual), values)
end end
# Match data specific to this matcher. private def failure_message(actual)
private struct MatchData(ExpectedType, ActualType) < MatchData "#{actual.label} is less than #{expected.label}"
# Creates the match data. end
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
super(matched)
end
# Information about the match. private def failure_message_when_negated(actual)
def named_tuple "#{actual.label} is greater than or equal to #{expected.label}"
{ end
expected: NegatablePrefixedMatchDataValue.new(">=", "<", @values.expected),
actual: @values.actual,
}
end
# Describes the condition that satisfies the matcher. private def values(actual)
# This is informational and displayed to the end-user. [
def message LabeledValue.new(">= #{expected.value}", "expected"),
"#{@values.actual_label} is greater than or equal to #{@values.expected_label} (using >=)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end
# Describes the condition that won't satsify the matcher. private def negated_values(actual)
# This is informational and displayed to the end-user. [
def negated_message LabeledValue.new("< #{expected.value}", "expected"),
"#{@values.actual_label} is less than #{@values.expected_label} (using >=)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end end
end end
end end

View file

@ -4,43 +4,34 @@ module Spectator::Matchers
# Matcher that tests whether one value is greater than another. # Matcher that tests whether one value is greater than another.
# The values are compared with the > operator. # The values are compared with the > operator.
struct GreaterThanMatcher(ExpectedType) < ValueMatcher(ExpectedType) struct GreaterThanMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Determines whether the matcher is satisfied with the value given to it.
private def match?(actual) private def match?(actual)
actual > expected actual.value > expected.value
end end
# Determines whether the matcher is satisfied with the partial given to it. def description
def match(partial, negated = false) "greater than #{expected.label}"
values = ExpectedActual.new(partial, self)
MatchData.new(match?(values.actual), values)
end end
# Match data specific to this matcher. private def failure_message(actual)
private struct MatchData(ExpectedType, ActualType) < MatchData "#{actual.label} is less than or equal to #{expected.label}"
# Creates the match data. end
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
super(matched)
end
# Information about the match. private def failure_message_when_negated(actual)
def named_tuple "#{actual.label} is greater than #{expected.label}"
{ end
expected: NegatablePrefixedMatchDataValue.new(">", "<=", @values.expected),
actual: @values.actual,
}
end
# Describes the condition that satisfies the matcher. private def values(actual)
# This is informational and displayed to the end-user. [
def message LabeledValue.new("> #{expected.value}", "expected"),
"#{@values.actual_label} is greater than #{@values.expected_label} (using >)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end
# Describes the condition that won't satsify the matcher. private def negated_values(actual)
# This is informational and displayed to the end-user. [
def negated_message LabeledValue.new("<= #{expected.value}", "expected"),
"#{@values.actual_label} is less than or equal to #{@values.expected_label} (using >)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end end
end end
end end

View file

@ -4,43 +4,34 @@ module Spectator::Matchers
# Matcher that tests whether one value is less than or equal to another. # Matcher that tests whether one value is less than or equal to another.
# The values are compared with the <= operator. # The values are compared with the <= operator.
struct LessThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType) struct LessThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Determines whether the matcher is satisfied with the value given to it.
private def match?(actual) private def match?(actual)
actual <= expected actual.value <= expected.value
end end
# Determines whether the matcher is satisfied with the partial given to it. def description
def match(partial, negated = false) "less than or equal to #{expected.label}"
values = ExpectedActual.new(partial, self)
MatchData.new(match?(values.actual), values)
end end
# Match data specific to this matcher. private def failure_message(actual)
private struct MatchData(ExpectedType, ActualType) < MatchData "#{actual.label} is greater than #{expected.label}"
# Creates the match data. end
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
super(matched)
end
# Information about the match. private def failure_message_when_negated(actual)
def named_tuple "#{actual.label} is less than or equal to #{expected.label}"
{ end
expected: NegatablePrefixedMatchDataValue.new("<=", ">", @values.expected),
actual: @values.actual,
}
end
# Describes the condition that satisfies the matcher. private def values(actual)
# This is informational and displayed to the end-user. [
def message LabeledValue.new("<= #{expected.value}", "expected"),
"#{@values.actual_label} is less than or equal to #{@values.expected_label} (using <=)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end
# Describes the condition that won't satsify the matcher. private def negated_values(actual)
# This is informational and displayed to the end-user. [
def negated_message LabeledValue.new("> #{expected.value}", "expected"),
"#{@values.actual_label} is greater than #{@values.expected_label} (using <=)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end end
end end
end end

View file

@ -4,43 +4,34 @@ module Spectator::Matchers
# Matcher that tests whether one value is less than another. # Matcher that tests whether one value is less than another.
# The values are compared with the < operator. # The values are compared with the < operator.
struct LessThanMatcher(ExpectedType) < ValueMatcher(ExpectedType) struct LessThanMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Determines whether the matcher is satisfied with the value given to it.
private def match?(actual) private def match?(actual)
actual < expected actual.value < expected.value
end end
# Determines whether the matcher is satisfied with the partial given to it. def description
def match(partial, negated = false) "less than #{expected.label}"
values = ExpectedActual.new(partial, self)
MatchData.new(match?(values.actual), values)
end end
# Match data specific to this matcher. private def failure_message(actual)
private struct MatchData(ExpectedType, ActualType) < MatchData "#{actual.label} is greater than or equal to #{expected.label}"
# Creates the match data. end
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
super(matched)
end
# Information about the match. private def failure_message_when_negated(actual)
def named_tuple "#{actual.label} is less than #{expected.label}"
{ end
expected: NegatablePrefixedMatchDataValue.new("<", ">=", @values.expected),
actual: @values.actual,
}
end
# Describes the condition that satisfies the matcher. private def values(actual)
# This is informational and displayed to the end-user. [
def message LabeledValue.new("< #{expected.value}", "expected"),
"#{@values.actual_label} is less than #{@values.expected_label} (using <)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end
# Describes the condition that won't satsify the matcher. private def negated_values(actual)
# This is informational and displayed to the end-user. [
def negated_message LabeledValue.new(">= #{expected.value}", "expected"),
"#{@values.actual_label} is greater than or equal to #{@values.expected_label} (using <)" LabeledValue.new(actual.value.to_s, "actual")
end ]
end end
end end
end end