module Michelson.Test.Util
( leftToShowPanic
, leftToPrettyPanic
, failedProp
, succeededProp
, qcIsLeft
, qcIsRight
) where
import Fmt (Buildable, pretty)
import Test.QuickCheck.Property (Property, Result(..), failed, property)
leftToShowPanic :: (Show e, HasCallStack) => Either e a -> a
leftToShowPanic = either (error . show) id
leftToPrettyPanic :: (Buildable e, HasCallStack) => Either e a -> a
leftToPrettyPanic = either (error . pretty) id
failedProp :: Text -> Property
failedProp r = property $ failed { reason = toString r }
succeededProp :: Property
succeededProp = property True
qcIsLeft :: Show b => Either a b -> Property
qcIsLeft (Left _) = property True
qcIsLeft (Right x) = failedProp $ "expected Left, got Right (" <> show x <> ")"
qcIsRight :: Show a => Either a b -> Property
qcIsRight (Right _) = property True
qcIsRight (Left x) = failedProp $ "expected Right, got Left (" <> show x <> ")"