Type annotations for #match?

This commit is contained in:
Michael Miller 2019-08-10 10:55:22 -06:00
parent c4b886cad2
commit 898ddcb616
20 changed files with 20 additions and 20 deletions

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the === operator.
struct CaseMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value === actual.value
end

View file

@ -6,7 +6,7 @@ module Spectator::Matchers
# Matcher for checking that a value is in a collection of other values.
struct CollectionMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value.includes?(actual.value)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are checked with the `includes?` method.
struct ContainMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value.all? do |item|
actual.value.includes?(item)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are checked with the `empty?` method.
struct EmptyMatcher < StandardMatcher
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value.empty?
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the == operator.
struct EqualityMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value == actual.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the >= operator.
struct GreaterThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value >= expected.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the > operator.
struct GreaterThanMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value > expected.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The set is checked with the `has_key?` method.
struct HaveKeyMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value.has_key?(expected.value)
end

View file

@ -6,7 +6,7 @@ module Spectator::Matchers
# Otherwise, it expects an `Enumerable` and iterates over each item until === is true.
struct HaveMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
if (value = actual.value).is_a?(String)
match_string?(value)
else

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The set is checked with the `has_value?` method.
struct HaveValueMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value.has_value?(expected.value)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the != operator.
struct InequalityMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value != actual.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the <= operator.
struct LessThanEqualMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value <= expected.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the < operator.
struct LessThanMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value < expected.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The `Object#nil?` method is used for this.
struct NilMatcher < StandardMatcher
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value.nil?
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The `Range#includes?` method is used for this check.
struct RangeMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value.includes?(actual.value)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the `Reference#same?` method.
struct ReferenceMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value.same?(actual.value)
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The set's `#size` method is used for this check.
struct SizeMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value == actual.value.size
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The set's `#size` method is used for this check.
struct SizeOfMatcher(ExpectedType) < ValueMatcher(ExpectedType)
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
expected.value.size == actual.value.size
end

View file

@ -26,7 +26,7 @@ module Spectator::Matchers
end
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
@truthy == !!actual.value
end

View file

@ -5,7 +5,7 @@ module Spectator::Matchers
# The values are compared with the `Object#is_a?` method.
struct TypeMatcher(Expected) < StandardMatcher
# Checks whether the matcher is satisifed with the expression given to it.
private def match?(actual)
private def match?(actual : TestExpression(T)) forall T
actual.value.is_a?(Expected)
end