From dc512e0ec4b351e9bde067e4d08b8f50ebd5ce51 Mon Sep 17 00:00:00 2001 From: Krasimir Angelov Date: Sun, 13 Sep 2026 16:21:56 +0200 Subject: [PATCH] add testsuite for parsing --- src/runtime/haskell/pgf2.cabal | 10 +++++++++ src/runtime/haskell/tests/parsing.hs | 31 ++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 src/runtime/haskell/tests/parsing.hs diff --git a/src/runtime/haskell/pgf2.cabal b/src/runtime/haskell/pgf2.cabal index 6c3ba549f..44d4260ad 100644 --- a/src/runtime/haskell/pgf2.cabal +++ b/src/runtime/haskell/pgf2.cabal @@ -75,6 +75,16 @@ test-suite linearization containers, pgf2 +test-suite parsing + type: exitcode-stdio-1.0 + main-is: tests/parsing.hs + default-language: Haskell2010 + build-depends: + base, + HUnit >= 1.6.1.0, + containers, + pgf2 + test-suite typechecking type: exitcode-stdio-1.0 main-is: tests/typechecking.hs diff --git a/src/runtime/haskell/tests/parsing.hs b/src/runtime/haskell/tests/parsing.hs new file mode 100644 index 000000000..c189d720d --- /dev/null +++ b/src/runtime/haskell/tests/parsing.hs @@ -0,0 +1,31 @@ +import Test.HUnit +import PGF2 +import qualified Data.Map as Map + +main = do + gr <- readPGF "tests/basic.pgf" + let Just cnc = Map.lookup "basic_cnc" (languages gr) + runTestTTAndExit $ + TestList + [TestCase (assertParseOk gr cnc "zero" [("intLit 0",1.609438),("c z",2.3025851)] "0") + ,TestCase (assertParseOk gr cnc "one" [("intLit 1",1.609438),("c (s ?)",2.3025851)] "1") + ,TestCase (assertParseOk gr cnc "two" [("c (s (s ?))",2.9957323)] "1 + 1") + ,TestCase (assertParseFail gr cnc "needs-bind" "1+1") + ,TestCase (assertParseOk gr cnc "int" [("intLit 128",1.609438)] "128") + ,TestCase (assertParseOk gr cnc "neg-int" [("intLit -128",1.609438)] "-128") + ,TestCase (assertParseOk gr cnc "float" [("floatLit 3.14",1.609438)] "3.14") + ,TestCase (assertParseOk gr cnc "neg-float" [("floatLit -3.14",1.609438)] "-3.14") + ,TestCase (assertParseOk gr cnc "string" [("stringLit \"abc\"",1.609438)] "abc") + ,TestCase (assertParseFail gr cnc "dwo-dots" "3.1.4") + ] + +assertParseOk gr cnc name expr_strs str = + case parse cnc (startCat gr) str of + ParseOk es -> let exp_es = [(e,prob) | (expr_str,prob) <- expr_strs, Just e <- [readExpr expr_str]] + in assertEqual name exp_es es + _ -> assertFailure (name++": the expression is not readable") + +assertParseFail gr cnc name str = + case parse cnc (startCat gr) str of + ParseOk es -> assertFailure (name++": the string should not have been parsable") + ParseFailed _ _ -> return ()