on 577fc17 help sign in
elk/tests/compiler/Tests/Property.hs
56 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)
10import Text.PrettyPrint as P
12import AST.Literal as Lit
13import qualified AST.Pattern as P
14import qualified AST.Variable as V
15import AST.PrettyPrint (Pretty, pretty)
16import Parse.Helpers (IParser, iParse)
17import Parse.Literal (literal)
18import qualified Parse.Pattern as Pat (expr)
19import qualified Parse.Type as Type (expr)
20import Tests.Property.Arbitrary
22propertyTests :: Test
23propertyTests =
24 testGroup "Parse/Print Agreement Tests"
25 [ testCase "Long Pattern test" $ assert (prop_parse_print Pat.expr longPat)
26 , testProperty "Literal test" $ prop_parse_print literal
27 , testProperty "Pattern test" $ prop_parse_print Pat.expr
28 , testProperty "Type test" $ prop_parse_print Type.expr
29 ]
31 where
32 -- This test was autogenerated from the Pattern test and should be
33 -- left in all its ugly glory.
34 longPat = P.Data (V.Raw "I")
35 [ P.Literal (Lit.Chr '+')
36 , P.Record
37 [ "q7yclkcm7k_ikstrczv_"
38 , "wQRv6gKsvvkjw4b5F"
39 ,"c9'eFfhk9FTvsMnwF_D"
40 ,"yqxhEkHvRFwZ"
41 ,"o"
42 ,"nbUlCn3y3NnkVoxhW"
43 ,"iJ0MNy3KZ_lrs"
44 ,"ug"
45 ,"sHHsX"
46 ,"mRKs9d"
47 ,"o2KiCX5'ZRzHJfRi8" ]
48 , P.Var "su'BrrbPUK6I33Eq"
49 ]
51prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
52prop_parse_print p x =
53 either (const False) (== x) . parse_print p $ x
55parse_print :: (Pretty a) => IParser a -> a -> Either String a
56parse_print p = either (Left . show) Right . iParse (p <* eof) . P.renderStyle P.style {mode=P.LeftMode} . pretty