module Conformance.TestUtils where

import Conformance
import Control.Monad.IO.Class
import Test.Syd

shouldConformStrict :: (Show ue, Show fe, Show w) => Conform ue fe w a -> IO a
shouldConformStrict :: forall ue fe w a.
(Show ue, Show fe, Show w) =>
Conform ue fe w a -> IO a
shouldConformStrict = forall ue fe w a.
(Show ue, Show fe, Show w) =>
Either (Either ue (Notes fe w)) a -> IO a
assertStrictResultSucceeded forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ue fe w a.
Conform ue fe w a -> Either (Either ue (Notes fe w)) a
runConformStrict

shouldConformTStrict :: (Show ue, Show fe, Show w, MonadIO m) => ConformT ue fe w m a -> m a
shouldConformTStrict :: forall ue fe w (m :: * -> *) a.
(Show ue, Show fe, Show w, MonadIO m) =>
ConformT ue fe w m a -> m a
shouldConformTStrict ConformT ue fe w m a
func = do
  Either (Either ue (Notes fe w)) a
errOrErrOrResult <- forall (m :: * -> *) ue fe w a.
Monad m =>
ConformT ue fe w m a -> m (Either (Either ue (Notes fe w)) a)
runConformTStrict ConformT ue fe w m a
func
  forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall ue fe w a.
(Show ue, Show fe, Show w) =>
Either (Either ue (Notes fe w)) a -> IO a
assertStrictResultSucceeded Either (Either ue (Notes fe w)) a
errOrErrOrResult

assertStrictResultSucceeded :: (Show ue, Show fe, Show w) => Either (Either ue (Notes fe w)) a -> IO a
assertStrictResultSucceeded :: forall ue fe w a.
(Show ue, Show fe, Show w) =>
Either (Either ue (Notes fe w)) a -> IO a
assertStrictResultSucceeded Either (Either ue (Notes fe w)) a
errOrErrOrResult =
  case Either (Either ue (Notes fe w)) a
errOrErrOrResult of
    Left Either ue (Notes fe w)
e -> forall a. HasCallStack => String -> IO a
expectationFailure forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show Either ue (Notes fe w)
e
    Right a
a -> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a

shouldConform :: (Show ue, Show fe) => Conform ue fe w a -> IO a
shouldConform :: forall ue fe w a. (Show ue, Show fe) => Conform ue fe w a -> IO a
shouldConform Conform ue fe w a
func =
  case forall ue fe w a.
Conform ue fe w a -> Either (HaltReason ue fe) (a, [w])
runConform Conform ue fe w a
func of
    Left HaltReason ue fe
hr ->
      forall a. HasCallStack => String -> IO a
expectationFailure forall a b. (a -> b) -> a -> b
$
        [String] -> String
unwords
          [ String
"runConform failed",
            forall a. Show a => a -> String
ppShow HaltReason ue fe
hr
          ]
    Right (a
a, [w]
_) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a

shouldConformT :: (Show ue, Show fe, MonadIO m) => ConformT ue fe w m a -> m a
shouldConformT :: forall ue fe (m :: * -> *) w a.
(Show ue, Show fe, MonadIO m) =>
ConformT ue fe w m a -> m a
shouldConformT ConformT ue fe w m a
func = do
  Either (HaltReason ue fe) (a, [w])
errOrErrOrResult <- forall (m :: * -> *) ue fe w a.
Monad m =>
ConformT ue fe w m a -> m (Either (HaltReason ue fe) (a, [w]))
runConformT ConformT ue fe w m a
func
  case Either (HaltReason ue fe) (a, [w])
errOrErrOrResult of
    Left HaltReason ue fe
hr ->
      forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$
        forall a. HasCallStack => String -> IO a
expectationFailure forall a b. (a -> b) -> a -> b
$
          [String] -> String
unwords
            [ String
"runConformT failed",
              forall a. Show a => a -> String
ppShow HaltReason ue fe
hr
            ]
    Right (a
a, [w]
_) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a

shouldConformLenient :: Show ue => Conform ue fe w a -> IO a
shouldConformLenient :: forall ue fe w a. Show ue => Conform ue fe w a -> IO a
shouldConformLenient = forall ue a fe w. Show ue => Either ue (a, Notes fe w) -> IO a
assertLenientResultSucceeded forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall ue fe w a. Conform ue fe w a -> Either ue (a, Notes fe w)
runConformLenient

shouldConformTLenient :: (Show ue, MonadIO m) => ConformT ue fe w m a -> m a
shouldConformTLenient :: forall ue (m :: * -> *) fe w a.
(Show ue, MonadIO m) =>
ConformT ue fe w m a -> m a
shouldConformTLenient ConformT ue fe w m a
func = do
  Either ue (a, Notes fe w)
errOrErrOrResult <- forall (m :: * -> *) ue fe w a.
Monad m =>
ConformT ue fe w m a -> m (Either ue (a, Notes fe w))
runConformTLenient ConformT ue fe w m a
func
  forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO forall a b. (a -> b) -> a -> b
$ forall ue a fe w. Show ue => Either ue (a, Notes fe w) -> IO a
assertLenientResultSucceeded Either ue (a, Notes fe w)
errOrErrOrResult

assertLenientResultSucceeded :: Show ue => Either ue (a, Notes fe w) -> IO a
assertLenientResultSucceeded :: forall ue a fe w. Show ue => Either ue (a, Notes fe w) -> IO a
assertLenientResultSucceeded Either ue (a, Notes fe w)
errOrErrOrResult =
  case Either ue (a, Notes fe w)
errOrErrOrResult of
    Left ue
e -> forall a. HasCallStack => String -> IO a
expectationFailure forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show ue
e
    Right (a
a, Notes fe w
_) -> forall (f :: * -> *) a. Applicative f => a -> f a
pure a
a