mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
New stub syntax to support operator methods
Works like: stub :[], index : Int32 { 42 } Addresses https://github.com/icy-arctic-fox/spectator/issues/14
This commit is contained in:
parent
93fa6f6e72
commit
9ac6121201
2 changed files with 32 additions and 2 deletions
|
@ -7,7 +7,7 @@ module Spectator::Mocks
|
|||
def initialize(@spectator_double_name : String, @null = false)
|
||||
end
|
||||
|
||||
private macro stub(definition, &block)
|
||||
private macro stub(definition, *types, &block)
|
||||
{%
|
||||
name = nil
|
||||
params = nil
|
||||
|
@ -44,6 +44,21 @@ module Spectator::Mocks
|
|||
params = [] of MacroId
|
||||
args = [] of MacroId
|
||||
body = block
|
||||
elsif definition.is_a?(SymbolLiteral) # stub :foo, arg : Int32
|
||||
name = definition.id
|
||||
named = false
|
||||
params = types
|
||||
if params.last.is_a?(Call)
|
||||
body = params.last.block
|
||||
params[-1] = params.last.name
|
||||
end
|
||||
args = params.map do |p|
|
||||
n = p.is_a?(TypeDeclaration) ? p.var : p.id
|
||||
r = named ? "#{n}: #{n}".id : n
|
||||
named = true if n.starts_with?('*')
|
||||
r
|
||||
end
|
||||
body = block unless body
|
||||
else
|
||||
raise "Unrecognized stub format"
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
module Spectator::Mocks
|
||||
module Stubs
|
||||
private macro stub(definition, _file = __FILE__, _line = __LINE__, &block)
|
||||
private macro stub(definition, *types, _file = __FILE__, _line = __LINE__, &block)
|
||||
{%
|
||||
receiver = nil
|
||||
name = nil
|
||||
|
@ -30,6 +30,21 @@ module Spectator::Mocks
|
|||
params = [] of MacroId
|
||||
args = [] of MacroId
|
||||
body = block
|
||||
elsif definition.is_a?(SymbolLiteral) # stub :foo, arg : Int32
|
||||
name = definition.id
|
||||
named = false
|
||||
params = types
|
||||
if params.last.is_a?(Call)
|
||||
body = params.last.block
|
||||
params[-1] = params.last.name
|
||||
end
|
||||
args = params.map do |p|
|
||||
n = p.is_a?(TypeDeclaration) ? p.var : p.id
|
||||
r = named ? "#{n}: #{n}".id : n
|
||||
named = true if n.starts_with?('*')
|
||||
r
|
||||
end
|
||||
body = block unless body
|
||||
else
|
||||
raise "Unrecognized stub format"
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue