on master help sign in
Make parse/print test more stringent, tweak Float gen.
37f5d9eMax New
tests/Tests/Property.hs+3−1
@@ -1,10 +1,12 @@
1module Tests.Property where
1module Tests.Property where
2
2
3+import Control.Applicative ((<*))
3import Test.Framework
4import Test.Framework
4import Test.Framework.Providers.HUnit
5import Test.Framework.Providers.HUnit
5import Test.Framework.Providers.QuickCheck2
6import Test.Framework.Providers.QuickCheck2
6import Test.HUnit (assert)
7import Test.HUnit (assert)
7import Test.QuickCheck
8import Test.QuickCheck
9+import Text.Parsec.Combinator (eof)
8
10
9import SourceSyntax.Literal as Lit
11import SourceSyntax.Literal as Lit
10import SourceSyntax.Pattern as Pat
12import SourceSyntax.Pattern as Pat
@@ -46,4 +48,4 @@ prop_parse_print p x =
46 either (const False) (== x) . parse_print p $ x
48 either (const False) (== x) . parse_print p $ x
47
49
48parse_print :: (Pretty a) => IParser a -> a -> Either String a
50parse_print :: (Pretty a) => IParser a -> a -> Either String a
49−parse_print p = either (Left . show) (Right) . iParse p . show . pretty
51+parse_print p = either (Left . show) (Right) . iParse (p <* eof) . show . pretty
tests/Tests/Property/Arbitrary.hs+7−4
@@ -13,7 +13,7 @@ import SourceSyntax.Pattern
13
13
14instance Arbitrary Literal where
14instance Arbitrary Literal where
15 arbitrary = oneof [ IntNum <$> arbitrary
15 arbitrary = oneof [ IntNum <$> arbitrary
16− , FloatNum <$> arbitrary
16+ , FloatNum <$> (arbitrary `suchThat` noE)
17 , Chr <$> arbitrary
17 , Chr <$> arbitrary
18 -- This is too permissive
18 -- This is too permissive
19 , Str <$> arbitrary
19 , Str <$> arbitrary
@@ -22,11 +22,15 @@ instance Arbitrary Literal where
22 ]
22 ]
23 shrink l = case l of
23 shrink l = case l of
24 IntNum n -> IntNum <$> shrink n
24 IntNum n -> IntNum <$> shrink n
25− FloatNum f -> FloatNum <$> shrink f
25+ FloatNum f -> FloatNum <$> (filter noE . shrink $ f)
26 Chr c -> Chr <$> shrink c
26 Chr c -> Chr <$> shrink c
27 Str s -> Str <$> shrink s
27 Str s -> Str <$> shrink s
28 Boolean b -> Boolean <$> shrink b
28 Boolean b -> Boolean <$> shrink b
29
29
30+noE :: Double -> Bool
31+noE = notElem 'e' . show
32+
33+
30instance Arbitrary Pattern where
34instance Arbitrary Pattern where
31 arbitrary = sized pat
35 arbitrary = sized pat
32 where pat :: Int -> Gen Pattern
36 where pat :: Int -> Gen Pattern
@@ -66,7 +70,6 @@ notReserved :: Gen String -> Gen String
66notReserved = flip exceptFor Parse.Helpers.reserveds
70notReserved = flip exceptFor Parse.Helpers.reserveds
67
71
68exceptFor :: (Ord a) => Gen a -> [a] -> Gen a
72exceptFor :: (Ord a) => Gen a -> [a] -> Gen a
69−exceptFor g xs = suchThat g notAnX
73+exceptFor g xs = g `suchThat` notAnX
70 where notAnX = flip Set.notMember xset
74 where notAnX = flip Set.notMember xset
71 xset = Set.fromList xs
75 xset = Set.fromList xs
72−