on master help sign in
Make arbitrary instances more restrictive
commit34b72a273fd5f251b052a7f57bb7f18837c27936 authorEvan Czaplicki <info@elm-lang.org> dateTue 10 Jun 2014, 13:37 (12 years ago) parent8bd16fd
1 file changed+5−4
tests/compiler/Tests/Property/Arbitrary.hs+5−4
tests/compiler/Tests/Property/Arbitrary.hs+5−4
@@ -14,7 +14,7 @@ import qualified AST.Type as T
1414import qualified AST.Variable as V
1515
1616instance Arbitrary V.Raw where
17− arbitrary = V.Raw <$> arbitrary
17+ arbitrary = V.Raw <$> capVar
1818 shrink (V.Raw v) = V.Raw <$> shrink v
1919
2020instance Arbitrary L.Literal where
@@ -85,12 +85,13 @@ instance Arbitrary v => Arbitrary (T.Type v) where
8585 field = (,) <$> lowVar <*> depthTipe
8686 fields = genVector n (\m -> (,) <$> lowVar <*> tipe m)
8787 fields1 = (:) <$> field <*> fields
88+ depthTipes = (:) <$> depthTipe <*> genVector n tipe
8889 in
8990 oneof
9091 [ T.Lambda <$> depthTipe <*> depthTipe
9192 , T.Var <$> lowVar
9293 , T.Type <$> arbitrary
93− , T.App <$> arbitrary <*> genVector n tipe
94+ , T.App <$> (T.Type <$> arbitrary) <*> depthTipes
9495 , T.Record <$> fields <*> pure Nothing
9596 , T.Record <$> fields1 <*> (Just . T.Var <$> lowVar)
9697 ]
@@ -99,8 +100,8 @@ instance Arbitrary v => Arbitrary (T.Type v) where
99100 case tipe of
100101 T.Lambda s t -> s : t : (T.Lambda <$> shrink s <*> shrink t)
101102 T.Var _ -> []
102− T.Aliased _ t -> [t]
103− T.Type _ -> []
103+ T.Aliased v t -> t : (T.Aliased v <$> shrink t)
104+ T.Type v -> T.Type <$> shrink v
104105 T.App t ts -> t : ts ++ (T.App <$> shrink t <*> shrink ts)
105106 T.Record fs t -> map snd fs ++ record
106107 where