mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Add basic range matcher
This commit is contained in:
parent
154832e5c4
commit
bc45a3bf41
1 changed files with 27 additions and 0 deletions
27
src/spectator/matchers/range_matcher.cr
Normal file
27
src/spectator/matchers/range_matcher.cr
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
require "./value_matcher"
|
||||||
|
|
||||||
|
module Spectator::Matchers
|
||||||
|
# Matcher that tests whether a value is in a given range or set of values.
|
||||||
|
# The `#includes?` method is used for this check.
|
||||||
|
# Typically this matcher uses a `Range`,
|
||||||
|
# but any type that implements the `#includes?` method is supported.
|
||||||
|
struct RangeMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||||
|
# Determines whether the matcher is satisfied with the value given to it.
|
||||||
|
# True is returned if the match was successful, false otherwise.
|
||||||
|
def match?(partial : Expectations::ValueExpectationPartial(ActualType)) : Bool forall ActualType
|
||||||
|
@expected.includes?(partial.actual)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Describes the condition that satisfies the matcher.
|
||||||
|
# This is informational and displayed to the end-user.
|
||||||
|
def message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType
|
||||||
|
"Expected #{partial.label} to be in #{label}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Describes the condition that won't satsify the matcher.
|
||||||
|
# This is informational and displayed to the end-user.
|
||||||
|
def negated_message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType
|
||||||
|
"Expected #{partial.label} to not be in #{label}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue