1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/test/Reg/Parse/Base.hs
Jan Mas Rovira e0ae356cd7
Use prettyString instead of show . pretty (#2711)
Use `prettyString` instead of relying on `Show` instance for `Doc a` so
that it is more consistent with `prettyText`.
2024-04-12 10:26:54 +02:00

33 lines
1.0 KiB
Haskell

module Reg.Parse.Base where
import Base
import Juvix.Compiler.Reg.Data.InfoTable
import Juvix.Compiler.Reg.Pretty
import Juvix.Compiler.Reg.Translation.FromSource
import Juvix.Data.PPOutput
regParseAssertion :: Path Abs File -> (String -> IO ()) -> Assertion
regParseAssertion mainFile step = do
step "Parse"
r <- parseFile mainFile
case r of
Left err -> assertFailure (prettyString err)
Right tab -> do
withTempDir'
( \dirPath -> do
let outputFile = dirPath <//> $(mkRelFile "out.out")
step "Print"
writeFileEnsureLn outputFile (ppPrint tab tab)
step "Parse printed"
r' <- parseFile outputFile
case r' of
Left err -> assertFailure (prettyString err)
Right tab' -> do
assertBool ("Check: print . parse = print . parse . print . parse") (ppPrint tab tab == ppPrint tab' tab')
)
parseFile :: Path Abs File -> IO (Either MegaparsecError InfoTable)
parseFile f = do
s <- readFile f
return (runParser f s)