Add names for most common special characters

These names will be used instead of an underscore. This helps with
naming.
This commit is contained in:
Michael Miller 2018-09-11 15:09:23 -06:00
parent 95ec999bba
commit 284e10482a

View file

@ -2,12 +2,46 @@ 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)
{% safe_name = what.id.stringify.gsub(/\W+/, "_") %} {% safe_name = what.id.stringify.chars.map { |c| SPECIAL_CHAR_MAPPING[c] || c }.join("").gsub(/\W+/, "_") %}
{% module_name = (type.id + safe_name.camelcase).id %} {% module_name = (type.id + safe_name.camelcase).id %}
{% context_module = CONTEXT_MODULE %} {% context_module = CONTEXT_MODULE %}
{% parent_given_vars = GIVEN_VARIABLES %} {% parent_given_vars = GIVEN_VARIABLES %}
@ -37,7 +71,7 @@ module Spectator
end end
macro it(description, &block) macro it(description, &block)
{% safe_name = description.id.stringify.gsub(/\W+/, "_") %} {% safe_name = description.id.stringify.chars.map { |c| SPECIAL_CHAR_MAPPING[c] || c }.join("").gsub(/\W+/, "_") %}
{% class_name = (safe_name.camelcase + "Example").id %} {% class_name = (safe_name.camelcase + "Example").id %}
{% given_vars = GIVEN_VARIABLES %} {% given_vars = GIVEN_VARIABLES %}
{% var_names = given_vars.map { |v| v[0] } %} {% var_names = given_vars.map { |v| v[0] } %}