Skip to content

Commit

Permalink
cover parsing code
Browse files Browse the repository at this point in the history
  • Loading branch information
olynch committed Jul 3, 2024
1 parent faf38c6 commit 813b064
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion test/util/SumTypes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ using MLStyle
using GATlab.Util.SumTypes
using Test

# Unit tests of parsing

@test SumTypes.fromexpr(:(x<:Int), SumTypes.TypeArg) isa SumTypes.TypeArg
@test_throws ErrorException SumTypes.fromexpr(:(x::Int), SumTypes.TypeArg)

@test SumTypes.toexpr(SumTypes.fromexpr(:(x<:Int), SumTypes.TypeArg)) == :(x<:Int)

@test SumTypes.toexpr(SumTypes.fromexpr(:(X{Y}), SumTypes.BaseType)) == :(X{Y})
@test_throws ErrorException SumTypes.fromexpr(:(1+1), SumTypes.BaseType)

@test SumTypes.fromexpr(:(x::Int), SumTypes.Field) isa SumTypes.Field
@test_throws ErrorException SumTypes.fromexpr(:(1+1), SumTypes.Field)

@test SumTypes.fromexpr(:(V(x::Int)), SumTypes.Variant, :T) isa SumTypes.Variant
@test_throws ErrorException SumTypes.fromexpr(:(V{}), SumTypes.Variant, :T)

# Integration tests

@sum AlgebraExpr{T} begin
Const(x::T)
Sum(summands::Vector{Self})
Expand All @@ -20,7 +38,7 @@ expr_type = sprint(show, AlgebraExpr)
"$sum_type($expr_type{Int64}[$const_type(3)::$expr_type{Int64}])::$expr_type{Int64}"

@sum MonoidExpr begin
Zero()
Zero
Plus(t1::Self, t2::Self)
end

Expand Down

0 comments on commit 813b064

Please sign in to comment.