about summary refs log blame commit diff
path: root/src/Xanthous/Util/QuickCheck.hs
blob: ac76a4c930d9865d622f2156eebbcc5a37fa4f3b (plain) (tree)



























                                                                                
module Xanthous.Util.QuickCheck
  ( FunctionShow(..)
  , functionJSON
  , FunctionJSON(..)
  ) where
--------------------------------------------------------------------------------
import Xanthous.Prelude
import Test.QuickCheck
import Test.QuickCheck.Function
import Test.QuickCheck.Instances.ByteString ()
import Data.Aeson
import Data.Coerce
--------------------------------------------------------------------------------

newtype FunctionShow a = FunctionShow a
  deriving newtype (Show, Read)

instance (Show a, Read a) => Function (FunctionShow a) where
  function = functionShow

functionJSON :: (ToJSON a, FromJSON a) => (a -> c) -> a :-> c
functionJSON = functionMap encode (headEx . decode)

newtype FunctionJSON a = FunctionJSON a
  deriving newtype (ToJSON, FromJSON)

instance (ToJSON a, FromJSON a) => Function (FunctionJSON a) where
  function = functionJSON