module Lorentz.Test.Doc
(
testLorentzDoc
, testDeclaresParameter
, testEachEntrypointIsDescribed
, module Michelson.Doc.Test
) where
import Fmt (pretty)
import Test.HUnit (assertBool, assertFailure)
import Lorentz.EntryPoints.Doc
import Michelson.Doc
import Michelson.Doc.Test
import Util.Typeable
testDeclaresParameter :: DocTest
testDeclaresParameter =
mkDocTest "Contract parameter is documented" $
\contractDoc ->
assertBool "No doc items describing contract parameter found" $
or $ forEachContractLayer contractDoc check
where
check Nothing _ = False
check (Just sdi) _ =
case sdi of
SomeDocItem (castIgnoringPhantom -> Just DEntryPoint{}) -> True
_ -> False
testEachEntrypointIsDescribed :: DocTest
testEachEntrypointIsDescribed =
mkDocTest "Each entrypoint has 'DDescription'" $
\contractDoc ->
sequence_ . forEachContractLayer contractDoc $ \mDocItem block ->
runMaybeT $ do
SomeDocItem docItem <- MaybeT . pure $ mDocItem
dep@DEntryPoint{} <- MaybeT . pure $ castIgnoringPhantom docItem
Nothing <- pure $ lookupDocBlockSection @DDescription block
MaybeT . assertFailure $
"Entrypoint '" <> pretty (depName dep) <> "' does not contain \
\description.\n\
\Put `doc $ DDescription \"text\"` in the entrypoint logic to fix this."
testLorentzDoc :: [DocTest]
testLorentzDoc = mconcat
[ testDocBasic
, [ testDeclaresParameter
, testEachEntrypointIsDescribed
]
]