packages feed

mdoc-0.1.0.0: test/MdocSpec.hs

-- |
--
-- Module      : MdocSpec
-- Copyright   : (c) 2026 Patrick Brisbin
-- License     : AGPL-3
-- Maintainer  : pbrisbin@gmail.com
-- Stability   : experimental
-- Portability : POSIX
module MdocSpec
  ( spec
  ) where

import Mdoc.Prelude

import Mdoc
import Mdoc.MacroArg
import Mdoc.MacroName
import Mdoc.MdocLine
import Mdoc.Test.Parse
import Test.Hspec

spec :: Spec
spec = do
  describe "parseMdoc" $ do
    it "parses a complete example" $ do
      parseTest
        parseMdoc
        [ ".Dd $Mdocdate$"
        , ".Dt PROGNAME section"
        , ".Os"
        , ".Sh NAME"
        , ".Nm progname"
        , ".Nd one line about what it does"
        , ".\\\" .Sh LIBRARY"
        , ".\\\" For sections 2, 3, and 9 only."
        , ".\\\" Not used in OpenBSD."
        , ".Sh SYNOPSIS"
        , ".Nm progname"
        , ".Op Fl options"
        , ".Ar"
        , ".Sh DESCRIPTION"
        , "The"
        , ".Nm"
        , "utility processes files ..."
        , ".\\\" .Sh CONTEXT"
        , ".\\\" For section 9 functions only."
        , ".\\\" .Sh IMPLEMENTATION NOTES"
        , ".\\\" Not used in OpenBSD."
        , ".\\\" .Sh RETURN VALUES"
        , ".\\\" For sections 2, 3, and 9 function return values only."
        , ".\\\" .Sh ENVIRONMENT"
        , ".\\\" For sections 1, 6, 7, and 8 only."
        , ".\\\" .Sh FILES"
        , ".\\\" .Sh EXIT STATUS"
        , ".\\\" For sections 1, 6, and 8 only."
        , ".\\\" .Sh EXAMPLES"
        , ".\\\" .Sh DIAGNOSTICS"
        , ".\\\" For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only."
        , ".\\\" .Sh ERRORS"
        , ".\\\" For sections 2, 3, 4, and 9 errno settings only."
        , ".\\\" .Sh SEE ALSO"
        , ".\\\" .Xr foobar 1"
        , ".\\\" .Sh STANDARDS"
        , ".\\\" .Sh HISTORY"
        , ".\\\" .Sh AUTHORS"
        , ".\\\" .Sh CAVEATS"
        , ".\\\" .Sh BUGS"
        , ".\\\" .Sh SECURITY CONSIDERATIONS"
        , ".\\\" Not used in OpenBSD."
        ]
        $ Mdoc
          { lines =
              [ MacroLine Dd [Mdocdate Nothing]
              , MacroLine Dt ["PROGNAME", "section"]
              , MacroLine Os []
              , MacroLine Sh ["NAME"]
              , MacroLine Nm ["progname"]
              , MacroLine Nd ["one", "line", "about", "what", "it", "does"]
              , Comment ".Sh LIBRARY"
              , Comment "For sections 2, 3, and 9 only."
              , Comment "Not used in OpenBSD."
              , MacroLine Sh ["SYNOPSIS"]
              , MacroLine Nm ["progname"]
              , MacroLine Op [Callable Fl, "options"]
              , MacroLine Ar []
              , MacroLine Sh ["DESCRIPTION"]
              , TextLine "The"
              , MacroLine Nm []
              , TextLine "utility processes files ..."
              , Comment ".Sh CONTEXT"
              , Comment "For section 9 functions only."
              , Comment ".Sh IMPLEMENTATION NOTES"
              , Comment "Not used in OpenBSD."
              , Comment ".Sh RETURN VALUES"
              , Comment "For sections 2, 3, and 9 function return values only."
              , Comment ".Sh ENVIRONMENT"
              , Comment "For sections 1, 6, 7, and 8 only."
              , Comment ".Sh FILES"
              , Comment ".Sh EXIT STATUS"
              , Comment "For sections 1, 6, and 8 only."
              , Comment ".Sh EXAMPLES"
              , Comment ".Sh DIAGNOSTICS"
              , Comment "For sections 1, 4, 6, 7, 8, and 9 printf/stderr messages only."
              , Comment ".Sh ERRORS"
              , Comment "For sections 2, 3, 4, and 9 errno settings only."
              , Comment ".Sh SEE ALSO"
              , Comment ".Xr foobar 1"
              , Comment ".Sh STANDARDS"
              , Comment ".Sh HISTORY"
              , Comment ".Sh AUTHORS"
              , Comment ".Sh CAVEATS"
              , Comment ".Sh BUGS"
              , Comment ".Sh SECURITY CONSIDERATIONS"
              , Comment "Not used in OpenBSD."
              ]
          }