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}"
|
"contains exactly #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
actual_elements = actual.value.to_a
|
actual_elements = actual.value.to_a
|
||||||
expected_elements = expected.value.to_a
|
expected_elements = expected.value.to_a
|
||||||
index = compare_arrays(expected_elements, actual_elements)
|
index = compare_arrays(expected_elements, actual_elements)
|
||||||
|
@ -31,7 +31,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
actual_elements = actual.value.to_a
|
actual_elements = actual.value.to_a
|
||||||
expected_elements = expected.value.to_a
|
expected_elements = expected.value.to_a
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ module Spectator::Matchers
|
||||||
"has attributes #{expected.label}"
|
"has attributes #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
|
@ -28,7 +28,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
FailedMatchData.new("#{actual.label} has attributes #{expected.label}", **values(snapshot))
|
FailedMatchData.new("#{actual.label} has attributes #{expected.label}", **values(snapshot))
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Spectator::Matchers
|
||||||
"ends with #{expected.label}"
|
"ends with #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:ends_with?)
|
if (value = actual.value).responds_to?(:ends_with?)
|
||||||
match_ends_with(value, actual.label)
|
match_ends_with(value, actual.label)
|
||||||
else
|
else
|
||||||
|
@ -50,7 +50,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if actual.value.responds_to?(:ends_with?)
|
if actual.value.responds_to?(:ends_with?)
|
||||||
negated_match_ends_with(actual)
|
negated_match_ends_with(actual)
|
||||||
else
|
else
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
exception = capture_exception { actual.value }
|
exception = capture_exception { actual.value }
|
||||||
if exception.nil?
|
if exception.nil?
|
||||||
FailedMatchData.new("#{actual.label} did not raise", expected: ExceptionType.inspect)
|
FailedMatchData.new("#{actual.label} did not raise", expected: ExceptionType.inspect)
|
||||||
|
@ -52,7 +52,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
exception = capture_exception { actual.value }
|
exception = capture_exception { actual.value }
|
||||||
if exception.nil?
|
if exception.nil?
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Spectator::Matchers
|
||||||
"has #{expected.label}"
|
"has #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
|
@ -25,7 +25,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
FailedMatchData.new("#{actual.label} has #{expected.label}", **values(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 ___."
|
# The phrasing should be such that it reads "it ___."
|
||||||
abstract def description : String
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Spectator::Matchers
|
||||||
"is #{expected.label}"
|
"is #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
|
@ -24,7 +24,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
FailedMatchData.new("#{actual.label} is #{expected.label}", **values(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}}
|
{{ExpectedType.keys.map { |e| "##{e}".id }.splat.stringify}}
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
|
@ -24,7 +24,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
snapshot = snapshot_values(actual.value)
|
snapshot = snapshot_values(actual.value)
|
||||||
if match?(snapshot)
|
if match?(snapshot)
|
||||||
FailedMatchData.new("#{actual.label} responds to #{label}", **snapshot)
|
FailedMatchData.new("#{actual.label} responds to #{label}", **snapshot)
|
||||||
|
|
|
@ -40,7 +40,7 @@ module Spectator::Matchers
|
||||||
values(actual)
|
values(actual)
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if match?(actual)
|
if match?(actual)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
else
|
else
|
||||||
|
@ -48,7 +48,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if does_not_match?(actual)
|
if does_not_match?(actual)
|
||||||
SuccessfulMatchData.new
|
SuccessfulMatchData.new
|
||||||
else
|
else
|
||||||
|
|
|
@ -14,7 +14,7 @@ module Spectator::Matchers
|
||||||
"starts with #{expected.label}"
|
"starts with #{expected.label}"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:starts_with?)
|
if (value = actual.value).responds_to?(:starts_with?)
|
||||||
match_starts_with(value, actual.label)
|
match_starts_with(value, actual.label)
|
||||||
else
|
else
|
||||||
|
@ -48,7 +48,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
if (value = actual.value).responds_to?(:starts_with?)
|
if (value = actual.value).responds_to?(:starts_with?)
|
||||||
negated_match_starts_with(value, actual.label)
|
negated_match_starts_with(value, actual.label)
|
||||||
else
|
else
|
||||||
|
|
|
@ -13,7 +13,7 @@ module Spectator::Matchers
|
||||||
"contains #{expected.label} in any order"
|
"contains #{expected.label} in any order"
|
||||||
end
|
end
|
||||||
|
|
||||||
def match(actual)
|
def match(actual : TestExpression(T)) : MatchData forall T
|
||||||
actual_elements = actual.value.to_a
|
actual_elements = actual.value.to_a
|
||||||
expected_elements = expected.value.to_a
|
expected_elements = expected.value.to_a
|
||||||
missing, extra = array_diff(expected_elements, actual_elements)
|
missing, extra = array_diff(expected_elements, actual_elements)
|
||||||
|
@ -30,7 +30,7 @@ module Spectator::Matchers
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def negated_match(actual)
|
def negated_match(actual : TestExpression(T)) : MatchData forall T
|
||||||
actual_elements = actual.value.to_a
|
actual_elements = actual.value.to_a
|
||||||
expected_elements = expected.value.to_a
|
expected_elements = expected.value.to_a
|
||||||
missing, extra = array_diff(expected_elements, actual_elements)
|
missing, extra = array_diff(expected_elements, actual_elements)
|
||||||
|
|
Loading…
Reference in a new issue