Define type annotations for match methods

Hopefully this speeds up some compilation.
This commit is contained in:
Michael Miller 2019-08-09 16:58:35 -06:00
parent a54e406fec
commit efd0ab089d
11 changed files with 22 additions and 22 deletions

View File

@ -16,7 +16,7 @@ module Spectator::Matchers
"contains exactly #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
actual_elements = actual.value.to_a
expected_elements = expected.value.to_a
index = compare_arrays(expected_elements, actual_elements)
@ -31,7 +31,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
actual_elements = actual.value.to_a
expected_elements = expected.value.to_a

View File

@ -19,7 +19,7 @@ module Spectator::Matchers
"has attributes #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new
@ -28,7 +28,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new("#{actual.label} has attributes #{expected.label}", **values(snapshot))

View File

@ -16,7 +16,7 @@ module Spectator::Matchers
"ends with #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
if (value = actual.value).responds_to?(:ends_with?)
match_ends_with(value, actual.label)
else
@ -50,7 +50,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
if actual.value.responds_to?(:ends_with?)
negated_match_ends_with(actual)
else

View File

@ -23,7 +23,7 @@ module Spectator::Matchers
end
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
exception = capture_exception { actual.value }
if exception.nil?
FailedMatchData.new("#{actual.label} did not raise", expected: ExceptionType.inspect)
@ -52,7 +52,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
exception = capture_exception { actual.value }
if exception.nil?
SuccessfulMatchData.new

View File

@ -16,7 +16,7 @@ module Spectator::Matchers
"has #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new
@ -25,7 +25,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new("#{actual.label} has #{expected.label}", **values(snapshot))

View File

@ -14,8 +14,8 @@ module Spectator::Matchers
# The phrasing should be such that it reads "it ___."
abstract def description : String
abstract def match(actual) : MatchData
abstract def match(actual : TestExpression(T)) : MatchData forall T
abstract def negated_match(actual) : MatchData
abstract def negated_match(actual : TestExpression(T)) : MatchData forall T
end
end

View File

@ -15,7 +15,7 @@ module Spectator::Matchers
"is #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new
@ -24,7 +24,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new("#{actual.label} is #{expected.label}", **values(snapshot))

View File

@ -15,7 +15,7 @@ module Spectator::Matchers
{{ExpectedType.keys.map { |e| "##{e}".id }.splat.stringify}}
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
SuccessfulMatchData.new
@ -24,7 +24,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
FailedMatchData.new("#{actual.label} responds to #{label}", **snapshot)

View File

@ -40,7 +40,7 @@ module Spectator::Matchers
values(actual)
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
if match?(actual)
SuccessfulMatchData.new
else
@ -48,7 +48,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
if does_not_match?(actual)
SuccessfulMatchData.new
else

View File

@ -14,7 +14,7 @@ module Spectator::Matchers
"starts with #{expected.label}"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
if (value = actual.value).responds_to?(:starts_with?)
match_starts_with(value, actual.label)
else
@ -48,7 +48,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
if (value = actual.value).responds_to?(:starts_with?)
negated_match_starts_with(value, actual.label)
else

View File

@ -13,7 +13,7 @@ module Spectator::Matchers
"contains #{expected.label} in any order"
end
def match(actual)
def match(actual : TestExpression(T)) : MatchData forall T
actual_elements = actual.value.to_a
expected_elements = expected.value.to_a
missing, extra = array_diff(expected_elements, actual_elements)
@ -30,7 +30,7 @@ module Spectator::Matchers
end
end
def negated_match(actual)
def negated_match(actual : TestExpression(T)) : MatchData forall T
actual_elements = actual.value.to_a
expected_elements = expected.value.to_a
missing, extra = array_diff(expected_elements, actual_elements)