{-# OPTIONS_HADDOCK hide #-}

module Polysemy.Test.Assert (
  module Polysemy.Test.Assert,
  assert,
  evalEither,
  (===),
) where

import Hedgehog (TestT, assert, evalEither, (===))

assertRight ::
  Eq a =>
  Show a =>
  Show e =>
  Monad m =>
  a ->
  Either e a ->
  TestT m ()
assertRight :: a -> Either e a -> TestT m ()
assertRight a
target =
  (a
target a -> a -> TestT m ()
forall (m :: * -> *) a.
(MonadTest m, Eq a, Show a, HasCallStack) =>
a -> a -> m ()
===) (a -> TestT m ())
-> (Either e a -> TestT m a) -> Either e a -> TestT m ()
forall (m :: * -> *) b c a.
Monad m =>
(b -> m c) -> (a -> m b) -> a -> m c
<=< Either e a -> TestT m a
forall (m :: * -> *) x a.
(MonadTest m, Show x, HasCallStack) =>
Either x a -> m a
evalEither

data ValueIsNothing =
  ValueIsNothing
  deriving Int -> ValueIsNothing -> ShowS
[ValueIsNothing] -> ShowS
ValueIsNothing -> String
(Int -> ValueIsNothing -> ShowS)
-> (ValueIsNothing -> String)
-> ([ValueIsNothing] -> ShowS)
-> Show ValueIsNothing
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ValueIsNothing] -> ShowS
$cshowList :: [ValueIsNothing] -> ShowS
show :: ValueIsNothing -> String
$cshow :: ValueIsNothing -> String
showsPrec :: Int -> ValueIsNothing -> ShowS
$cshowsPrec :: Int -> ValueIsNothing -> ShowS
Show

assertJust ::
  Eq a =>
  Show a =>
  Monad m =>
  a ->
  Maybe a ->
  TestT m ()
assertJust :: a -> Maybe a -> TestT m ()
assertJust a
target =
  a -> Either ValueIsNothing a -> TestT m ()
forall a e (m :: * -> *).
(Eq a, Show a, Show e, Monad m) =>
a -> Either e a -> TestT m ()
assertRight a
target (Either ValueIsNothing a -> TestT m ())
-> (Maybe a -> Either ValueIsNothing a) -> Maybe a -> TestT m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueIsNothing -> Maybe a -> Either ValueIsNothing a
forall l r. l -> Maybe r -> Either l r
maybeToRight ValueIsNothing
ValueIsNothing

evalMaybe ::
  Monad m =>
  Maybe a ->
  TestT m a
evalMaybe :: Maybe a -> TestT m a
evalMaybe =
  Either ValueIsNothing a -> TestT m a
forall (m :: * -> *) x a.
(MonadTest m, Show x, HasCallStack) =>
Either x a -> m a
evalEither (Either ValueIsNothing a -> TestT m a)
-> (Maybe a -> Either ValueIsNothing a) -> Maybe a -> TestT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ValueIsNothing -> Maybe a -> Either ValueIsNothing a
forall l r. l -> Maybe r -> Either l r
maybeToRight ValueIsNothing
ValueIsNothing