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

briand at aracnet.com briand at aracnet.com
Sat Jun 11 20:16:39 CEST 2011

On Sat, 11 Jun 2011 10:34:47 -0700
Alexander Solla <alex.solla at gmail.com> wrote:

> 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.

Wouldn't also be reasonable for the test cases to be generated from the grammar automagically ?  Seems much more useful than attempting to do it by hand.  Seems like something which would have already been done, i.e. there's already a tool out there that does that ?


More information about the Haskell-Cafe mailing list