on master help sign in
Make parse/print test more stringent, tweak Float gen.
commit37f5d9e1eaac5953829397a458f671125f1a3f80 authorMax New <maxsnew@gmail.com> dateSun 29 Dec 2013, 22:11 (13 years ago) parentd003062
2 files changed+10−5
tests/Tests/Property.hs+3−1 tests/Tests/Property/Arbitrary.hs+7−4
tests/Tests/Property.hs+3−1
@@ -1,10 +1,12 @@
11module Tests.Property where
22
3+import Control.Applicative ((<*))
34import Test.Framework
45import Test.Framework.Providers.HUnit
56import Test.Framework.Providers.QuickCheck2
67import Test.HUnit (assert)
78import Test.QuickCheck
9+import Text.Parsec.Combinator (eof)
810
911import SourceSyntax.Literal as Lit
1012import SourceSyntax.Pattern as Pat
@@ -46,4 +48,4 @@ prop_parse_print p x =
4648 either (const False) (== x) . parse_print p $ x
4749
4850parse_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
1313
1414instance Arbitrary Literal where
1515 arbitrary = oneof [ IntNum <$> arbitrary
16− , FloatNum <$> arbitrary
16+ , FloatNum <$> (arbitrary `suchThat` noE)
1717 , Chr <$> arbitrary
1818 -- This is too permissive
1919 , Str <$> arbitrary
@@ -22,11 +22,15 @@ instance Arbitrary Literal where
2222 ]
2323 shrink l = case l of
2424 IntNum n -> IntNum <$> shrink n
25− FloatNum f -> FloatNum <$> shrink f
25+ FloatNum f -> FloatNum <$> (filter noE . shrink $ f)
2626 Chr c -> Chr <$> shrink c
2727 Str s -> Str <$> shrink s
2828 Boolean b -> Boolean <$> shrink b
2929
30+noE :: Double -> Bool
31+noE = notElem 'e' . show
32+
33+
3034instance Arbitrary Pattern where
3135 arbitrary = sized pat
3236 where pat :: Int -> Gen Pattern
@@ -66,7 +70,6 @@ notReserved :: Gen String -> Gen String
6670notReserved = flip exceptFor Parse.Helpers.reserveds
6771
6872exceptFor :: (Ord a) => Gen a -> [a] -> Gen a
69−exceptFor g xs = suchThat g notAnX
73+exceptFor g xs = g `suchThat` notAnX
7074 where notAnX = flip Set.notMember xset
7175 xset = Set.fromList xs
72−