[Haskell-cafe] How do you test a parser?

Alexander Solla alex.solla at gmail.com
Sat Jun 11 19:34:47 CEST 2011

On Sat, Jun 11, 2011 at 10:06 AM, Sean Perry <shaleh at speakeasy.net> wrote:

> Choices, choices.
> The first one is to use unit tests. Look at the grammar and make sure the
> obvious stuff fails or succeeds. "a + b", "a :+ b", etc. You can do this at
> the Haskell level with parser objects.
> Next you can write small samples to test things the unit tests did not.
> Compare the output to known results. There are numerous examples of this in
> the open source world you can either reuse or crib from.

Don't just test the "obvious" things.   If the parse tree is truly a tree,
it is an initial algebra and amenable to case analysis as an initial
algebra.  In other words, you can do a proof by induction, just by checking
all the base cases.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20110611/cc2bd1ff/attachment.htm>

More information about the Haskell-Cafe mailing list