Skip to content

Commit

Permalink
First unit test for tree-sitter backend
Browse files Browse the repository at this point in the history
  • Loading branch information
chaserhkj committed Nov 26, 2023
1 parent f1c5101 commit 0fa9df7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions source/test/BNFC/Backend/TreeSitterSpec.hs
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 0fa9df7

Please sign in to comment.