packages feed

mdoc-0.1.1.0: test/Mdoc/Test/Render.hs

module Mdoc.Test.Render
  ( IsMdoc (..)
  , shouldRender
  ) where

import Mdoc.Prelude

import Mdoc
import Mdoc.MdocLine
import Mdoc.Pretty
import Test.Hspec

class IsMdoc a where
  toMdoc :: a -> Mdoc

instance IsMdoc Mdoc where
  toMdoc = id

instance IsMdoc [MdocLine] where
  toMdoc = Mdoc

instance IsMdoc (NonEmpty MdocLine) where
  toMdoc = Mdoc . toList

instance IsMdoc MdocLine where
  toMdoc = Mdoc . pure

shouldRender :: IsMdoc a => a -> [Text] -> Expectation
shouldRender a lns = actual `shouldBe` expected
 where
  actual = renderPlain $ prettyMdoc $ toMdoc a
  expected = mconcat $ map (<> "\n") lns

infix 1 `shouldRender`