Fix bug when printing constrained compositions
This commit is contained in:
parent
1f277d9e30
commit
79cc802a70
|
@ -31,8 +31,10 @@ module Dry
|
|||
end
|
||||
|
||||
def self.included(base)
|
||||
ast_type = Inflector.underscore(Inflector.demodulize(base)).to_sym
|
||||
composition_name = Inflector.demodulize(base)
|
||||
ast_type = Inflector.underscore(composition_name).to_sym
|
||||
base.define_singleton_method(:ast_type) { ast_type }
|
||||
base.define_singleton_method(:composition_name) { composition_name }
|
||||
base.const_set("Constrained", Class.new(base) { include Constrained })
|
||||
end
|
||||
|
||||
|
|
|
@ -43,13 +43,12 @@ module Dry
|
|||
def initialize(printer, composition_class)
|
||||
@printer = printer
|
||||
@composition_class = composition_class
|
||||
@composition_name = Inflector.demodulize(composition_class)
|
||||
end
|
||||
|
||||
def visit(composition)
|
||||
visit_constructors(composition) do |constructors|
|
||||
printer.visit_options(composition.options, composition.meta) do |opts|
|
||||
yield "#{composition_name}<#{constructors}#{opts}>"
|
||||
yield "#{@composition_class.composition_name}<#{constructors}#{opts}>"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -174,6 +174,18 @@ RSpec.describe Dry::Types::Implication do
|
|||
end
|
||||
end
|
||||
|
||||
context "constrained" do
|
||||
let(:type) { t::Nominal::String.constrained(format: /foo/) > t::Nominal::String.constrained(min_size: 4) }
|
||||
|
||||
it "returns string representation of the type" do
|
||||
expect(type.to_s).to eql(
|
||||
"#<Dry::Types[Implication<" \
|
||||
"Constrained<Nominal<String> rule=[format?(/foo/)]> > "\
|
||||
"Constrained<Nominal<String> rule=[min_size?(4)]>>]>"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "implication tree" do
|
||||
let(:type) { t::Nominal::String > (t::Nominal::Integer > (t::Nominal::Date > t::Nominal::Time)) }
|
||||
|
||||
|
|
|
@ -189,6 +189,18 @@ RSpec.describe Dry::Types::Intersection do
|
|||
end
|
||||
end
|
||||
|
||||
context "constrained" do
|
||||
let(:type) { t::Nominal::String.constrained(format: /foo/) & t::Nominal::String.constrained(min_size: 4) }
|
||||
|
||||
it "returns string representation of the type" do
|
||||
expect(type.to_s).to eql(
|
||||
"#<Dry::Types[Intersection<" \
|
||||
"Constrained<Nominal<String> rule=[format?(/foo/)]> & "\
|
||||
"Constrained<Nominal<String> rule=[min_size?(4)]>>]>"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "intersection tree" do
|
||||
let(:type) { t::Nominal::String & t::Nominal::Integer & t::Nominal::Date & t::Nominal::Time }
|
||||
|
||||
|
|
|
@ -257,6 +257,21 @@ RSpec.describe Dry::Types::Sum do
|
|||
end
|
||||
end
|
||||
|
||||
context "constrained" do
|
||||
let(:type) do
|
||||
Dry::Types["nominal.string"].constrained(format: /foo/) |
|
||||
Dry::Types["nominal.string"].constrained(min_size: 4)
|
||||
end
|
||||
|
||||
it "returns string representation of the type" do
|
||||
expect(type.to_s).to eql(
|
||||
"#<Dry::Types[Sum<" \
|
||||
"Constrained<Nominal<String> rule=[format?(/foo/)]> | "\
|
||||
"Constrained<Nominal<String> rule=[min_size?(4)]>>]>"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "sum tree" do
|
||||
let(:type) do
|
||||
Dry::Types["nominal.string"] | Dry::Types["nominal.integer"] |
|
||||
|
|
Loading…
Reference in New Issue