on master help sign in
Get tests compiling again
8895172Evan Czaplicki
tests/compiler/Tests/Property.hs+18−17
@@ -11,6 +11,7 @@ import Text.PrettyPrint as P
11
11
12import AST.Literal as Lit
12import AST.Literal as Lit
13import qualified AST.Pattern as P
13import qualified AST.Pattern as P
14+import qualified AST.Variable as V
14import AST.PrettyPrint (Pretty, pretty)
15import AST.PrettyPrint (Pretty, pretty)
15import Parse.Helpers (IParser, iParse)
16import Parse.Helpers (IParser, iParse)
16import Parse.Literal (literal)
17import Parse.Literal (literal)
@@ -21,8 +22,7 @@ import Tests.Property.Arbitrary
21propertyTests :: Test
22propertyTests :: Test
22propertyTests =
23propertyTests =
23 testGroup "Parse/Print Agreement Tests"
24 testGroup "Parse/Print Agreement Tests"
24− [
25− testCase "Long Pattern test" $ assert (prop_parse_print Pat.expr longPat)
25+ [ testCase "Long Pattern test" $ assert (prop_parse_print Pat.expr longPat)
26 , testProperty "Literal test" $ prop_parse_print literal
26 , testProperty "Literal test" $ prop_parse_print literal
27 , testProperty "Pattern test" $ prop_parse_print Pat.expr
27 , testProperty "Pattern test" $ prop_parse_print Pat.expr
28 , testProperty "Type test" $ prop_parse_print Type.expr
28 , testProperty "Type test" $ prop_parse_print Type.expr
@@ -31,21 +31,22 @@ propertyTests =
31 where
31 where
32 -- This test was autogenerated from the Pattern test and should be
32 -- This test was autogenerated from the Pattern test and should be
33 -- left in all its ugly glory.
33 -- left in all its ugly glory.
34+ longPat = P.Data (V.Raw "I")
34− longPat = P.Data "I" [ P.Literal (Lit.Chr '+')
35+ [ P.Literal (Lit.Chr '+')
35− , P.Record
36+ , P.Record
36− [ "q7yclkcm7k_ikstrczv_"
37+ [ "q7yclkcm7k_ikstrczv_"
37− , "wQRv6gKsvvkjw4b5F"
38+ , "wQRv6gKsvvkjw4b5F"
38− ,"c9'eFfhk9FTvsMnwF_D"
39+ ,"c9'eFfhk9FTvsMnwF_D"
39− ,"yqxhEkHvRFwZ"
40+ ,"yqxhEkHvRFwZ"
40− ,"o"
41+ ,"o"
41− ,"nbUlCn3y3NnkVoxhW"
42+ ,"nbUlCn3y3NnkVoxhW"
42− ,"iJ0MNy3KZ_lrs"
43+ ,"iJ0MNy3KZ_lrs"
43− ,"ug"
44+ ,"ug"
44− ,"sHHsX"
45+ ,"sHHsX"
45− ,"mRKs9d"
46+ ,"mRKs9d"
46− ,"o2KiCX5'ZRzHJfRi8" ]
47+ ,"o2KiCX5'ZRzHJfRi8" ]
47− , P.Var "su'BrrbPUK6I33Eq"
48+ , P.Var "su'BrrbPUK6I33Eq"
48− ]
49+ ]
49
50
50prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
51prop_parse_print :: (Pretty a, Arbitrary a, Eq a) => IParser a -> a -> Bool
51prop_parse_print p x =
52prop_parse_print p x =
tests/compiler/Tests/Property/Arbitrary.hs+14−9
@@ -11,6 +11,11 @@ import qualified Parse.Helpers (reserveds)
11import qualified AST.Literal as L
11import qualified AST.Literal as L
12import qualified AST.Pattern as P
12import qualified AST.Pattern as P
13import qualified AST.Type as T
13import qualified AST.Type as T
14+import qualified AST.Variable as V
15+
16+instance Arbitrary V.Raw where
17+ arbitrary = V.Raw <$> arbitrary
18+ shrink (V.Raw v) = V.Raw <$> shrink v
14
19
15instance Arbitrary L.Literal where
20instance Arbitrary L.Literal where
16 arbitrary =
21 arbitrary =
@@ -41,10 +46,10 @@ genVector n generator = do
41 let m = n `div` (len + 1)
46 let m = n `div` (len + 1)
42 vectorOf len $ generator m
47 vectorOf len $ generator m
43
48
44−instance Arbitrary P.Pattern where
49+instance Arbitrary v => Arbitrary (P.Pattern v) where
45 arbitrary = sized pat
50 arbitrary = sized pat
46 where
51 where
47− pat :: Int -> Gen P.Pattern
52+ pat :: (Arbitrary v) => Int -> Gen (P.Pattern v)
48 pat n =
53 pat n =
49 oneof
54 oneof
50 [ pure P.Anything
55 [ pure P.Anything
@@ -52,7 +57,7 @@ instance Arbitrary P.Pattern where
52 , P.Record <$> (listOf1 lowVar)
57 , P.Record <$> (listOf1 lowVar)
53 , P.Literal <$> arbitrary
58 , P.Literal <$> arbitrary
54 , P.Alias <$> lowVar <*> pat (n-1)
59 , P.Alias <$> lowVar <*> pat (n-1)
55− , P.Data <$> capVar <*> genVector n pat
60+ , P.Data <$> arbitrary <*> genVector n pat
56 ]
61 ]
57
62
58 shrink pat =
63 shrink pat =
@@ -61,7 +66,7 @@ instance Arbitrary P.Pattern where
61 P.Var v -> P.Var <$> shrinkWHead v
66 P.Var v -> P.Var <$> shrinkWHead v
62 P.Literal l -> P.Literal <$> shrink l
67 P.Literal l -> P.Literal <$> shrink l
63 P.Alias s p -> p : (P.Alias <$> shrinkWHead s <*> shrink p)
68 P.Alias s p -> p : (P.Alias <$> shrinkWHead s <*> shrink p)
64− P.Data s ps -> ps ++ (P.Data <$> shrinkWHead s <*> shrink ps)
69+ P.Data s ps -> ps ++ (P.Data <$> shrink s <*> shrink ps)
65 P.Record fs ->
70 P.Record fs ->
66 P.Record <$> filter (all notNull) (filter notNull (shrink fs))
71 P.Record <$> filter (all notNull) (filter notNull (shrink fs))
67 where
72 where
@@ -71,10 +76,10 @@ shrinkWHead :: Arbitrary a => [a] -> [[a]]
71shrinkWHead [] = error "Should be nonempty"
76shrinkWHead [] = error "Should be nonempty"
72shrinkWHead (x:xs) = (x:) <$> shrink xs
77shrinkWHead (x:xs) = (x:) <$> shrink xs
73
78
74−instance Arbitrary T.Type where
79+instance Arbitrary v => Arbitrary (T.Type v) where
75 arbitrary = sized tipe
80 arbitrary = sized tipe
76 where
81 where
77− tipe :: Int -> Gen T.Type
82+ tipe :: Arbitrary v => Int -> Gen (T.Type v)
78 tipe n =
83 tipe n =
79 let depthTipe = tipe =<< choose (0,n)
84 let depthTipe = tipe =<< choose (0,n)
80 field = (,) <$> lowVar <*> depthTipe
85 field = (,) <$> lowVar <*> depthTipe
@@ -84,16 +89,16 @@ instance Arbitrary T.Type where
84 oneof
89 oneof
85 [ T.Lambda <$> depthTipe <*> depthTipe
90 [ T.Lambda <$> depthTipe <*> depthTipe
86 , T.Var <$> lowVar
91 , T.Var <$> lowVar
87− , T.Data <$> capVar <*> genVector n tipe
92+ , T.Data <$> arbitrary <*> genVector n tipe
88 , T.Record <$> fields <*> pure Nothing
93 , T.Record <$> fields <*> pure Nothing
89− , T.Record <$> fields1 <*> (Just <$> lowVar)
94+ , T.Record <$> fields1 <*> (Just . T.Var <$> lowVar)
90 ]
95 ]
91
96
92 shrink tipe =
97 shrink tipe =
93 case tipe of
98 case tipe of
94 T.Lambda s t -> s : t : (T.Lambda <$> shrink s <*> shrink t)
99 T.Lambda s t -> s : t : (T.Lambda <$> shrink s <*> shrink t)
95 T.Var _ -> []
100 T.Var _ -> []
96− T.Data n ts -> ts ++ (T.Data <$> shrinkWHead n <*> shrink ts)
101+ T.Data n ts -> ts ++ (T.Data <$> shrink n <*> shrink ts)
97 T.Record fs t -> map snd fs ++ record
102 T.Record fs t -> map snd fs ++ record
98 where
103 where
99 record =
104 record =