{-# OPTIONS_GHC -fno-warn-deprecations #-}
module Test.Hspec.Core.Extension.Config.Type (
  Option(..)
, Config(..)

, setAnnotation
, getAnnotation

, addSpecTransformation
, applySpecTransformation
) where

import           Prelude ()
import           Test.Hspec.Core.Compat

import qualified GetOpt.Declarative as Declarative

import           Test.Hspec.Core.Config.Definition (Config(..))
import qualified Test.Hspec.Core.Config.Definition as Core

import           Test.Hspec.Core.Extension.Tree (SpecTree)

newtype Option = Option { Option -> Option Config
unOption :: Declarative.Option Config }

setAnnotation :: Typeable value => value -> Config -> Config
setAnnotation :: forall value. Typeable value => value -> Config -> Config
setAnnotation = value -> Config -> Config
forall value. Typeable value => value -> Config -> Config
Core.setConfigAnnotation

getAnnotation :: Typeable value => Config -> Maybe value
getAnnotation :: forall value. Typeable value => Config -> Maybe value
getAnnotation = Config -> Maybe value
forall value. Typeable value => Config -> Maybe value
Core.getConfigAnnotation

newtype SpecTransformation = SpecTransformation { SpecTransformation -> Config -> [SpecTree] -> [SpecTree]
unSpecTransformation :: Config -> [SpecTree] -> [SpecTree] }

setSpecTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> Config -> Config
setSpecTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> Config -> Config
setSpecTransformation = SpecTransformation -> Config -> Config
forall value. Typeable value => value -> Config -> Config
setAnnotation (SpecTransformation -> Config -> Config)
-> ((Config -> [SpecTree] -> [SpecTree]) -> SpecTransformation)
-> (Config -> [SpecTree] -> [SpecTree])
-> Config
-> Config
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Config -> [SpecTree] -> [SpecTree]) -> SpecTransformation
SpecTransformation

getSpecTransformation :: Config -> Config -> [SpecTree] -> [SpecTree]
getSpecTransformation :: Config -> Config -> [SpecTree] -> [SpecTree]
getSpecTransformation = (Config -> [SpecTree] -> [SpecTree])
-> (SpecTransformation -> Config -> [SpecTree] -> [SpecTree])
-> Maybe SpecTransformation
-> Config
-> [SpecTree]
-> [SpecTree]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (\ Config
_ -> [SpecTree] -> [SpecTree]
forall a. a -> a
id) SpecTransformation -> Config -> [SpecTree] -> [SpecTree]
unSpecTransformation (Maybe SpecTransformation -> Config -> [SpecTree] -> [SpecTree])
-> (Config -> Maybe SpecTransformation)
-> Config
-> Config
-> [SpecTree]
-> [SpecTree]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config -> Maybe SpecTransformation
forall value. Typeable value => Config -> Maybe value
getAnnotation

addSpecTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> Config -> Config
addSpecTransformation :: (Config -> [SpecTree] -> [SpecTree]) -> Config -> Config
addSpecTransformation Config -> [SpecTree] -> [SpecTree]
f Config
config = (Config -> [SpecTree] -> [SpecTree]) -> Config -> Config
setSpecTransformation (\ Config
c -> Config -> [SpecTree] -> [SpecTree]
f Config
c ([SpecTree] -> [SpecTree])
-> ([SpecTree] -> [SpecTree]) -> [SpecTree] -> [SpecTree]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Config -> Config -> [SpecTree] -> [SpecTree]
getSpecTransformation Config
config Config
c) Config
config

applySpecTransformation :: Core.Config -> [SpecTree] -> [SpecTree]
applySpecTransformation :: Config -> [SpecTree] -> [SpecTree]
applySpecTransformation Config
config = Config -> Config -> [SpecTree] -> [SpecTree]
getSpecTransformation Config
config Config
config