2023-11-16 13:20:34 +03:00
|
|
|
module BackendMarkdown.Negative where
|
|
|
|
|
|
|
|
import Base
|
|
|
|
import Juvix.Compiler.Backend.Markdown.Error
|
|
|
|
import Juvix.Parser.Error
|
|
|
|
|
|
|
|
type FailMsg = String
|
|
|
|
|
|
|
|
data NegTest = NegTest
|
|
|
|
{ _name :: String,
|
|
|
|
_relDir :: Path Rel Dir,
|
|
|
|
_file :: Path Rel File,
|
|
|
|
_checkErr :: ParserError -> Maybe FailMsg
|
|
|
|
}
|
|
|
|
|
|
|
|
testDescr :: NegTest -> TestDescr
|
|
|
|
testDescr NegTest {..} =
|
|
|
|
let tRoot = root <//> _relDir
|
|
|
|
file' = tRoot <//> _file
|
|
|
|
in TestDescr
|
|
|
|
{ _testName = _name,
|
|
|
|
_testRoot = tRoot,
|
|
|
|
_testAssertion = Single $ do
|
2023-12-06 20:24:59 +03:00
|
|
|
entryPoint <- testDefaultEntryPointIO tRoot file'
|
2023-12-30 22:15:35 +03:00
|
|
|
result <- testTaggedLockedToIO (runIOEither entryPoint upToParsing)
|
2023-11-16 13:20:34 +03:00
|
|
|
case mapLeft fromJuvixError result of
|
|
|
|
Left (Just err) -> whenJust (_checkErr err) assertFailure
|
|
|
|
Right _ -> assertFailure "Unexpected success."
|
|
|
|
Left Nothing -> assertFailure "Unexpected error."
|
|
|
|
}
|
|
|
|
|
|
|
|
allTests :: TestTree
|
|
|
|
allTests =
|
|
|
|
testGroup
|
|
|
|
"Markdown negative tests"
|
|
|
|
(map (mkTest . testDescr) tests)
|
|
|
|
|
|
|
|
root :: Path Abs Dir
|
|
|
|
root = relToProject $(mkRelDir "tests/negative")
|
|
|
|
|
|
|
|
wrongError :: Maybe FailMsg
|
|
|
|
wrongError = Just "Incorrect error"
|
|
|
|
|
|
|
|
tests :: [NegTest]
|
|
|
|
tests =
|
|
|
|
[ NegTest
|
|
|
|
"Empty file"
|
|
|
|
$(mkRelDir "Markdown")
|
|
|
|
$(mkRelFile "Empty.juvix.md")
|
|
|
|
$ \case
|
|
|
|
ErrMarkdownBackend (ErrNoJuvixCodeBlocks _) -> Nothing
|
|
|
|
_ -> wrongError,
|
|
|
|
NegTest
|
|
|
|
"No Juvix code blocks"
|
|
|
|
$(mkRelDir "Markdown")
|
|
|
|
$(mkRelFile "NoJuvixCodeBlocks.juvix.md")
|
|
|
|
$ \case
|
|
|
|
ErrMarkdownBackend (ErrNoJuvixCodeBlocks _) -> Nothing
|
|
|
|
_ -> wrongError
|
|
|
|
]
|