mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Merge branch 'master' into release/0.10
This commit is contained in:
commit
a3305a9273
3 changed files with 63 additions and 1 deletions
|
@ -274,7 +274,8 @@ This has been changed so that it compiles and raises an error at runtime with a
|
||||||
First version ready for public use.
|
First version ready for public use.
|
||||||
|
|
||||||
|
|
||||||
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.36...HEAD
|
[Unreleased]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.37...release%2F0.10
|
||||||
|
[0.9.36]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.36...v0.9.37
|
||||||
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.35...v0.9.36
|
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.35...v0.9.36
|
||||||
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...v0.9.35
|
[0.9.35]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.34...v0.9.35
|
||||||
[0.9.34]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.33...v0.9.34
|
[0.9.34]: https://gitlab.com/arctic-fox/spectator/-/compare/v0.9.33...v0.9.34
|
||||||
|
|
41
src/spectator/matchers/pattern_matcher.cr
Normal file
41
src/spectator/matchers/pattern_matcher.cr
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
require "./value_matcher"
|
||||||
|
|
||||||
|
module Spectator::Matchers
|
||||||
|
# Common matcher that tests whether a value matches another.
|
||||||
|
# The values are compared with the === operator.
|
||||||
|
# This is the same as `CaseMatcher`, but the operands are flipped.
|
||||||
|
struct PatternMatcher(ExpectedType) < ValueMatcher(ExpectedType)
|
||||||
|
# Short text about the matcher's purpose.
|
||||||
|
# This explains what condition satisfies the matcher.
|
||||||
|
# The description is used when the one-liner syntax is used.
|
||||||
|
def description : String
|
||||||
|
"matches #{expected.label}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Checks whether the matcher is satisifed with the expression given to it.
|
||||||
|
private def match?(actual : TestExpression(T)) : Bool forall T
|
||||||
|
actual.value === expected.value
|
||||||
|
end
|
||||||
|
|
||||||
|
# Message displayed when the matcher isn't satisifed.
|
||||||
|
#
|
||||||
|
# This is only called when `#match?` returns false.
|
||||||
|
#
|
||||||
|
# The message should typically only contain the test expression labels.
|
||||||
|
# Actual values should be returned by `#values`.
|
||||||
|
private def failure_message(actual) : String
|
||||||
|
"#{actual.label} does not match #{expected.label}"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Message displayed when the matcher isn't satisifed and is negated.
|
||||||
|
# This is essentially what would satisfy the matcher if it wasn't negated.
|
||||||
|
#
|
||||||
|
# This is only called when `#does_not_match?` returns false.
|
||||||
|
#
|
||||||
|
# The message should typically only contain the test expression labels.
|
||||||
|
# Actual values should be returned by `#values`.
|
||||||
|
private def failure_message_when_negated(actual) : String
|
||||||
|
"#{actual.label} matched #{expected.label}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -82,6 +82,26 @@ module Spectator::Matchers
|
||||||
InequalityMatcher.new(expected)
|
InequalityMatcher.new(expected)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Creates a matcher that checks if a value is semantically equal to an expected value.
|
||||||
|
# The spec would look like:
|
||||||
|
# ```
|
||||||
|
# expect("foobar").to be === /foo/
|
||||||
|
# ```
|
||||||
|
def ===(value)
|
||||||
|
expected = TestValue.new(value)
|
||||||
|
PatternMatcher.new(expected)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Creates a matcher that checks if a value matches the pattern of an expected value.
|
||||||
|
# The spec would look like:
|
||||||
|
# ```
|
||||||
|
# expect("foobar").to be =~ /foo/
|
||||||
|
# ```
|
||||||
|
def =~(value)
|
||||||
|
expected = TestValue.new(value)
|
||||||
|
PatternMatcher.new(expected)
|
||||||
|
end
|
||||||
|
|
||||||
# Checks whether the matcher is satisifed with the expression given to it.
|
# Checks whether the matcher is satisifed with the expression given to it.
|
||||||
private def match?(actual : Expression(T)) : Bool forall T
|
private def match?(actual : Expression(T)) : Bool forall T
|
||||||
@truthy == !!actual.value
|
@truthy == !!actual.value
|
||||||
|
|
Loading…
Reference in a new issue