Sub-type value modifier from MatchDataValue

This includes renaming the types.
This commit is contained in:
Michael Miller 2019-03-22 10:55:57 -06:00
parent 4f6309a032
commit 33841e8888
27 changed files with 43 additions and 35 deletions

View file

@ -4,7 +4,7 @@ def match_data_value(match_data, key)
end end
# Retrieves the string representation and base value # Retrieves the string representation and base value
# from a `Spectator::Matchers::PrefixedValue` # from a `Spectator::Matchers::PrefixedMatchDataValue`
# in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`. # in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`.
def match_data_prefix(match_data, key) def match_data_prefix(match_data, key)
prefix = match_data.values.fetch(key) { raise "#{key} is missing" } prefix = match_data.values.fetch(key) { raise "#{key} is missing" }

View file

@ -1,7 +1,9 @@
require "./match_data_value"
module Spectator::Matchers module Spectator::Matchers
# Selects a value based on whether the value is negated. # Selects a value based on whether the value is negated.
# This is used when a matcher is negated. # This is used when a matcher is negated.
private class AlternativeValue(T1, T2) private struct AlternativeMatchDataValue(T1, T2) < MatchDataValue
# Creates the wrapper. # Creates the wrapper.
def initialize(@value1 : T1, @value2 : T2) def initialize(@value1 : T1, @value2 : T2)
@negated = false @negated = false

View file

@ -49,7 +49,7 @@ module Spectator::Matchers
{% begin %} {% begin %}
{ {
{% for attribute in ExpectedType.keys %} {% for attribute in ExpectedType.keys %}
{{"expected " + attribute.stringify}}: NegatableValue.new(@values.expected[{{attribute.symbolize}}]), {{"expected " + attribute.stringify}}: NegatableMatchDataValue.new(@values.expected[{{attribute.symbolize}}]),
{{"actual " + attribute.stringify}}: @values.actual[{{attribute.symbolize}}], {{"actual " + attribute.stringify}}: @values.actual[{{attribute.symbolize}}],
{% end %} {% end %}
} }

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(@values.expected), expected: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -28,7 +28,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
subset: NegatableValue.new(@values.expected), subset: NegatableMatchDataValue.new(@values.expected),
superset: @values.actual, superset: @values.actual,
} }
end end

View file

@ -27,7 +27,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new([] of Nil), expected: NegatableMatchDataValue.new([] of Nil),
actual: @actual, actual: @actual,
} }
end end

View file

@ -39,7 +39,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(@values.expected), expected: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(@values.expected), expected: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -67,7 +67,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
"expected type": NegatableValue.new(ExceptionType), "expected type": NegatableMatchDataValue.new(ExceptionType),
"actual type": @values.actual.class, "actual type": @values.actual.class,
} }
end end
@ -95,9 +95,9 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
"expected type": NegatableValue.new(ExceptionType), "expected type": NegatableMatchDataValue.new(ExceptionType),
"actual type": @values.actual.class, "actual type": @values.actual.class,
"expected message": NegatableValue.new(@values.expected), "expected message": NegatableMatchDataValue.new(@values.expected),
"actual message": @values.actual.message, "actual message": @values.actual.message,
} }
end end

View file

@ -26,8 +26,8 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatablePrefixedValue.new(">=", "<", @values.expected), expected: NegatablePrefixedMatchDataValue.new(">=", "<", @values.expected),
actual: PrefixedValue.new(actual_operator, @values.actual), actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
} }
end end

View file

@ -26,8 +26,8 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatablePrefixedValue.new(">", "<=", @values.expected), expected: NegatablePrefixedMatchDataValue.new(">", "<=", @values.expected),
actual: PrefixedValue.new(actual_operator, @values.actual), actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
} }
end end

View file

@ -27,7 +27,7 @@ module Spectator::Matchers
def named_tuple def named_tuple
actual = @values.actual actual = @values.actual
{ {
key: NegatableValue.new(@values.expected), key: NegatableMatchDataValue.new(@values.expected),
actual: actual.responds_to?(:keys) ? actual.keys : actual, actual: actual.responds_to?(:keys) ? actual.keys : actual,
} }
end end

View file

@ -51,7 +51,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
subset: NegatableValue.new(@values.expected), subset: NegatableMatchDataValue.new(@values.expected),
superset: @values.actual, superset: @values.actual,
} }
end end

