mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Move ValueWrapper and TypedValueWrapper to Internals
Trying to hide from top-level some inner-workings.
This commit is contained in:
parent
887a04a92a
commit
cddfe5591d
11 changed files with 46 additions and 36 deletions
|
@ -58,7 +58,7 @@ module Spectator
|
|||
end
|
||||
|
||||
protected def build : ExampleGroup
|
||||
root_group.build(nil, {} of Symbol => ValueWrapper)
|
||||
root_group.build(nil, {} of Symbol => Internals::ValueWrapper)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module Spectator
|
|||
def initialize(@example_type : Example.class)
|
||||
end
|
||||
|
||||
def build(group : ExampleGroup, locals : Hash(Symbol, ValueWrapper)) : Example
|
||||
def build(group : ExampleGroup, locals : Hash(Symbol, Internals::ValueWrapper)) : Example
|
||||
@example_type.new(group, locals)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,7 +37,7 @@ module Spectator
|
|||
@around_each_hooks << block
|
||||
end
|
||||
|
||||
def build(parent : ExampleGroup?, locals : Hash(Symbol, ValueWrapper)) : ExampleGroup
|
||||
def build(parent : ExampleGroup?, locals : Hash(Symbol, Internals::ValueWrapper)) : ExampleGroup
|
||||
ExampleGroup.new(@what, parent, build_hooks).tap do |group|
|
||||
children = @children.map do |child|
|
||||
child.build(group, locals).as(ExampleGroup::Child)
|
||||
|
|
|
@ -4,11 +4,11 @@ module Spectator
|
|||
module DSL
|
||||
class GivenExampleGroupBuilder < ExampleGroupBuilder
|
||||
|
||||
def initialize(what : String, @collection : Array(ValueWrapper), @symbol : Symbol)
|
||||
def initialize(what : String, @collection : Array(Internals::ValueWrapper), @symbol : Symbol)
|
||||
super(what)
|
||||
end
|
||||
|
||||
def build(parent : ExampleGroup?, locals : Hash(Symbol, ValueWrapper)) : ExampleGroup
|
||||
def build(parent : ExampleGroup?, locals : Hash(Symbol, Internals::ValueWrapper)) : ExampleGroup
|
||||
ExampleGroup.new(@what, parent, build_hooks).tap do |group|
|
||||
children = [] of ExampleGroup::Child
|
||||
@collection.each do |value|
|
||||
|
|
|
@ -4,7 +4,7 @@ module Spectator
|
|||
module DSL
|
||||
module StructureDSL
|
||||
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper))
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper))
|
||||
end
|
||||
|
||||
macro describe(what, &block)
|
||||
|
@ -37,13 +37,13 @@ module Spectator
|
|||
{{collection}}
|
||||
end
|
||||
|
||||
@%wrapper : ::Spectator::ValueWrapper
|
||||
@%wrapper : ::Spectator::Internals::ValueWrapper
|
||||
|
||||
def {{block.args.empty? ? "value".id : block.args.first}}
|
||||
@%wrapper.as(::Spectator::TypedValueWrapper(typeof(%collection.first))).value
|
||||
@%wrapper.as(::Spectator::Internals::TypedValueWrapper(typeof(%collection.first))).value
|
||||
end
|
||||
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper))
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper))
|
||||
super
|
||||
@%wrapper = locals[:%group]
|
||||
end
|
||||
|
@ -70,14 +70,14 @@ module Spectator
|
|||
macro let(name, &block)
|
||||
let!(%value) {{block}}
|
||||
|
||||
@%wrapper : ::Spectator::ValueWrapper?
|
||||
@%wrapper : ::Spectator::Internals::ValueWrapper?
|
||||
|
||||
def {{name.id}}
|
||||
if (wrapper = @%wrapper)
|
||||
wrapper.unsafe_as(::Spectator::TypedValueWrapper(typeof(%value))).value
|
||||
wrapper.unsafe_as(::Spectator::Internals::TypedValueWrapper(typeof(%value))).value
|
||||
else
|
||||
%value.tap do |value|
|
||||
@%wrapper = ::Spectator::TypedValueWrapper(typeof(%value)).new(value)
|
||||
@%wrapper = ::Spectator::Internals::TypedValueWrapper(typeof(%value)).new(value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -159,9 +159,9 @@ module Spectator
|
|||
include {{@type.id}}
|
||||
|
||||
def {{to_a_method_name.id}}
|
||||
Array(::Spectator::ValueWrapper).new.tap do |array|
|
||||
Array(::Spectator::Internals::ValueWrapper).new.tap do |array|
|
||||
{{collection_method_name.id}}.each do |item|
|
||||
array << ::Spectator::TypedValueWrapper(typeof(item)).new(item)
|
||||
array << ::Spectator::Internals::TypedValueWrapper(typeof(item)).new(item)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -173,7 +173,7 @@ module Spectator
|
|||
include ::Spectator::DSL::ExampleDSL
|
||||
include {{@type.id}}
|
||||
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::ValueWrapper))
|
||||
def initialize(locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper))
|
||||
super
|
||||
end
|
||||
|
||||
|
@ -185,7 +185,7 @@ module Spectator
|
|||
|
||||
private macro _spectator_example(example_class_name, wrapper_class_name, base_class, description, &block)
|
||||
class {{example_class_name.id}} < {{base_class.id}}
|
||||
def initialize(group : ::Spectator::ExampleGroup, locals : Hash(Symbol, ::Spectator::ValueWrapper))
|
||||
def initialize(group : ::Spectator::ExampleGroup, locals : Hash(Symbol, ::Spectator::Internals::ValueWrapper))
|
||||
super
|
||||
@instance = {{wrapper_class_name.id}}.new(locals)
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@ module Spectator
|
|||
abstract def run : Result
|
||||
abstract def description : String
|
||||
|
||||
def initialize(@group, @locals = {} of Symbol => ValueWrapper)
|
||||
def initialize(@group, @locals = {} of Symbol => Internals::ValueWrapper)
|
||||
end
|
||||
|
||||
private getter locals
|
||||
|
|
6
src/spectator/internals.cr
Normal file
6
src/spectator/internals.cr
Normal file
|
@ -0,0 +1,6 @@
|
|||
require "./internals/*"
|
||||
|
||||
module Spectator
|
||||
module Internals
|
||||
end
|
||||
end
|
12
src/spectator/internals/typed_value_wrapper.cr
Normal file
12
src/spectator/internals/typed_value_wrapper.cr
Normal file
|
@ -0,0 +1,12 @@
|
|||
require "./value_wrapper"
|
||||
|
||||
module Spectator
|
||||
module Internals
|
||||
class TypedValueWrapper(T) < ValueWrapper
|
||||
getter value : T
|
||||
|
||||
def initialize(@value : T)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
11
src/spectator/internals/value_wrapper.cr
Normal file
11
src/spectator/internals/value_wrapper.cr
Normal file
|
@ -0,0 +1,11 @@
|
|||
module Spectator
|
||||
module Internals
|
||||
# Base class for proxying test values to examples.
|
||||
# This abstraction is required for inferring types.
|
||||
# The `DSL#let` macro makes heavy use of this.
|
||||
abstract class ValueWrapper
|
||||
# Retrieves the underlying value.
|
||||
abstract def value
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
require "./value_wrapper"
|
||||
|
||||
module Spectator
|
||||
class TypedValueWrapper(T) < ValueWrapper
|
||||
getter value : T
|
||||
|
||||
def initialize(@value : T)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,9 +0,0 @@
|
|||
module Spectator
|
||||
# Base class for proxying test values to examples.
|
||||
# This abstraction is required for inferring types.
|
||||
# The `DSL#let` macro makes heavy use of this.
|
||||
abstract class ValueWrapper
|
||||
# Retrieves the underlying value.
|
||||
abstract def value
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue