mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Hide special character mapping
This commit is contained in:
parent
625a331745
commit
10fc6c6a35
2 changed files with 36 additions and 36 deletions
|
@ -2,5 +2,38 @@ module Spectator
|
||||||
module ContextDefinitions
|
module ContextDefinitions
|
||||||
ALL = {} of Path => Object
|
ALL = {} of Path => Object
|
||||||
MAPPING = {} of String => Context
|
MAPPING = {} of String => Context
|
||||||
|
|
||||||
|
SPECIAL_CHARS = {
|
||||||
|
'~' => "Tilde",
|
||||||
|
'`' => "Tick",
|
||||||
|
'!' => "Bang",
|
||||||
|
'@' => "At",
|
||||||
|
'#' => "Hash",
|
||||||
|
'$' => "Dollar",
|
||||||
|
'%' => "Percent",
|
||||||
|
'^' => "Carret",
|
||||||
|
'&' => "And",
|
||||||
|
'*' => "Star",
|
||||||
|
'(' => "LParen",
|
||||||
|
')' => "RParen",
|
||||||
|
'+' => "Plus",
|
||||||
|
'=' => "Eq",
|
||||||
|
'{' => "LBrace",
|
||||||
|
'}' => "RBrace",
|
||||||
|
'[' => "LBracket",
|
||||||
|
']' => "RBracket",
|
||||||
|
':' => "Colon",
|
||||||
|
';' => "SColon",
|
||||||
|
'<' => "Lt",
|
||||||
|
'>' => "Gt",
|
||||||
|
',' => "Comma",
|
||||||
|
'.' => "Dot",
|
||||||
|
'?' => "Question",
|
||||||
|
'/' => "Slash",
|
||||||
|
'"' => "DQuote",
|
||||||
|
'|' => "Or",
|
||||||
|
'\\' => "BSlash",
|
||||||
|
'\'' => "SQuote"
|
||||||
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -3,46 +3,13 @@ require "./example_group"
|
||||||
module Spectator
|
module Spectator
|
||||||
module DSL
|
module DSL
|
||||||
|
|
||||||
SPECIAL_CHAR_MAPPING = {
|
|
||||||
'~' => "Tilde",
|
|
||||||
'`' => "Tick",
|
|
||||||
'!' => "Bang",
|
|
||||||
'@' => "At",
|
|
||||||
'#' => "Hash",
|
|
||||||
'$' => "Dollar",
|
|
||||||
'%' => "Percent",
|
|
||||||
'^' => "Carret",
|
|
||||||
'&' => "And",
|
|
||||||
'*' => "Star",
|
|
||||||
'(' => "LParen",
|
|
||||||
')' => "RParen",
|
|
||||||
'+' => "Plus",
|
|
||||||
'=' => "Eq",
|
|
||||||
'{' => "LBrace",
|
|
||||||
'}' => "RBrace",
|
|
||||||
'[' => "LBracket",
|
|
||||||
']' => "RBracket",
|
|
||||||
':' => "Colon",
|
|
||||||
';' => "SColon",
|
|
||||||
'<' => "Lt",
|
|
||||||
'>' => "Gt",
|
|
||||||
',' => "Comma",
|
|
||||||
'.' => "Dot",
|
|
||||||
'?' => "Question",
|
|
||||||
'/' => "Slash",
|
|
||||||
'"' => "DQuote",
|
|
||||||
'|' => "Or",
|
|
||||||
'\\' => "BSlash",
|
|
||||||
'\'' => "SQuote"
|
|
||||||
}
|
|
||||||
|
|
||||||
macro describe(what, type = "Describe", &block)
|
macro describe(what, type = "Describe", &block)
|
||||||
context({{what}}, {{type}}) {{block}}
|
context({{what}}, {{type}}) {{block}}
|
||||||
end
|
end
|
||||||
|
|
||||||
macro context(what, type = "Context", &block)
|
macro context(what, type = "Context", &block)
|
||||||
{% parent_module = @type %}
|
{% parent_module = @type %}
|
||||||
{% safe_name = what.id.stringify.chars.map { |c| SPECIAL_CHAR_MAPPING[c] || c }.join("").gsub(/\W+/, "_") %}
|
{% safe_name = what.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_") %}
|
||||||
{% module_name = (type.id + safe_name.camelcase).id %}
|
{% module_name = (type.id + safe_name.camelcase).id %}
|
||||||
{% absolute_module_name = [parent_module, module_name].join("::").id %}
|
{% absolute_module_name = [parent_module, module_name].join("::").id %}
|
||||||
{% what_arg = what.is_a?(StringLiteral) ? what : what.stringify %}
|
{% what_arg = what.is_a?(StringLiteral) ? what : what.stringify %}
|
||||||
|
@ -163,7 +130,7 @@ module Spectator
|
||||||
|
|
||||||
macro it(description, &block)
|
macro it(description, &block)
|
||||||
{% parent_module = @type %}
|
{% parent_module = @type %}
|
||||||
{% safe_name = description.id.stringify.chars.map { |c| SPECIAL_CHAR_MAPPING[c] || c }.join("").gsub(/\W+/, "_") %}
|
{% safe_name = description.id.stringify.chars.map { |c| ::Spectator::ContextDefinitions::SPECIAL_CHARS[c] || c }.join("").gsub(/\W+/, "_") %}
|
||||||
{% class_name = (safe_name.camelcase + "Example").id %}
|
{% class_name = (safe_name.camelcase + "Example").id %}
|
||||||
{% given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given] %}
|
{% given_vars = ::Spectator::ContextDefinitions::ALL[parent_module.id][:given] %}
|
||||||
{% var_names = given_vars.map { |v| v[:name] } %}
|
{% var_names = given_vars.map { |v| v[:name] } %}
|
||||||
|
@ -178,7 +145,7 @@ module Spectator
|
||||||
|
|
||||||
class {{class_name.id}} < ::Spectator::Example
|
class {{class_name.id}} < ::Spectator::Example
|
||||||
include Locals
|
include Locals
|
||||||
|
|
||||||
{% if given_vars.empty? %}
|
{% if given_vars.empty? %}
|
||||||
def initialize(context)
|
def initialize(context)
|
||||||
super(context)
|
super(context)
|
||||||
|
|
Loading…
Reference in a new issue