Allow matchers to be used in case equality

This commit is contained in:
Michael Miller 2024-01-27 11:17:19 -07:00
parent 5520999b6d
commit b5fbc96195
No known key found for this signature in database
GPG Key ID: 32B47AE8F388A1FF
1 changed files with 14 additions and 0 deletions

View File

@ -1,3 +1,4 @@
require "../value"
require "./match_data"
module Spectator::Matchers
@ -22,6 +23,19 @@ module Spectator::Matchers
# A successful match with `#match` should normally fail for this method, and vice-versa.
abstract def negated_match(actual : Expression(T)) : MatchData forall T
# Compares a matcher against a value.
# Enables composable matchers.
def ===(actual : Expression(T)) : Bool
match(actual).matched?
end
# Compares a matcher against a value.
# Enables composable matchers.
def ===(other) : Bool
expression = Value.new(other)
match(expression).matched?
end
private def match_data_description(actual : Expression(T)) : String forall T
match_data_description(actual.label)
end