mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Support case equality of tuples, arrays, named tuples, and hashes in stub argument matching
This commit is contained in:
parent
b5fbc96195
commit
556d4783bf
1 changed files with 15 additions and 3 deletions
|
@ -7,7 +7,7 @@ module Spectator
|
|||
end
|
||||
|
||||
# Utility method for comparing two tuples considering special types.
|
||||
private def compare_tuples(a : Tuple, b : Tuple)
|
||||
private def compare_tuples(a : Tuple | Array, b : Tuple | Array)
|
||||
return false if a.size != b.size
|
||||
|
||||
a.zip(b) do |a_value, b_value|
|
||||
|
@ -18,14 +18,14 @@ module Spectator
|
|||
|
||||
# Utility method for comparing two tuples considering special types.
|
||||
# Supports nilable tuples (ideal for splats).
|
||||
private def compare_tuples(a : Tuple?, b : Tuple?)
|
||||
private def compare_tuples(a : Tuple? | Array?, b : Tuple? | Array?)
|
||||
return false if a.nil? ^ b.nil?
|
||||
|
||||
compare_tuples(a.not_nil!, b.not_nil!)
|
||||
end
|
||||
|
||||
# Utility method for comparing two named tuples ignoring order.
|
||||
private def compare_named_tuples(a : NamedTuple, b : NamedTuple)
|
||||
private def compare_named_tuples(a : NamedTuple | Hash, b : NamedTuple | Hash)
|
||||
a.each do |k, v1|
|
||||
v2 = b.fetch(k) { return false }
|
||||
return false unless compare_values(v1, v2)
|
||||
|
@ -50,6 +50,18 @@ module Spectator
|
|||
else
|
||||
a == b
|
||||
end
|
||||
when Tuple, Array
|
||||
if b.is_a?(Tuple) || b.is_a?(Array)
|
||||
compare_tuples(a, b)
|
||||
else
|
||||
a === b
|
||||
end
|
||||
when NamedTuple, Hash
|
||||
if b.is_a?(NamedTuple) || b.is_a?(Hash)
|
||||
compare_named_tuples(a, b)
|
||||
else
|
||||
a === b
|
||||
end
|
||||
else
|
||||
a === b
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue