mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Capture element type
This commit is contained in:
parent
0eaf8efcc6
commit
3ff5b2ac5e
1 changed files with 19 additions and 5 deletions
|
@ -3,7 +3,7 @@ require "./value_matcher"
|
|||
module Spectator::Matchers
|
||||
# Matcher for checking that the contents of one array (or similar type)
|
||||
# has the exact same contents as another and in the same order.
|
||||
struct ArrayMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||
struct ArrayMatcher(ExpectedType) < ValueMatcher(Array(ExpectedType))
|
||||
# Determines whether the matcher is satisfied with the partial given to it.
|
||||
# `MatchData` is returned that contains information about the match.
|
||||
def match(partial)
|
||||
|
@ -21,10 +21,24 @@ module Spectator::Matchers
|
|||
end
|
||||
end
|
||||
|
||||
# Creates the value matcher.
|
||||
# The label should be a string representation of the expectation.
|
||||
# The expected value is stored for later use.
|
||||
def initialize(expected : Array(ExpectedType), label : String)
|
||||
super
|
||||
end
|
||||
|
||||
# Creates the value matcher.
|
||||
# The label is generated by calling `#to_s` on the expected value.
|
||||
# The expected value is stored for later use.
|
||||
def initialize(expected : Array(ExpectedType))
|
||||
super
|
||||
end
|
||||
|
||||
# Common functionality for all match data for this matcher.
|
||||
private abstract struct CommonMatchData(ExpectedType, ActualType) < MatchData
|
||||
# Creates the match data.
|
||||
def initialize(matched, @values : ExpectedActual(ExpectedType, ActualType))
|
||||
def initialize(matched, @values : ExpectedActual(Array(ExpectedType), Array(ActualType)))
|
||||
super(matched)
|
||||
end
|
||||
|
||||
|
@ -47,7 +61,7 @@ module Spectator::Matchers
|
|||
# This type is used when the actual value matches the expected value.
|
||||
private struct IdenticalMatchData(ExpectedType, ActualType) < CommonMatchData(ExpectedType, ActualType)
|
||||
# Creates the match data.
|
||||
def initialize(values : ExpectedActual(ExpectedType, ActualType))
|
||||
def initialize(values : ExpectedActual(Array(ExpectedType), Array(ActualType)))
|
||||
super(true, values)
|
||||
end
|
||||
|
||||
|
@ -62,7 +76,7 @@ module Spectator::Matchers
|
|||
# This type is used when the actual size differs from the expected size.
|
||||
private struct SizeMatchData(ExpectedType, ActualType) < CommonMatchData(ExpectedType, ActualType)
|
||||
# Creates the match data.
|
||||
def initialize(values : ExpectedActual(ExpectedType, ActualType))
|
||||
def initialize(values : ExpectedActual(Array(ExpectedType), Array(ActualType)))
|
||||
super(false, values)
|
||||
end
|
||||
|
||||
|
@ -85,7 +99,7 @@ module Spectator::Matchers
|
|||
# This type is used when the actual contents differs from the expected contents.
|
||||
private struct ContentMatchData(ExpectedType, ActualType) < CommonMatchData(ExpectedType, ActualType)
|
||||
# Creates the match data.
|
||||
def initialize(@index : Int32, values : ExpectedActual(ExpectedType, ActualType))
|
||||
def initialize(@index : Int32, values : ExpectedActual(Array(ExpectedType), Array(ActualType)))
|
||||
super(false, values)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue