Skip to content

Commit

Permalink
Add negative tests for parser
Browse files Browse the repository at this point in the history
  • Loading branch information
paulcadman committed Apr 17, 2024
1 parent 7c57581 commit 1b88f30
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module Juvix.Compiler.Backend.Markdown.Data.MkJuvixBlockOptions where
import Juvix.Parser.Error.Base
import Juvix.Prelude.Base
import Juvix.Prelude.Parsing hiding (runParser)
import Juvix.Prelude.Path
import Text.Megaparsec qualified as P
import Text.Megaparsec.Char.Lexer qualified as L

Expand All @@ -24,8 +25,8 @@ renderJuvixBlockOptions = \case
MkJuvixBlockOptionsShow -> ""
MkJuvixBlockOptionsExtractModule -> optionExtractModuleStatements

parseJuvixBlockOptions :: Text -> Either MegaparsecError MkJuvixBlockOptions
parseJuvixBlockOptions = mapLeft MegaparsecError . P.runParser parseOptions ""
parseJuvixBlockOptions :: Path Abs File -> Text -> Either MegaparsecError MkJuvixBlockOptions
parseJuvixBlockOptions p = mapLeft MegaparsecError . P.runParser parseOptions (toFilePath p)

type Parser = P.Parsec Void Text

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ go fname = do
modify (set processingStateMk r)
MkConcat lS <$> go fname
MkJuvixCodeBlock j -> do
opts <- case parseJuvixBlockOptions (j ^. juvixCodeBlockOptions) of
opts <- case parseJuvixBlockOptions fname (j ^. juvixCodeBlockOptions) of
Left e ->
throw
( ErrInvalidCodeBlockAttribtues
Expand Down
7 changes: 7 additions & 0 deletions test/BackendMarkdown/Negative.hs
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ tests =
$(mkRelFile "InvalidExtractModuleBlockNotJustModule.juvix.md")
$ \e -> case fromJuvixError e of
Just (ErrInvalidExtractModuleBlock _) -> Nothing
_ -> wrongError e,
NegTest
"code block with both hide and extract-module-statements"
$(mkRelDir "Markdown")
$(mkRelFile "InvalidCodeBlockExtraAttribute.juvix.md")
$ \e -> case fromJuvixError e of
Just (ErrInvalidCodeBlockAttribtues _) -> Nothing
_ -> wrongError e
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Title

```juvix
module InvalidExtractModuleBlockExtraAttribute;
```

```juvix hide extract-module-statements
type T := t;
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Title

```juvix
module InvalidExtractModuleBlockUnknownAttribute;
```

```juvix invalid-attribute
type T := t;
```

0 comments on commit 1b88f30

Please sign in to comment.