View file

@ -27,7 +27,7 @@ module Spectator::Matchers
def named_tuple def named_tuple
actual = @values.actual actual = @values.actual
{ {
value: NegatableValue.new(@values.expected), value: NegatableMatchDataValue.new(@values.expected),
actual: actual.responds_to?(:values) ? actual.values : actual, actual: actual.responds_to?(:values) ? actual.values : actual,
} }
end end

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatablePrefixedValue.new("Not", "", @values.expected), expected: NegatablePrefixedMatchDataValue.new("Not", "", @values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -26,8 +26,8 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatablePrefixedValue.new("<=", ">", @values.expected), expected: NegatablePrefixedMatchDataValue.new("<=", ">", @values.expected),
actual: PrefixedValue.new(actual_operator, @values.actual), actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
} }
end end

View file

@ -26,8 +26,8 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatablePrefixedValue.new("<", ">=", @values.expected), expected: NegatablePrefixedMatchDataValue.new("<", ">=", @values.expected),
actual: PrefixedValue.new(actual_operator, @values.actual), actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
} }
end end

View file

@ -1,6 +1,6 @@
require "./match_data_labeled_value" require "./match_data_labeled_value"
require "./match_data_value" require "./match_data_value"
require "./generic_match-data_value" require "./generic_match_data_value"
module Spectator::Matchers module Spectator::Matchers
# Information regarding a expectation parial and matcher. # Information regarding a expectation parial and matcher.

View file

@ -1,7 +1,9 @@
require "./match_data_value"
module Spectator::Matchers module Spectator::Matchers
# Wraps an expected value that can be negated. # Wraps an expected value that can be negated.
# This is used when a matcher is negated. # This is used when a matcher is negated.
private class NegatableValue(T) private class NegatableMatchDataValue(T) < MatchDataValue
# Negatable value. # Negatable value.
getter value getter value

View file

@ -1,7 +1,9 @@
require "./match_data_value"
module Spectator::Matchers module Spectator::Matchers
# Wraps a prefixed value that can be negated. # Wraps a prefixed value that can be negated.
# This is used when a matcher is negated. # This is used when a matcher is negated.
private class NegatablePrefixedValue(T) private struct NegatablePrefixedMatchDataValue(T) < MatchDataValue
# Negatable value. # Negatable value.
getter value getter value

View file

@ -27,7 +27,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(nil), expected: NegatableMatchDataValue.new(nil),
actual: @actual, actual: @actual,
} }
end end

View file

@ -1,6 +1,8 @@
require "./match_data_value"
module Spectator::Matchers module Spectator::Matchers
# Prefixes (for output formatting) an actual or expected value. # Prefixes (for output formatting) an actual or expected value.
private struct PrefixedValue(T) private struct PrefixedMatchDataValue(T) < MatchDataValue
# Value being prefixed. # Value being prefixed.
getter value : T getter value : T

View file

@ -67,8 +67,8 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
lower: NegatablePrefixedValue.new(">=", "<", range.begin), lower: NegatablePrefixedMatchDataValue.new(">=", "<", range.begin),
upper: NegatablePrefixedValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end), upper: NegatablePrefixedMatchDataValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end),
actual: @values.actual, actual: @values.actual,
} }
end end
@ -112,7 +112,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
set: NegatableValue.new(@values.expected), set: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(@values.expected), expected: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -39,7 +39,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(@values.expected), expected: NegatableMatchDataValue.new(@values.expected),
actual: @values.actual, actual: @values.actual,
} }
end end

View file

@ -99,7 +99,7 @@ module Spectator::Matchers
truthy = "Not false or nil" truthy = "Not false or nil"
falsey = "false or nil" falsey = "false or nil"
{ {
expected: AlternativeValue.new(@truthy ? truthy : falsey, @truthy ? falsey : truthy), expected: AlternativeMatchDataValue.new(@truthy ? truthy : falsey, @truthy ? falsey : truthy),
actual: @actual, actual: @actual,
truthy: !!@actual, truthy: !!@actual,
} }

View file

@ -32,7 +32,7 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
def named_tuple def named_tuple
{ {
expected: NegatableValue.new(ExpectedType), expected: NegatableMatchDataValue.new(ExpectedType),
actual: ActualType, actual: ActualType,
} }
end end