mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Define type annotations for match methods
Hopefully this speeds up some compilation.
This commit is contained in:
parent
a54e406fec
commit
efd0ab089d
11 changed files with 22 additions and 22 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue