mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Sub-type value modifier from MatchDataValue
This includes renaming the types.
This commit is contained in:
parent
4f6309a032
commit
33841e8888
27 changed files with 43 additions and 35 deletions
|
@ -4,7 +4,7 @@ def match_data_value(match_data, key)
|
|||
end
|
||||
|
||||
# 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`.
|
||||
def match_data_prefix(match_data, key)
|
||||
prefix = match_data.values.fetch(key) { raise "#{key} is missing" }
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
require "./match_data_value"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Selects a value based on whether the value is negated.
|
||||
# This is used when a matcher is negated.
|
||||
private class AlternativeValue(T1, T2)
|
||||
private struct AlternativeMatchDataValue(T1, T2) < MatchDataValue
|
||||
# Creates the wrapper.
|
||||
def initialize(@value1 : T1, @value2 : T2)
|
||||
@negated = false
|
|
@ -49,7 +49,7 @@ module Spectator::Matchers
|
|||
{% begin %}
|
||||
{
|
||||
{% 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}}],
|
||||
{% end %}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(@values.expected),
|
||||
expected: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
subset: NegatableValue.new(@values.expected),
|
||||
subset: NegatableMatchDataValue.new(@values.expected),
|
||||
superset: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new([] of Nil),
|
||||
expected: NegatableMatchDataValue.new([] of Nil),
|
||||
actual: @actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(@values.expected),
|
||||
expected: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(@values.expected),
|
||||
expected: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -67,7 +67,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
"expected type": NegatableValue.new(ExceptionType),
|
||||
"expected type": NegatableMatchDataValue.new(ExceptionType),
|
||||
"actual type": @values.actual.class,
|
||||
}
|
||||
end
|
||||
|
@ -95,9 +95,9 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
"expected type": NegatableValue.new(ExceptionType),
|
||||
"expected type": NegatableMatchDataValue.new(ExceptionType),
|
||||
"actual type": @values.actual.class,
|
||||
"expected message": NegatableValue.new(@values.expected),
|
||||
"expected message": NegatableMatchDataValue.new(@values.expected),
|
||||
"actual message": @values.actual.message,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -26,8 +26,8 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatablePrefixedValue.new(">=", "<", @values.expected),
|
||||
actual: PrefixedValue.new(actual_operator, @values.actual),
|
||||
expected: NegatablePrefixedMatchDataValue.new(">=", "<", @values.expected),
|
||||
actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatablePrefixedValue.new(">", "<=", @values.expected),
|
||||
actual: PrefixedValue.new(actual_operator, @values.actual),
|
||||
expected: NegatablePrefixedMatchDataValue.new(">", "<=", @values.expected),
|
||||
actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ module Spectator::Matchers
|
|||
def named_tuple
|
||||
actual = @values.actual
|
||||
{
|
||||
key: NegatableValue.new(@values.expected),
|
||||
key: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: actual.responds_to?(:keys) ? actual.keys : actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -51,7 +51,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
subset: NegatableValue.new(@values.expected),
|
||||
subset: NegatableMatchDataValue.new(@values.expected),
|
||||
superset: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -27,7 +27,7 @@ module Spectator::Matchers
|
|||
def named_tuple
|
||||
actual = @values.actual
|
||||
{
|
||||
value: NegatableValue.new(@values.expected),
|
||||
value: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: actual.responds_to?(:values) ? actual.values : actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatablePrefixedValue.new("Not", "", @values.expected),
|
||||
expected: NegatablePrefixedMatchDataValue.new("Not", "", @values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -26,8 +26,8 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatablePrefixedValue.new("<=", ">", @values.expected),
|
||||
actual: PrefixedValue.new(actual_operator, @values.actual),
|
||||
expected: NegatablePrefixedMatchDataValue.new("<=", ">", @values.expected),
|
||||
actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -26,8 +26,8 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatablePrefixedValue.new("<", ">=", @values.expected),
|
||||
actual: PrefixedValue.new(actual_operator, @values.actual),
|
||||
expected: NegatablePrefixedMatchDataValue.new("<", ">=", @values.expected),
|
||||
actual: PrefixedMatchDataValue.new(actual_operator, @values.actual),
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
require "./match_data_labeled_value"
|
||||
require "./match_data_value"
|
||||
require "./generic_match-data_value"
|
||||
require "./generic_match_data_value"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Information regarding a expectation parial and matcher.
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
require "./match_data_value"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Wraps an expected value that can be negated.
|
||||
# This is used when a matcher is negated.
|
||||
private class NegatableValue(T)
|
||||
private class NegatableMatchDataValue(T) < MatchDataValue
|
||||
# Negatable value.
|
||||
getter value
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
require "./match_data_value"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Wraps a prefixed value that can be negated.
|
||||
# This is used when a matcher is negated.
|
||||
private class NegatablePrefixedValue(T)
|
||||
private struct NegatablePrefixedMatchDataValue(T) < MatchDataValue
|
||||
# Negatable value.
|
||||
getter value
|
||||
|
|
@ -27,7 +27,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(nil),
|
||||
expected: NegatableMatchDataValue.new(nil),
|
||||
actual: @actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
require "./match_data_value"
|
||||
|
||||
module Spectator::Matchers
|
||||
# Prefixes (for output formatting) an actual or expected value.
|
||||
private struct PrefixedValue(T)
|
||||
private struct PrefixedMatchDataValue(T) < MatchDataValue
|
||||
# Value being prefixed.
|
||||
getter value : T
|
||||
|
|
@ -67,8 +67,8 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
lower: NegatablePrefixedValue.new(">=", "<", range.begin),
|
||||
upper: NegatablePrefixedValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end),
|
||||
lower: NegatablePrefixedMatchDataValue.new(">=", "<", range.begin),
|
||||
upper: NegatablePrefixedMatchDataValue.new(exclusive? ? "<" : "<=", exclusive? ? ">=" : ">", range.end),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
@ -112,7 +112,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
set: NegatableValue.new(@values.expected),
|
||||
set: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -26,7 +26,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(@values.expected),
|
||||
expected: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(@values.expected),
|
||||
expected: NegatableMatchDataValue.new(@values.expected),
|
||||
actual: @values.actual,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -99,7 +99,7 @@ module Spectator::Matchers
|
|||
truthy = "Not 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,
|
||||
truthy: !!@actual,
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ module Spectator::Matchers
|
|||
# Information about the match.
|
||||
def named_tuple
|
||||
{
|
||||
expected: NegatableValue.new(ExpectedType),
|
||||
expected: NegatableMatchDataValue.new(ExpectedType),
|
||||
actual: ActualType,
|
||||
}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue