mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Handle deferred stub with type
This commit is contained in:
parent
49764e5873
commit
1bbe5067b6
1 changed files with 21 additions and 9 deletions
|
@ -1,18 +1,30 @@
|
|||
module Spectator
|
||||
abstract class Double
|
||||
macro stub(definition, &block)
|
||||
delegate {{definition.name.id}}, to: @internal
|
||||
{%
|
||||
name = nil
|
||||
args = nil
|
||||
body = nil
|
||||
if definition.is_a?(Call) # stub foo { :bar }
|
||||
name = definition.name.id
|
||||
args = definition.args
|
||||
body = definition.block.is_a?(Nop) ? block : definition.block
|
||||
elsif definition.is_a?(TypeDeclaration) # stub foo : Symbol
|
||||
name = definition.var
|
||||
args = [] of MacroId
|
||||
body = block
|
||||
else
|
||||
raise "Unrecognized stub format"
|
||||
end
|
||||
%}
|
||||
delegate {{name}}, to: @internal
|
||||
|
||||
private class Internal
|
||||
def {{definition.name.id}}({{definition.args.splat}})
|
||||
{% if definition.block.is_a?(Nop) %}
|
||||
{% if block.is_a?(Nop) %}
|
||||
raise "Stubbed method called without being allowed"
|
||||
{% else %}
|
||||
{{block.body}}
|
||||
{% end %}
|
||||
def {{name}}({{args.splat}})
|
||||
{% if body && !body.is_a?(Nop) %}
|
||||
{{body.body}}
|
||||
{% else %}
|
||||
{{definition.block.body}}
|
||||
raise "Stubbed method called without being allowed"
|
||||
{% end %}
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue