Use symbols instead of strings for hash lookups

This commit is contained in:
Michael Miller 2018-09-19 21:06:10 -06:00
parent a28f512ae4
commit 0f7640411f
3 changed files with 12 additions and 12 deletions

View file

@ -1,7 +1,7 @@
module Spectator module Spectator
module Definitions module Definitions
ALL = {} of Path => Object ALL = {} of Path => Object
GROUPS = {} of String => ExampleGroup GROUPS = {} of Symbol => ExampleGroup
SPECIAL_CHARS = { SPECIAL_CHARS = {
'~' => "Tilde", '~' => "Tilde",

View file

@ -12,10 +12,10 @@ module Spectator
module {{type.id}}%context module {{type.id}}%context
include {{@type.id}} include {{@type.id}}
::Spectator::Definitions::GROUPS[\{{@type.stringify}}] = ::Spectator::Definitions::GROUPS[\{{@type.symbolize}}] =
ExampleGroup.new( ExampleGroup.new(
{{what.is_a?(StringLiteral) ? what : what.stringify}}, {{what.is_a?(StringLiteral) ? what : what.stringify}},
::Spectator::Definitions::GROUPS[{{@type.stringify}}] ::Spectator::Definitions::GROUPS[{{@type.symbolize}}]
) )
{% if what.is_a?(Path) || what.is_a?(Generic) %} {% if what.is_a?(Path) || what.is_a?(Generic) %}
@ -39,11 +39,11 @@ module Spectator
end end
%collection = Collection%collection.new.%to_a %collection = Collection%collection.new.%to_a
::Spectator::Definitions::GROUPS[\{{@type.stringify}}] = ::Spectator::Definitions::GROUPS[\{{@type.symbolize}}] =
GivenExampleGroup(typeof(%collection.first)).new( GivenExampleGroup(typeof(%collection.first)).new(
{{collection.stringify}}, {{collection.stringify}},
%collection, %collection,
::Spectator::Definitions::GROUPS[{{@type.stringify}}] ::Spectator::Definitions::GROUPS[{{@type.symbolize}}]
) )
{{block.body}} {{block.body}}
@ -99,23 +99,23 @@ module Spectator
end end
macro before_all(&block) macro before_all(&block)
::Spectator::Definitions::GROUPS[{{@type.stringify}}].before_all_hooks << -> {{block}} ::Spectator::Definitions::GROUPS[{{@type.symbolize}}].before_all_hooks << -> {{block}}
end end
macro before_each(&block) macro before_each(&block)
::Spectator::Definitions::GROUPS[{{@type.stringify}}].before_each_hooks << -> {{block}} ::Spectator::Definitions::GROUPS[{{@type.symbolize}}].before_each_hooks << -> {{block}}
end end
macro after_all(&block) macro after_all(&block)
::Spectator::Definitions::GROUPS[{{@type.stringify}}].after_all_hooks << -> {{block}} ::Spectator::Definitions::GROUPS[{{@type.symbolize}}].after_all_hooks << -> {{block}}
end end
macro after_each(&block) macro after_each(&block)
::Spectator::Definitions::GROUPS[{{@type.stringify}}].after_each_hooks << -> {{block}} ::Spectator::Definitions::GROUPS[{{@type.symbolize}}].after_each_hooks << -> {{block}}
end end
macro around_each(&block) macro around_each(&block)
::Spectator::Definitions::GROUPS[{{@type.stringify}}].around_each_hooks << Proc(Proc(Nil), Nil).new {{block}} ::Spectator::Definitions::GROUPS[{{@type.symbolize}}].around_each_hooks << Proc(Proc(Nil), Nil).new {{block}}
end end
def include_examples def include_examples
@ -142,7 +142,7 @@ module Spectator
end end
end end
%group = ::Spectator::Definitions::GROUPS[{{@type.stringify}}] %group = ::Spectator::Definitions::GROUPS[\{{@type.symbolize}}]
%group.children << Example%example.new(%group) %group.children << Example%example.new(%group)
end end

View file

@ -11,6 +11,6 @@ module Spectator
given: [] of Object, given: [] of Object,
children: [] of Object children: [] of Object
} %} } %}
::Spectator::Definitions::GROUPS[{{@type.stringify}}] = ::Spectator::ExampleGroup::ROOT ::Spectator::Definitions::GROUPS[{{@type.symbolize}}] = ::Spectator::ExampleGroup::ROOT
end end
end end