mdoc-0.3.2.0: test/Mdoc/Test/Render.hs
-- |
--
-- Module : Mdoc.Test.Render
-- Copyright : (c) 2026 Patrick Brisbin
-- License : AGPL-3
-- Maintainer : pbrisbin@gmail.com
-- Stability : experimental
-- Portability : POSIX
module Mdoc.Test.Render
( shouldRender
, prettyDescribeds
, prettyDescribed
, renderPlain
) where
import Mdoc.Prelude
import Data.Text qualified as T
import Mdoc.Data.Described
import Mdoc.Pretty
import Test.Hspec
shouldRender :: (HasCallStack, Pretty a) => a -> [Text] -> Expectation
shouldRender a lns =
renderPlain (pretty a) `shouldBe` T.intercalate "\n" lns
infix 1 `shouldRender`
prettyDescribeds :: Pretty a => [Described a] -> Doc ann
prettyDescribeds = vsep . map prettyDescribed
-- | @Described@ is rendered to JSON and formatted in-template, so we don't want
-- to have a misleading 'Pretty' instance. So we use this instead.
prettyDescribed :: Pretty a => Described a -> Doc ann
prettyDescribed d = vsep $ catMaybes [Just $ ".It" <+> pretty d.item, pretty <$> d.help]