From 950c57bae1a16c27cfbdc1ac197611e1a2e43d43 Mon Sep 17 00:00:00 2001 From: Sukera Date: Tue, 2 Jul 2024 09:46:40 +0200 Subject: [PATCH] Fix tests broken through the addition of new type parameter of `Composed` --- src/api.jl | 12 ++++++------ test/runtests.jl | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/api.jl b/src/api.jl index b07b651..1a230da 100644 --- a/src/api.jl +++ b/src/api.jl @@ -375,10 +375,10 @@ A `Possibility` composed from multiple different `Possibility` through Should not be instantiated manually; keep the object returned by `@composed` around instead. """ -struct Composed{S,P,T} <: Data.Possibility{T} +struct Composed{S,T,P} <: Data.Possibility{T} function Composed{S,P}() where {S,P} - prodtype = Base.promote_op(Data.produce!, TestCase, Composed{S,P}) - new{S, P, prodtype}() + prodtype = Base.promote_op(Data.produce!, TestCase, Composed{S,Any,P}) + new{S, prodtype, P}() end end @@ -386,7 +386,7 @@ function Base.show(io::IO, c::Composed{S}) where S print(io, "@composed ", S, "(...)") end -function Base.show(io::IO, ::MIME"text/plain", c::Composed{S,P,T}) where {S,P,T} +function Base.show(io::IO, ::MIME"text/plain", c::Composed{S,T,P}) where {S,P,T} obj = example(c) print(io, styled""" {code,underline:$Composed\{$S\}}: @@ -506,7 +506,7 @@ function composed_from_func(e::Expr) return esc(quote $structfunc - function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,$id}) + function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,T,$id}) where T $name($strategy_let...) end @@ -529,7 +529,7 @@ function composed_from_call(e::Expr) id = QuoteNode(gensym()) return esc(quote - function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,$id}) + function $Data.produce!($tc::$TestCase, ::$Composed{$prodname,T,$id}) where T $func($args...) end diff --git a/test/runtests.jl b/test/runtests.jl index eadbe26..2a62f77 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -35,6 +35,8 @@ const verb = VERSION.major == 1 && VERSION.minor < 11 @testset "Interfaces" begin possibility_subtypes = filter(!=(Supposition.Composed), subtypes(Data.Possibility)) @testset "Possibility" RI.check_implementations(Supposition.Data.Possibility, possibility_subtypes) + comp = @composed (i=Data.Integers(0,10),) -> i + @testset "Composed" RI.check_implementations(Supposition.Data.Possibility, (typeof(comp),)) @testset "ExampleDB" RI.check_implementations(Supposition.ExampleDB) end # Write your tests here. @@ -643,7 +645,7 @@ const verb = VERSION.major == 1 && VERSION.minor < 11 end @testset "Expected return types" begin - @test gen isa Supposition.Composed{:uint8tup, Tuple{UInt8,UInt8}} + @test gen isa Supposition.Composed{:uint8tup} @test Data.postype(gen) === Tuple{UInt8, UInt8} @test example(gen) isa Tuple{UInt8, UInt8} end @@ -685,7 +687,7 @@ const verb = VERSION.major == 1 && VERSION.minor < 11 @testset "Named anon" begin named = @composed named_anon(a=Data.Integers{Int8}(),b=preexisting) -> a isa Int8 && b isa Int8 - @test named isa Supposition.Composed{:named_anon, Bool} + @test named isa Supposition.Composed{:named_anon} @test Data.postype(named) === Bool @test example(named) isa Bool @test named_anon(Int8(1), Int8(2)) @@ -696,7 +698,7 @@ const verb = VERSION.major == 1 && VERSION.minor < 11 foo(a,b) = a+b preexisting = Data.Integers{Int8}() existing = @composed foo(Data.Integers{Int8}(), preexisting) - @test existing isa Supposition.Composed{:foo, Int8} + @test existing isa Supposition.Composed{:foo} @test Data.postype(existing) === Int8 @test example(existing) isa Int8 # can still call the existing function @@ -713,7 +715,7 @@ const verb = VERSION.major == 1 && VERSION.minor < 11 end @testset "Expected return types" begin - @test g2 isa Supposition.Composed{:stringcat, String} + @test g2 isa Supposition.Composed{:stringcat} @test Data.postype(g2) === String @test example(g2) isa String end