| Safe Haskell | None |
|---|---|
| Language | GHC2021 |
Skeletest.Internal.Predicate
Synopsis
- data Predicate (m :: Type -> Type) a
- data PredicateResult
- runPredicate :: Monad m => Predicate m a -> a -> m PredicateResult
- renderPredicate :: forall (m :: Type -> Type) a. Predicate m a -> Text
- anything :: forall (m :: Type -> Type) a. Monad m => Predicate m a
- eq :: forall a (m :: Type -> Type). (Eq a, Monad m) => a -> Predicate m a
- gt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- gte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- lt :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- lte :: forall a (m :: Type -> Type). (Ord a, Monad m) => a -> Predicate m a
- just :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m (Maybe a)
- nothing :: forall (m :: Type -> Type) a. Monad m => Predicate m (Maybe a)
- left :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> Predicate m (Either a b)
- right :: forall (m :: Type -> Type) b a. Monad m => Predicate m b -> Predicate m (Either a b)
- class IsTuple a => IsPredTuple (m :: Type -> Type) a where
- type ToPredTuple (m :: Type -> Type) a
- toHListPred :: proxy a -> ToPredTuple m a -> HList (Predicate m) (TupleArgs a)
- tup :: forall a (m :: Type -> Type). (IsPredTuple m a, Monad m) => ToPredTuple m a -> Predicate m a
- con :: forall a (m :: Type -> Type). a -> Predicate m a
- 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
- approx :: forall a (m :: Type -> Type). (Fractional a, Ord a, Monad m) => Tolerance -> a -> Predicate m a
- tol :: Tolerance
- data Tolerance = Tolerance {}
- (<<<) :: forall (m :: Type -> Type) a b. Monad m => Predicate m a -> (b -> a) -> Predicate m b
- (>>>) :: forall (m :: Type -> Type) b a. Monad m => (b -> a) -> Predicate m a -> Predicate m b
- not :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a
- (&&) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a
- (||) :: forall (m :: Type -> Type) a. Monad m => Predicate m a -> Predicate m a -> Predicate m a
- and :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a
- or :: forall (m :: Type -> Type) a. Monad m => [Predicate m a] -> Predicate m a
- any :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a)
- all :: forall t (m :: Type -> Type) a. (Foldable t, Monad m) => Predicate m a -> Predicate m (t a)
- elem :: forall a t (m :: Type -> Type). (Eq a, Foldable t, Monad m) => a -> Predicate m (t a)
- class HasSubsequences a where
- isPrefixOf :: a -> a -> Bool
- isInfixOf :: a -> a -> Bool
- isSuffixOf :: a -> a -> Bool
- hasPrefix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- hasInfix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- hasSuffix :: forall a (m :: Type -> Type). (HasSubsequences a, Monad m) => a -> Predicate m a
- returns :: MonadIO m => Predicate m a -> Predicate m (m a)
- throws :: (Exception e, MonadUnliftIO m) => Predicate m e -> Predicate m (m a)
- data Fun a b = Fun String (a -> b)
- data IsoChecker a b = IsoChecker (Fun a b) (Fun a b)
- (===) :: (a -> b) -> (a -> b) -> IsoChecker a b
- isoWith :: (HasCallStack, Show a, Eq b) => Gen a -> Predicate PropertyM (IsoChecker a b)
- matchesSnapshot :: forall a (m :: Type -> Type). (Typeable a, MonadIO m) => Predicate m a
Documentation
data PredicateResult Source #
Constructors
| PredicateSuccess | |
| PredicateFail Text |
runPredicate :: Monad m => Predicate m a -> a -> m PredicateResult Source #
General
Ord
Data types
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
| IsPredTuple m (a, b) Source # | |||||
Defined in Skeletest.Internal.Predicate Associated Types
Methods toHListPred :: proxy (a, b) -> ToPredTuple m (a, b) -> HList (Predicate m) (TupleArgs (a, b)) Source # | |||||
| IsPredTuple m (a, b, c) Source # | |||||
Defined in Skeletest.Internal.Predicate Associated Types
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 # | |||||
Defined in Skeletest.Internal.Predicate Associated Types
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 # | |||||
Defined in Skeletest.Internal.Predicate Associated Types
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 # | |||||
Defined in Skeletest.Internal.Predicate Associated Types
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
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 #
(&&) :: 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 #
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
| HasSubsequences Text Source # | |
| Eq a => HasSubsequences [a] Source # | |
Defined in Skeletest.Internal.Predicate | |
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
Functions
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
isoWith :: (HasCallStack, Show a, Eq b) => Gen a -> Predicate PropertyM (IsoChecker a b) Source #
See (===).