Skip to content

Instantly share code, notes, and snippets.

@HirotoShioi
Created March 1, 2019 07:07
Show Gist options
  • Save HirotoShioi/98f05389933992dc0e0e88c3a31d0569 to your computer and use it in GitHub Desktop.
Save HirotoShioi/98f05389933992dc0e0e88c3a31d0569 to your computer and use it in GitHub Desktop.
Working example of validity library
{-|
-- dependencies:
-- - base >= 4.7 && < 5
-- - validity
-- - hspec
-- - genvalidity
-- - genvalidity-hspec
-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE TypeApplications #-}
module Lib where
import Data.GenValidity (GenUnchecked, GenValid, Validity)
import GHC.Generics (Generic)
import Test.Hspec (hspec)
import Test.Validity (eqSpec, genValidSpec)
data MyType = MyType
{ myBool :: Bool
, myRational :: Rational
} deriving (Show, Eq, Generic)
instance Validity MyType
instance GenUnchecked MyType
instance GenValid MyType
spec :: IO ()
spec = hspec $ do
eqSpec @MyType
genValidSpec @MyType
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment