Skip to content

Commit

Permalink
Fix tests broken through the addition of new type parameter of `Compo…
Browse files Browse the repository at this point in the history
…sed`
  • Loading branch information
Seelengrab committed Jul 2, 2024
1 parent 57edcfb commit 950c57b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/api.jl
Original file line number Diff line number Diff line change
Expand Up @@ -375,18 +375,18 @@ 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

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\}}:
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
10 changes: 6 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 950c57b

Please sign in to comment.