Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Node.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data Node
| SinglelineComment Text
| MultilineComment Text
| Null
deriving (Eq, Show)
deriving (Eq, Read, Show)

isCommentNode :: Node -> Bool
isCommentNode (MultilineComment _) = True
Expand Down
8 changes: 3 additions & 5 deletions test/Parsing/DSLSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ module Parsing.DSLSpec (
spec,
) where

import Control.Monad (forM_)
import Data.ByteString (ByteString)
import Data.List (isSuffixOf)
import Data.String (fromString)
Expand Down Expand Up @@ -59,10 +58,9 @@ ruleSetSpecs :: Spec
ruleSetSpecs = do
inputFiles <-
runIO $ filter (isSuffixOf ".jbfl") <$> getDirectoryContents "examples/jbfl"
let outputFile f = "examples/ast/jbfl/" ++ takeWhile (/= '.') f ++ ".hs"
forM_ inputFiles $ \inFile -> do
let outFile = outputFile inFile
ruleSetSpec inFile outFile
let outputFile inFile = "examples/ast/jbfl/" ++ takeWhile (/= '.') inFile ++ ".hs"
testInputFile inFile = ruleSetSpec inFile (outputFile inFile)
mapM_ testInputFile inputFiles

expLabels :: [String] -> ET ByteString
expLabels = foldMap elabel
Expand Down
28 changes: 27 additions & 1 deletion test/Parsing/JbeamSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ module Parsing.JbeamSpec (
spec,
) where

import Data.List (isSuffixOf)
import Data.Vector (fromList)
import Parsing.Common.Helpers
import Parsing.Jbeam
import Parsing.ParsingTestHelpers
import SpecHelper
import System.Directory (getDirectoryContents)
import Test.Hspec.Megaparsec
import Text.Megaparsec

import Data.ByteString qualified as BS (
readFile,
)

numberSpec :: [(String, Node)]
numberSpec = [("123", Number 123), ("123.123", Number 123.123)]

Expand Down Expand Up @@ -64,8 +70,28 @@ invalidSpec =
where
expLabels = foldMap elabel ["a valid scalar", "object", "array"]

topNodeSpec :: FilePath -> FilePath -> Spec
topNodeSpec inFilename outFilename = do
let inputPath = "examples/jbeam/" ++ inFilename
input <- runIO $ BS.readFile inputPath
output <- runIO $ readFile outFilename
let desc = "should parse contents of " ++ inFilename ++ " to AST in " ++ outFilename
describe desc . works $
parseNodes input `shouldBe` Right (read output)

topNodeSpecs :: Spec
topNodeSpecs = do
inputFiles <-
runIO $ filter (isSuffixOf ".jbeam") <$> getDirectoryContents "examples/jbeam"
let outputFile inFile = "examples/ast/jbeam/" ++ takeWhile (/= '.') inFile ++ ".hs"
testInputFile inFile = topNodeSpec inFile (outputFile inFile)
mapM_ testInputFile inputFiles

spec :: Spec
spec = sequence_ $ invalidSpec : map (applyParserSpec nodeParser) specs
spec = do
mapM_ (applyParserSpec nodeParser) specs
invalidSpec
topNodeSpecs
where
specs =
concat
Expand Down
4 changes: 2 additions & 2 deletions tools/dump_ast/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dumpJbflAST dir filename = do
contents <- BL.readFile (dir ++ "/" ++ filename)
case parseDSL (BL.toStrict contents) of
Right rs -> dump rs
Left _ -> error "error :("
Left _ -> error $ "error " ++ filename
where
dump contents =
let outFile = "examples/ast/jbfl/" ++ takeWhile (/= '.') filename ++ ".hs"
Expand All @@ -47,7 +47,7 @@ dumpJbeamAST dir filename = do
contents <- BL.readFile (dir ++ "/" ++ filename)
case parseNodes (BL.toStrict contents) of
Right rs -> dump rs
Left _ -> error "error :("
Left _ -> error $ "error " ++ filename
where
dump contents =
let outFile = "examples/ast/jbeam/" ++ takeWhile (/= '.') filename ++ ".hs"
Expand Down