On Tue, 3 Apr 2007 16:01:56 +0100
Joel Reymont <[EMAIL PROTECTED]> wrote:
Folks,

I'm trying to figure out how to test a Parsec-based parser with Smallcheck [1]. My test AST is below and the goal is to return StyleValue <Int here> if the parser is fed an integer, or return Solid when parsing "Solid", etc.
data Style
     = StyleValue Expr
     | Solid
     | Dashed
     | Dotted
     | Dashed2
     | Dashed3
     deriving Show
I'd use QuickCheck rather than SmallCheck. First write Arbitrary instances for Style and Expr (plus obviously any other types used by Expr). Then write another generator that converts a Style to a string with random formatting (whitespace, comments etc). Then assert that the parse of the generated string is equal to the original value.

You might also want to write another string generator that also inserts random syntax errors, so you can test for the correct detection of syntax errors.

Paul.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to