on master help sign in
added some guards. todo turn this into correct Gen. still one failcase
commitc6165576188c923ee05a8e5ce764d5aaab1431f0 authorJohn P Mayer Jr <john.p.mayer.jr@gmail.com> dateTue 14 Jan 2014, 02:47 (13 years ago) parentd92ac79
2 files changed+23−9
tests/Tests/Property.hs+5−3 tests/Tests/Property/Arbitrary.hs+18−6
tests/Tests/Property.hs+5−3
@@ -13,16 +13,18 @@ import SourceSyntax.Pattern as Pat
1313import SourceSyntax.PrettyPrint (Pretty, pretty)
1414import Parse.Helpers (IParser, iParse)
1515import Parse.Literal (literal)
16−import Parse.Pattern (expr)
16+import qualified Parse.Pattern as Pat (expr)
17+import qualified Parse.Type as Type (expr)
1718import Tests.Property.Arbitrary
1819
1920propertyTests :: Test
2021propertyTests =
2122 testGroup "Parse/Print Agreement Tests"
2223 [
23− testCase "Long Pattern test" $ assert (prop_parse_print expr longPat)
24+ testCase "Long Pattern test" $ assert (prop_parse_print Pat.expr longPat)
2425 , testProperty "Literal test" $ prop_parse_print literal
25− , testProperty "Pattern test" $ prop_parse_print expr
26+ , testProperty "Pattern test" $ prop_parse_print Pat.expr
27+ , testProperty "Type test" $ prop_parse_print Type.expr
2628 ]
2729
2830 where
tests/Tests/Property/Arbitrary.hs+18−6
@@ -56,22 +56,31 @@ instance Arbitrary Pattern where
5656 PData s ps -> ps ++ (PData <$> shrinkWHead s <*> shrink ps)
5757 where shrinkWHead (x:xs) = (x:) <$> shrink xs
5858
59+isValidType :: Type -> Bool
60+isValidType (Lambda s t) = isValidType s && isValidType t
61+isValidType (Record [] (Just _)) = False
62+isValidType (Record (("",_):_) _) = False
63+isValidType (Record fs _) = all isValidType $ map snd fs
64+isValidType (Data _ []) = False
65+isValidType (Data _ ts) = all isValidType ts
66+isValidType _ = True
67+
5968instance Arbitrary Type where
60− arbitrary = sized tipe
69+ arbitrary = sized tipe `suchThat` isValidType
6170 where tipe :: Int -> Gen Type
6271 tipe n = oneof [ Lambda <$> depthTipe <*> depthTipe
63− , Var <$> arbitrary
64− , Data <$> arbitrary <*> listOf1 depthTipe
65− , Record <$> listOf ((,) <$> arbitrary <*> depthTipe) <*> arbitrary
72+ , Var <$> lowVar
73+ , Data <$> capVar <*> listOf1 depthTipe
74+ , Record <$> listOf ((,) <$> lowVar <*> depthTipe) <*> maybeOf lowVar
6675 ]
6776 where depthTipe :: Gen Type
6877 depthTipe = choose (0,n) >>= tipe
6978
70− shrink tipe = case tipe of
79+ shrink tipe = filter isValidType $ case tipe of
7180 Lambda s t -> Lambda <$> shrink s <*> shrink t
7281 Var _ -> []
7382 Data n ts -> Data n <$> shrink ts
74− Record fs t -> Record <$> shrink fs <*> pure t
83+ Record fs t -> Record <$> shrink fs <*> pure t
7584
7685lowVar :: Gen String
7786lowVar = notReserved $ (:) <$> lower <*> listOf varLetter
@@ -84,6 +93,9 @@ capVar = notReserved $ (:) <$> upper <*> listOf varLetter
8493varLetter :: Gen Char
8594varLetter = elements $ ['a'..'z'] ++ ['A'..'Z'] ++ ['0'..'9'] ++ ['\'', '_']
8695
96+maybeOf :: Gen a -> Gen (Maybe a)
97+maybeOf g = oneof [ pure Nothing, Just <$> g ]
98+
8799notReserved :: Gen String -> Gen String
88100notReserved = flip exceptFor Parse.Helpers.reserveds
89101