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
|
module Spectator
|
||||||
VERSION = "0.1.0"
|
VERSION = "0.1.0"
|
||||||
|
|
||||||
macro describe(what, source_file = __FILE__, source_line = __LINE__, &block)
|
macro describe(what, &block)
|
||||||
module SpectatorExamples
|
DSL.root({{what}}) {{block}}
|
||||||
::Spectator::DSL::StructureDSL.describe({{what}}) {{block}}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
at_exit do
|
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 Spectator
|
||||||
module DSL
|
module DSL
|
||||||
|
macro root(what, &block)
|
||||||
|
module SpectatorExamples
|
||||||
|
include StructureDSL
|
||||||
|
|
||||||
|
describe({{what}}) {{block}}
|
||||||
|
end
|
||||||
|
end
|
||||||
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
|
@group_stack.pop
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_example(factory : ExampleFactory) : Nil
|
def add_example(factory : AbstractExampleFactory) : Nil
|
||||||
current_group.add_child(factory)
|
current_group.add_child(factory)
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
class Factory%example < ::Spectator::ExampleFactory
|
::Spectator::DSL::Builder.add_example_factory(
|
||||||
def build(locals : Hash(Symbol, ValueWrapper))
|
::Spectator::DSL::ExampleFactory(Example%example).new
|
||||||
Example%example.new(locals)
|
)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
::Spectator::Definitions::GROUPS[\{{@type.symbolize}}].children << Factory%example.new
|
|
||||||
end
|
end
|
||||||
|
|
||||||
macro pending(description, &block)
|
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…
Add table
Add a link
Reference in a new issue