module Test.Hspec.Core.Tree (
SpecTree
, Tree (..)
, Item (..)
, Location (..)
, LocationAccuracy (..)
, specGroup
, specItem
) where
import Prelude ()
import Test.Hspec.Compat
import Test.Hspec.Core.Example
data Tree c a =
Node String [Tree c a]
| NodeWithCleanup c [Tree c a]
| Leaf a
deriving Functor
instance Foldable (Tree c) where
foldMap = go
where
go :: Monoid m => (a -> m) -> Tree c a -> m
go f t = case t of
Node _ xs -> foldMap (foldMap f) xs
NodeWithCleanup _ xs -> foldMap (foldMap f) xs
Leaf x -> f x
instance Traversable (Tree c) where
sequenceA = go
where
go :: Applicative f => Tree c (f a) -> f (Tree c a)
go t = case t of
Node label xs -> Node label <$> sequenceA (map go xs)
NodeWithCleanup action xs -> NodeWithCleanup action <$> sequenceA (map go xs)
Leaf a -> Leaf <$> a
type SpecTree a = Tree (ActionWith a) (Item a)
data Item a = Item {
itemRequirement :: String
, itemLocation :: Maybe Location
, itemIsParallelizable :: Bool
, itemExample :: Params -> (ActionWith a -> IO ()) -> ProgressCallback -> IO Result
}
data Location = Location {
locationFile :: String
, locationLine :: Int
, locationColumn :: Int
, locationAccuracy :: LocationAccuracy
} deriving (Eq, Show)
data LocationAccuracy =
ExactLocation |
BestEffort
deriving (Eq, Show)
specGroup :: String -> [SpecTree a] -> SpecTree a
specGroup s = Node msg
where
msg
| null s = "(no description given)"
| otherwise = s
specItem :: Example a => String -> a -> SpecTree (Arg a)
specItem s e = Leaf $ Item requirement Nothing False (evaluateExample e)
where
requirement
| null s = "(unspecified behavior)"
| otherwise = s