Skip to content

Commit

Permalink
add a test for the unreachable clause reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
exaexa committed Aug 17, 2023
1 parent 1b67ead commit 856f7d3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/clauses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,27 @@ end
@test_throws DomainError P.flatten(rules, Char)
end

@testset "Unreachable rules are reported" begin
rules = Dict(:xxx => P.seq(:yyy, P.fail), :yyy => P.epsilon, :zzz => P.epsilon)

@test_throws ErrorException P.make_grammar([:xxx], P.flatten(rules, Char))
@test begin
# this should simply not throw anything
P.make_grammar([:xxx, :zzz], P.flatten(rules, Char))
true
end

@test try
P.make_grammar([:xxx], P.flatten(rules, Char))
catch e
b = IOBuffer()
showerror(b, e)
errorstring = String(take!(b))

(occursin(":zzz", errorstring) && all(!occursin(errorstring), [":xxx", ":yyy"]))
end
end

@testset "Corner-case epsilon matches" begin
str = "whateveρ"

Expand Down

0 comments on commit 856f7d3

Please sign in to comment.