mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Remove setter and extra code for given vars
This commit is contained in:
parent
e30da2be19
commit
fbea3533ea
1 changed files with 25 additions and 40 deletions
|
@ -57,26 +57,15 @@ module Spectator
|
||||||
end
|
end
|
||||||
%}
|
%}
|
||||||
|
|
||||||
@%wrapper : ValueWrapper?
|
def self.%collection
|
||||||
|
|
||||||
private def %collection
|
|
||||||
{{collection}}
|
{{collection}}
|
||||||
end
|
end
|
||||||
|
|
||||||
private def %collection_first
|
def self.{{var_name}}
|
||||||
%collection.first
|
%collection.first
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{var_name.id}}
|
\{% ::Spectator::ContextDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, type_def: (@type.id + ".{{var_name}}").id} %}
|
||||||
@%wrapper.as(TypedValueWrapper(typeof(%collection_first))).value
|
|
||||||
end
|
|
||||||
|
|
||||||
{% setter = "_set_#{var_name.id}".id %}
|
|
||||||
private def {{setter}}(value)
|
|
||||||
@%wrapper = TypedValueWrapper(typeof(%collection_first)).new(value)
|
|
||||||
end
|
|
||||||
|
|
||||||
\{% ::Spectator::ContextDefinitions::ALL[@type.id][:given] << {name: "{{var_name}}".id, collection: "{{collection}}".id, setter: "{{setter}}".id} %}
|
|
||||||
|
|
||||||
{{block.body}}
|
{{block.body}}
|
||||||
end
|
end
|
||||||
|
@ -151,23 +140,23 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
class {{class_name.id}} < ::Spectator::Example
|
class {{class_name.id}} < ::Spectator::Example
|
||||||
include {{parent_module}}
|
{% for given_var, i in given_vars %}
|
||||||
|
@%var{i} : ValueWrapper
|
||||||
|
|
||||||
{% if given_vars.empty? %}
|
private def %var{i}
|
||||||
def initialize(context)
|
@%var{i}.unsafe_as(TypedValueWrapper(typeof({{given_var[:type_def]}}))).value
|
||||||
super(context)
|
|
||||||
end
|
|
||||||
{% else %}
|
|
||||||
def initialize(context{% for v, i in var_names %}, %var{i}{% end %})
|
|
||||||
super(context)
|
|
||||||
{% for given_var, i in given_vars %}
|
|
||||||
{{given_var[:setter]}}(%var{i})
|
|
||||||
{% end %}
|
|
||||||
end
|
end
|
||||||
{% end %}
|
{% end %}
|
||||||
|
|
||||||
|
def initialize(context{% for v, i in var_names %}, %var{i}{% end %})
|
||||||
|
super(context)
|
||||||
|
{% for given_var, i in given_vars %}
|
||||||
|
@%var{i} = TypedValueWrapper(typeof({{given_var[:type_def]}})).new(%var{i})
|
||||||
|
{% end %}
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
Example%example.new.%run({{ var_names.join(", ").id }})
|
Example%example.new.%run({% for v, i in var_names %}%var{i}{% if i < var_names.size - 1 %}, {% end %}{% end %})
|
||||||
end
|
end
|
||||||
|
|
||||||
def description
|
def description
|
||||||
|
@ -180,20 +169,16 @@ module Spectator
|
||||||
end
|
end
|
||||||
|
|
||||||
%current_context = ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]
|
%current_context = ::Spectator::ContextDefinitions::MAPPING[{{parent_module.stringify}}]
|
||||||
{% if given_vars.empty? %}
|
{% for given_var, i in given_vars %}
|
||||||
%current_context.examples << {{class_name.id}}.new(%current_context)
|
{%
|
||||||
{% else %}
|
var_name = given_var[:name]
|
||||||
{% for given_var, i in given_vars %}
|
collection = given_var[:collection]
|
||||||
{%
|
%}
|
||||||
var_name = given_var[:name]
|
{{collection}}.each do |%var{i}|
|
||||||
collection = given_var[:collection]
|
{% end %}
|
||||||
%}
|
%current_context.examples << {{class_name.id}}.new(%current_context {% for v, i in var_names %}, %var{i}{% end %})
|
||||||
{{collection}}.each do |%var{i}|
|
{% for given_var in given_vars %}
|
||||||
{% end %}
|
end
|
||||||
%current_context.examples << {{class_name.id}}.new(%current_context {% for v, i in var_names %}, %var{i}{% end %})
|
|
||||||
{% for given_var in given_vars %}
|
|
||||||
end
|
|
||||||
{% end %}
|
|
||||||
{% end %}
|
{% end %}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue