-- | HUnit and Hspec integration for 'Predicate'
module Test.Predicates.HUnit (assertSatisfied, (@?~), shouldSatisfy) where

import Test.HUnit (Assertion, assertFailure)
import Test.Predicates (Predicate (accept, explain))

assertSatisfied :: Predicate a -> a -> Assertion
assertSatisfied :: Predicate a -> a -> Assertion
assertSatisfied Predicate a
predicate a
val =
  if Predicate a -> a -> Bool
forall a. Predicate a -> a -> Bool
accept Predicate a
predicate a
val
    then () -> Assertion
forall (m :: * -> *) a. Monad m => a -> m a
return ()
    else String -> Assertion
forall a. HasCallStack => String -> IO a
assertFailure (Predicate a -> a -> String
forall a. Predicate a -> a -> String
explain Predicate a
predicate a
val)

(@?~) :: a -> Predicate a -> Assertion
@?~ :: a -> Predicate a -> Assertion
(@?~) = (Predicate a -> a -> Assertion) -> a -> Predicate a -> Assertion
forall a b c. (a -> b -> c) -> b -> a -> c
flip Predicate a -> a -> Assertion
forall a. Predicate a -> a -> Assertion
assertSatisfied

shouldSatisfy :: a -> Predicate a -> Assertion
shouldSatisfy :: a -> Predicate a -> Assertion
shouldSatisfy = (Predicate a -> a -> Assertion) -> a -> Predicate a -> Assertion
forall a b c. (a -> b -> c) -> b -> a -> c
flip Predicate a -> a -> Assertion
forall a. Predicate a -> a -> Assertion
assertSatisfied