-- | @QuickCheck@ related utilities.
module Data.TreeDiff.QuickCheck (
    ediffEq,
    ) where

import Data.TreeDiff
import System.Console.ANSI (SGR (Reset), setSGRCode)
import Test.QuickCheck     (Property, counterexample)

-- | A variant of '===', which outputs a diff when values are inequal.
ediffEq :: (Eq a, ToExpr a) => a -> a -> Property
ediffEq :: forall a. (Eq a, ToExpr a) => a -> a -> Property
ediffEq a
x a
y = String -> Bool -> Property
forall prop. Testable prop => String -> prop -> Property
counterexample
    ([SGR] -> String
setSGRCode [SGR
Reset] String -> String -> String
forall a. [a] -> [a] -> [a]
++ Doc -> String
forall a. Show a => a -> String
show (Edit EditExpr -> Doc
ansiWlEditExpr (Edit EditExpr -> Doc) -> Edit EditExpr -> Doc
forall a b. (a -> b) -> a -> b
$ a -> a -> Edit EditExpr
forall a. ToExpr a => a -> a -> Edit EditExpr
ediff a
x a
y))
    (a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
y)