skeletest-0.1.0: Batteries-included, opinionated test framework
Safe HaskellNone
LanguageGHC2021

Skeletest.Internal.Predicate

Synopsis

Documentation

data Predicate (m :: Type -> Type) a Source #

renderPredicate :: forall (m :: Type -> Type) a. Predicate m a -> Text Source #

General

anything :: forall (m :: Type -> Type) a. Monad m => Predicate m a Source #

Ord

eq :: forall a (m :: Type -> Type). (Eq a, Monad m) => a -> Predicate m a Source #

gt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a Source #

gte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a Source #

lt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a Source #

lte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a Source #

Data types

just :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m (Maybe a) Source #

nothing :: forall (m :: Type -> Type) a. Monad m => Predicate m (Maybe a) Source #

left :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> Predicate m (Either a b) Source #

right :: forall (m :: Type -> Type) b a. Monad m => Predicate m b -> Predicate m (Either a b) Source #

class IsTuple a => IsPredTuple (m :: Type -> Type) a where Source #

Associated Types

type ToPredTuple (m :: Type -> Type) a Source #

Methods

toHListPred :: proxy a -> ToPredTuple m a -> HList (Predicate m) (TupleArgs a) Source #

Instances

Instances details
IsPredTuple m (a, b) Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Associated Types

type ToPredTuple m (a, b) 
Instance details

Defined in Skeletest.Internal.Predicate

type ToPredTuple m (a, b) = (Predicate m a, Predicate m b)

Methods

toHListPred :: proxy (a, b) -> ToPredTuple m (a, b) -> HList (Predicate m) (TupleArgs (a, b)) Source #

IsPredTuple m (a, b, c) Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Associated Types

type ToPredTuple m (a, b, c) 
Instance details

Defined in Skeletest.Internal.Predicate

type ToPredTuple m (a, b, c) = (Predicate m a, Predicate m b, Predicate m c)

Methods

toHListPred :: proxy (a, b, c) -> ToPredTuple m (a, b, c) -> HList (Predicate m) (TupleArgs (a, b, c)) Source #

IsPredTuple m (a, b, c, d) Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Associated Types

type ToPredTuple m (a, b, c, d) 
Instance details

Defined in Skeletest.Internal.Predicate

type ToPredTuple m (a, b, c, d) = (Predicate m a, Predicate m b, Predicate m c, Predicate m d)

Methods

toHListPred :: proxy (a, b, c, d) -> ToPredTuple m (a, b, c, d) -> HList (Predicate m) (TupleArgs (a, b, c, d)) Source #

IsPredTuple m (a, b, c, d, e) Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Associated Types

type ToPredTuple m (a, b, c, d, e) 
Instance details

Defined in Skeletest.Internal.Predicate

type ToPredTuple m (a, b, c, d, e) = (Predicate m a, Predicate m b, Predicate m c, Predicate m d, Predicate m e)

Methods

toHListPred :: proxy (a, b, c, d, e) -> ToPredTuple m (a, b, c, d, e) -> HList (Predicate m) (TupleArgs (a, b, c, d, e)) Source #

IsPredTuple m (a, b, c, d, e, f) Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Associated Types

type ToPredTuple m (a, b, c, d, e, f) 
Instance details

Defined in Skeletest.Internal.Predicate

type ToPredTuple m (a, b, c, d, e, f) = (Predicate m a, Predicate m b, Predicate m c, Predicate m d, Predicate m e, Predicate m f)

Methods

toHListPred :: proxy (a, b, c, d, e, f) -> ToPredTuple m (a, b, c, d, e, f) -> HList (Predicate m) (TupleArgs (a, b, c, d, e, f)) Source #

tup :: forall a (m :: Type -> Type). (IsPredTuple m a, Monad m) => ToPredTuple m a -> Predicate m a Source #

Matches a tuple satisfying the given predicates. Works for tuples up to 6 elements.

P.tup (P.eq 1, P.gt 2, P.hasPrefix "hello ")

con :: forall a (m :: Type -> Type). a -> Predicate m a Source #

A predicate for checking that a value matches the given constructor.

It takes one argument, which is the constructor, except with all fields taking a Predicate instead of the normal value. Skeletest will rewrite the expression so it typechecks correctly.

>>> user `shouldSatisfy` P.con User{name = P.eq "user1", email = P.contains "@"}

Record fields that are omitted are not checked at all; i.e. P.con Foo{} and P.con Foo{a = P.anything} are equivalent.

conMatches :: forall (m :: Type -> Type) (fields :: [Type]) a. Monad m => String -> Maybe (HList (Const String :: Type -> Type) fields) -> (a -> Maybe (HList Identity fields)) -> HList (Predicate m) fields -> Predicate m a Source #

A predicate for checking that a value matches the given constructor. Assumes that the arguments correctly match the constructor being tested, so it should not be written directly, only generated from con.

Numeric

approx :: forall a (m :: Type -> Type). (Fractional a, Ord a, Monad m) => Tolerance -> a -> Predicate m a Source #

A predicate for checking that a value is equal within some tolerance.

Useful for checking equality with floats, which might not be exactly equal. For more information, see: https://jvns.ca/blog/2023/01/13/examples-of-floating-point-problems/.

>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol 0.3
>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Just 1e-6} 0.3
>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.abs = 1e-12} 0.3
>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Just 1e-6, P.abs = 1e-12} 0.3
>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Nothing} 0.3
>>> (0.1 + 0.2) `shouldSatisfy` P.approx P.tol{P.rel = Nothing, P.abs = 1e-12} 0.3

data Tolerance Source #

Constructors

Tolerance 

Fields

Combinators

(<<<) :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> (b -> a) -> Predicate m b infixr 1 Source #

(>>>) :: forall (m :: Type -> Type) b a. Monad m => (b -> a) -> Predicate m a -> Predicate m b infixr 1 Source #

not :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a Source #

(&&) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a Source #

(||) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a Source #

and :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a Source #

or :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a Source #

Containers

any :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a) Source #

all :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a) Source #

elem :: forall a t (m :: Type -> Type). (Eq a, Foldable t, Monad m) => a -> Predicate m (t a) Source #

Subsequences

class HasSubsequences a where Source #

Methods

isPrefixOf :: a -> a -> Bool Source #

isInfixOf :: a -> a -> Bool Source #

isSuffixOf :: a -> a -> Bool Source #

Instances

Instances details
HasSubsequences Text Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Eq a => HasSubsequences [a] Source # 
Instance details

Defined in Skeletest.Internal.Predicate

Methods

isPrefixOf :: [a] -> [a] -> Bool Source #

isInfixOf :: [a] -> [a] -> Bool Source #

isSuffixOf :: [a] -> [a] -> Bool Source #

hasPrefix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #

hasInfix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #

hasSuffix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a Source #

IO

returns :: MonadIO m => Predicate m a -> Predicate m (m a) Source #

Functions

data Fun a b Source #

Constructors

Fun String (a -> b) 

data IsoChecker a b Source #

Constructors

IsoChecker (Fun a b) (Fun a b) 

(===) :: (a -> b) -> (a -> b) -> IsoChecker a b infix 2 Source #

Verify if two functions are isomorphic.

prop "reverse . reverse === id" $ do
  let genList = Gen.list (Gen.linear 0 10) $ Gen.int (Gen.linear 0 1000)
  (reverse . reverse) === id `shouldSatisfy` P.isoWith genList

Snapshot testing

matchesSnapshot :: forall a (m :: Type -> Type). (Typeable a, MonadIO m) => Predicate m a Source #