1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
|
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Test.Hedgehog.Text where
import Data.Int (Int64)
import Data.Typeable (Typeable)
import Hedgehog
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import Text.Read (readEither)
genSize :: Gen Size
genSize =
Size <$> Gen.enumBounded
genOdd :: Gen Int64
genOdd =
let
mkOdd x =
if odd x then
x
else
pred x
in
mkOdd <$> Gen.int64 (Range.constant 1 maxBound)
genSeed :: Gen Seed
genSeed =
Seed <$> Gen.word64 Range.constantBounded <*> fmap fromIntegral genOdd
genPrecedence :: Gen Int
genPrecedence =
Gen.int (Range.constant 0 11)
genString :: Gen String
genString =
Gen.string (Range.constant 0 100) Gen.alpha
checkShowAppend :: (Typeable a, Show a) => Gen a -> Property
checkShowAppend gen =
property $ do
prec <- forAll genPrecedence
x <- forAll gen
xsuffix <- forAll genString
ysuffix <- forAll genString
showsPrec prec x xsuffix ++ ysuffix === showsPrec prec x (xsuffix ++ ysuffix)
trippingReadShow :: (Eq a, Typeable a, Show a, Read a) => Gen a -> Property
trippingReadShow gen =
property $ do
prec <- forAll genPrecedence
x <- forAll gen
tripping x (\z -> showsPrec prec z "") readEither
prop_show_append_size :: Property
prop_show_append_size =
checkShowAppend genSize
prop_tripping_append_size :: Property
prop_tripping_append_size =
trippingReadShow genSize
prop_show_append_seed :: Property
prop_show_append_seed =
checkShowAppend genSeed
prop_tripping_append_seed :: Property
prop_tripping_append_seed =
trippingReadShow genSeed
tests :: IO Bool
tests =
checkParallel $$(discover)
|