module FreeC.Test.Expectations
(
shouldBeSimilarTo
, shouldNotBeSimilarTo
, prettyShouldBe
) where
import Test.Hspec
import FreeC.IR.Similar
import FreeC.Pretty
shouldBeSimilarTo :: (Similar a, Pretty a) => a -> a -> Expectation
shouldBeSimilarTo n m
| n `similar` m = return ()
| otherwise = expectationFailure
$ showPretty
$ prettyString "Expected similar nodes, but" <$$> line
<> indent 2 (pretty n)
<> line <$$> prettyString "is not similar to" <$$> line
<> indent 2 (pretty m)
<> line
shouldNotBeSimilarTo :: (Similar a, Pretty a) => a -> a -> Expectation
shouldNotBeSimilarTo n m
| n `notSimilar` m = return ()
| otherwise = expectationFailure
$ showPretty
$ prettyString "Expected dissimilar nodes, but" <$$> line
<> indent 2 (pretty n)
<> line <$$> prettyString "is similar to" <$$> line
<> indent 2 (pretty m)
<> line
prettyShouldBe :: (Pretty a, Pretty b) => a -> b -> Expectation
prettyShouldBe x y = let discardWhitespace = unwords . words
prettyX = discardWhitespace (showPretty x)
prettyY = discardWhitespace (showPretty y)
in prettyX `shouldBe` prettyY