-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module Tree.Parse where | ||
|
||
import Base | ||
import Tree.Parse.Positive qualified as P | ||
|
||
allTests :: TestTree | ||
allTests = testGroup "JuvixTree parsing" [P.allTests] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Tree.Parse.Base where | ||
|
||
import Base | ||
import Juvix.Compiler.Tree.Data.InfoTable | ||
import Juvix.Compiler.Tree.Pretty | ||
import Juvix.Compiler.Tree.Translation.FromSource | ||
import Juvix.Data.PPOutput | ||
|
||
treeParseAssertion :: Path Abs File -> (String -> IO ()) -> Assertion | ||
treeParseAssertion 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module Tree.Parse.Positive where | ||
|
||
import Base | ||
import Tree.Eval.Positive qualified as Eval | ||
import Tree.Parse.Base | ||
|
||
type PosTest = Eval.PosTest | ||
|
||
testDescr :: PosTest -> TestDescr | ||
testDescr Eval.PosTest {..} = | ||
let tRoot = Eval.root <//> _relDir | ||
file' = tRoot <//> _file | ||
in TestDescr | ||
{ _testName = _name, | ||
_testRoot = tRoot, | ||
_testAssertion = Steps $ treeParseAssertion file' | ||
} | ||
|
||
allTests :: TestTree | ||
allTests = | ||
testGroup | ||
"JuvixTree parsing positive tests" | ||
(map (mkTest . testDescr) Eval.tests) |