on 63243ca help sign in
elk/tests/Tests/Property.hs
51 lines 1.9 kB history raw
1module Tests.Property where
3import Control.Applicative ((<*))
4import Test.Framework
5import Test.Framework.Providers.HUnit
6import Test.Framework.Providers.QuickCheck2
7import Test.HUnit (assert)
8import Test.QuickCheck
9import Text.Parsec.Combinator (eof)
11import SourceSyntax.Literal as Lit
12import SourceSyntax.Pattern as Pat
13import SourceSyntax.PrettyPrint (Pretty, pretty)
14import Parse.Helpers (IParser, iParse)
15import Parse.Literal (literal)
16import Parse.Pattern (expr)
17import Tests.Property.Arbitrary
19propertyTests :: Test
20propertyTests =
21 testGroup "Parse/Print Agreement Tests"
22 [
23 testCase "Long Pattern test" $ assert (prop_parse_print expr longPat)
24 , testProperty "Literal test" $ prop_parse_print literal
25 , testProperty "Pattern test" $ prop_parse_print expr
26 ]
28 where
29 -- This test was autogenerated from the Pattern test and should be
30 -- left in all its ugly glory.
31 longPat = Pat.PData "I" [ Pat.PLiteral (Lit.Chr '+')
32 , Pat.PRecord [
33 "q7yclkcm7k_ikstrczv_"
34 , "wQRv6gKsvvkjw4b5F"
35 ,"c9'eFfhk9FTvsMnwF_D"
36 ,"yqxhEkHvRFwZ"
37 ,"o"
38 ,"nbUlCn3y3NnkVoxhW"
39 ,"iJ0MNy3KZ_lrs"
40 ,"ug"
41 ,"sHHsX"
42 ,"mRKs9d"
43 ,"o2KiCX5'ZRzHJfRi8" ]
44 , Pat.PVar "su'BrrbPUK6I33Eq" ]
46prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
47prop_parse_print p x =
48 either (const False) (== x) . parse_print p $ x
50parse_print :: (Pretty a) => IParser a -> a -> Either String a
51parse_print p = either (Left . show) (Right) . iParse (p <* eof) . show . pretty