module Test.OITestGenerator.Axiom (
Axiom(),
axiom, withGens, axiom_name, axiom_gens,
AxiomResult(),
ar_cond, ar_lhs, ar_rhs, (=!=), (===>)
) where
import Data.Label
import Language.Haskell.TH
import Prelude
import Test.OITestGenerator.GenHelper
import Test.OITestGenerator.HasGens
newtype AxiomResult a = AxiomResult (Bool, a, a)
infix 1 =!=
(=!=) :: a -> a -> AxiomResult a
lhs =!= rhs = AxiomResult (True, lhs, rhs)
infixr 0 ===>
(===>) :: Bool -> AxiomResult a -> AxiomResult a
cond ===> AxiomResult (cond', lhs, rhs) = AxiomResult (cond && cond', lhs, rhs)
ar_cond :: AxiomResult a -> Bool
ar_cond (AxiomResult (cond, _, _)) = cond
ar_lhs :: AxiomResult a -> a
ar_lhs (AxiomResult (_, lhs, _)) = lhs
ar_rhs :: AxiomResult a -> a
ar_rhs (AxiomResult (_, _, rhs)) = rhs
data Axiom = Axiom {
_name :: Name,
_gens :: Q [Name]
}
mkLabel ''Axiom
axiom :: Name -> Axiom
axiom name' = Axiom {
_name = name',
_gens = return []
}
axiom_name :: Axiom -> Name
axiom_name = get name
axiom_gens :: Axiom -> Q [Name]
axiom_gens = get gens
instance HasGens Axiom where
withGens axiom' gens' = flip (set gens) axiom' $
let qargn = num_args_name nm
nm = get name axiom'
in qargn >>= \argn ->
if argn == length gens'
then return gens'
else fail $ "Axiom " ++ show nm ++ " has "
++ show argn ++ " arguments, but "
++ show (length gens') ++ " Gens are given"