[Haskell-cafe] SmallCheck and parser testing

Joel Reymont joelr1 at gmail.com
Tue Apr 3 11:01:56 EDT 2007


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 figure that the following is needed somehow:

instance Serial Style where
     series = cons1 StyleValue . depth 0
              \/ cons0 Solid
              \/ cons0 Dashed
              \/ cons0 Dashed2
              \/ cons0 Dashed3
              \/ cons0 Dotted

My parser is 'style', so I would be passing it as p below

run p input =
     case (parse p "" input) of
       Left err -> do { putStr "parse error at "
                      ; print err
       Right x -> x

How do I go from here to making sure my parser is valid?

I thought of the following property (thanks sjanssen)

prop_parse p s =
     show (run p s) == s

but I don't know how to proceed from here.

	Thanks, Joel

[1] http://www.cs.york.ac.uk/fp/darcs/smallcheck/


More information about the Haskell-Cafe mailing list