From 856f7d3d3ab9d32ca2a920ae394d24cf4136e588 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 17 Aug 2023 09:25:57 +0200 Subject: [PATCH] add a test for the unreachable clause reporting --- test/clauses.jl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/clauses.jl b/test/clauses.jl index 79f1c3e..e60fb14 100644 --- a/test/clauses.jl +++ b/test/clauses.jl @@ -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ρ"