mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
More refatoring
This commit is contained in:
parent
a1b5533504
commit
9ba3fc898b
8 changed files with 31 additions and 70 deletions
|
@ -4,10 +4,8 @@ require "./spectator/*"
|
|||
module Spectator
|
||||
VERSION = "0.1.0"
|
||||
|
||||
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
||||
module SpectatorExamples
|
||||
::Spectator::DSL::StructureDSL.describe({{what}}) {{block}}
|
||||
end
|
||||
macro describe(what, &block)
|
||||
DSL.root({{what}}) {{block}}
|
||||
end
|
||||
|
||||
at_exit do
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
module Spectator
|
||||
module Definitions
|
||||
ALL = {} of Path => Object
|
||||
GROUPS = {} of Symbol => ExampleGroup
|
||||
|
||||
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
|
|
@ -2,5 +2,12 @@ require "./dsl/*"
|
|||
|
||||
module Spectator
|
||||
module DSL
|
||||
macro root(what, &block)
|
||||
module SpectatorExamples
|
||||
include StructureDSL
|
||||
|
||||
describe({{what}}) {{block}}
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
7
src/spectator/dsl/abstract_example_factory.cr
Normal file
7
src/spectator/dsl/abstract_example_factory.cr
Normal file
|
@ -0,0 +1,7 @@
|
|||
module Spectator
|
||||
module DSL
|
||||
abstract class AbstractExampleFactory
|
||||
abstract def build(locals : Hash(Symbol, ValueWrapper)) : Example
|
||||
end
|
||||
end
|
||||
end
|
|
@ -26,7 +26,7 @@ module Spectator
|
|||
@group_stack.pop
|
||||
end
|
||||
|
||||
def add_example(factory : ExampleFactory) : Nil
|
||||
def add_example(factory : AbstractExampleFactory) : Nil
|
||||
current_group.add_child(factory)
|
||||
end
|
||||
|
||||
|
|
11
src/spectator/dsl/example_factory.cr
Normal file
11
src/spectator/dsl/example_factory.cr
Normal file
|
@ -0,0 +1,11 @@
|
|||
require "./abstract_example_factory"
|
||||
|
||||
module Spectator
|
||||
module DSL
|
||||
class ExampleFactory(T) < AbstractExampleFactory
|
||||
def build(locals : Hash(Symbol, ValueWrapper)) : Example
|
||||
T.new(locals)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -165,13 +165,9 @@ module Spectator
|
|||
end
|
||||
end
|
||||
|
||||
class Factory%example < ::Spectator::ExampleFactory
|
||||
def build(locals : Hash(Symbol, ValueWrapper))
|
||||
Example%example.new(locals)
|
||||
end
|
||||
end
|
||||
|
||||
::Spectator::Definitions::GROUPS[\{{@type.symbolize}}].children << Factory%example.new
|
||||
::Spectator::DSL::Builder.add_example_factory(
|
||||
::Spectator::DSL::ExampleFactory(Example%example).new
|
||||
)
|
||||
end
|
||||
|
||||
macro pending(description, &block)
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
require "./dsl"
|
||||
require "./definitions"
|
||||
|
||||
module Spectator
|
||||
module Examples
|
||||
include ::Spectator::DSL::StructureDSL
|
||||
|
||||
{% ::Spectator::Definitions::ALL[@type.id] = {
|
||||
name: "ROOT",
|
||||
parent: nil,
|
||||
given: [] of Object,
|
||||
children: [] of Object
|
||||
} %}
|
||||
::Spectator::Definitions::GROUPS[{{@type.symbolize}}] = ::Spectator::ExampleGroup::ROOT
|
||||
|
||||
def initialize(locals = {} of Symbol => ValueWrapper)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue