[Haskell-cafe] SmallCheck and parser testing
Paul Johnson
paul at cogito.org.uk
Tue Apr 3 13:38:36 EDT 2007
On Tue, 3 Apr 2007 16:01:56 +0100
Joel Reymont <joelr1 at gmail.com> 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.
More information about the Haskell-Cafe
mailing list