2017-04-11 03:08:08 +03:00
|
|
|
{-# LANGUAGE RankNTypes #-}
|
2017-04-12 04:59:40 +03:00
|
|
|
module Test.Hedgehog.Compat (
|
|
|
|
(...)
|
|
|
|
, choose
|
|
|
|
, blindForAll
|
|
|
|
, semiBlindForAll
|
|
|
|
, forAllRender
|
|
|
|
)where
|
2017-04-11 03:08:08 +03:00
|
|
|
|
|
|
|
import Control.Monad.Trans.Class (MonadTrans(..))
|
|
|
|
|
|
|
|
import Data.Typeable ( typeOf )
|
|
|
|
|
|
|
|
import qualified Hedgehog.Gen as Gen
|
|
|
|
import qualified Hedgehog.Range as Range
|
|
|
|
import Hedgehog.Internal.Property
|
|
|
|
import Hedgehog.Internal.Source
|
|
|
|
import Hedgehog.Internal.Show
|
|
|
|
|
|
|
|
(...) :: (c -> d) -> (a -> b -> c) -> a -> b -> d
|
|
|
|
(...) = (.) . (.)
|
|
|
|
{-# INLINE (...) #-}
|
|
|
|
|
2017-04-12 04:59:40 +03:00
|
|
|
choose :: ( Monad m, Integral a ) => a -> a -> Gen.Gen m a
|
2017-04-11 03:08:08 +03:00
|
|
|
choose = Gen.integral ... Range.constant
|
|
|
|
|
2017-04-12 04:59:40 +03:00
|
|
|
blindForAll :: Monad m => Gen.Gen m a -> Test m a
|
2017-04-11 03:08:08 +03:00
|
|
|
blindForAll = Test . lift . lift
|
|
|
|
|
2017-04-12 04:59:40 +03:00
|
|
|
semiBlindForAll :: (Monad m, Show a, HasCallStack) => Gen.Gen m a -> Test m a
|
2017-04-11 03:08:08 +03:00
|
|
|
semiBlindForAll gen = do
|
|
|
|
x <- Test . lift $ lift gen
|
|
|
|
writeLog $ Input (getCaller callStack) (typeOf ()) (showPretty x)
|
|
|
|
return x
|
|
|
|
|
2017-04-12 04:59:40 +03:00
|
|
|
forAllRender :: (Monad m, HasCallStack) => ( a -> String ) -> Gen.Gen m a -> Test m a
|
2017-04-11 03:08:08 +03:00
|
|
|
forAllRender render gen = do
|
|
|
|
x <- Test . lift $ lift gen
|
|
|
|
writeLog $ Input (getCaller callStack) (typeOf ()) (render x)
|
|
|
|
return x
|