on c19392f help sign in
elk/tests/Test/Property.hs
68 lines 2.1 kB history raw
1module Test.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 Reporting.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 Test.Property.Arbitrary
23propertyTests :: Test
24propertyTests =
25 testGroup "Parse/Print Agreement Tests"
26 [ testCase "Long Pattern test" $ assert (prop_parse_print Pat.expr longPat)
27 , testProperty "Literal test" $ prop_parse_print literal
28 , testProperty "Pattern test" $ prop_parse_print Pat.expr
29 , testProperty "Type test" $ prop_parse_print Type.expr
30 ]
32 where
33 -- This test was autogenerated from the Pattern test and should be
34 -- left in all its ugly glory.
35 longPat = P.Data (V.Raw "I")
36 [ P.Literal (Lit.Chr '+')
37 , P.Record
38 [ "q7yclkcm7k_ikstrczv_"
39 , "wQRv6gKsvvkjw4b5F"
40 ,"c9'eFfhk9FTvsMnwF_D"
41 ,"yqxhEkHvRFwZ"
42 ,"o"
43 ,"nbUlCn3y3NnkVoxhW"
44 ,"iJ0MNy3KZ_lrs"
45 ,"ug"
46 ,"sHHsX"
47 ,"mRKs9d"
48 ,"o2KiCX5'ZRzHJfRi8" ]
49 , P.Var "su'BrrbPUK6I33Eq"
50 ]
53prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
54prop_parse_print parser value =
55 either (const False) (== value) (parse_print parser value)
58parse_print :: (Pretty a) => IParser a -> a -> Either String a
59parse_print parser value =
60 let doc =
61 pretty value
63 string =
64 P.renderStyle P.style { mode = P.LeftMode } doc
65 in
66 case iParse (parser <* eof) string of
67 Left msg -> Left (show msg)
68 Right x -> Right x