From 0fa9df7ea8f5dc68036defc23fa629793b070d6c Mon Sep 17 00:00:00 2001 From: Kangjing Huang Date: Sun, 26 Nov 2023 17:25:38 -0500 Subject: [PATCH] First unit test for tree-sitter backend --- source/test/BNFC/Backend/TreeSitterSpec.hs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 source/test/BNFC/Backend/TreeSitterSpec.hs diff --git a/source/test/BNFC/Backend/TreeSitterSpec.hs b/source/test/BNFC/Backend/TreeSitterSpec.hs new file mode 100644 index 00000000..1651a10a --- /dev/null +++ b/source/test/BNFC/Backend/TreeSitterSpec.hs @@ -0,0 +1,25 @@ +module BNFC.Backend.TreeSitterSpec where + +import BNFC.Options +import BNFC.GetCF + +import Test.Hspec +import BNFC.Hspec + +import BNFC.Backend.TreeSitter -- SUT + +calcOptions = defaultOptions { lang = "Calc" } +getCalc = parseCF calcOptions TargetTreeSitter $ + unlines [ "EAdd. Exp ::= Exp \"+\" Exp1 ;" + , "ESub. Exp ::= Exp \"-\" Exp1 ;" + , "EMul. Exp1 ::= Exp1 \"*\" Exp2 ;" + , "EDiv. Exp1 ::= Exp1 \"/\" Exp2 ;" + , "EInt. Exp2 ::= Integer ;" + , "coercions Exp 2 ;" ] + +spec = do + + describe "Tree-Sitter backend" $ do + it "creates the grammar.js file" $ do + calc <- getCalc + makeTreeSitter calcOptions calc `shouldGenerate` "grammar.js"