1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
module BNFC.GetCFSpec where
import Test.Hspec
-- SUT:
import BNFC.GetCF
import BNFC.CF
import qualified BNFC.Abs as Abs
spec :: Spec
spec = do
describe "transItem" $ do
it "translate a non-terminal" $
transItem (Abs.NTerminal (Abs.IdCat (npIdentifier "Foo3")))
`shouldBe` [Left (CoercCat "Foo" 3)]
it "translate a terminal" $
transItem (Abs.Terminal "foobar") `shouldBe` [Right "foobar"]
it "skips empty terminals" $
transItem (Abs.Terminal "") `shouldBe` []
it "splits multiwords terminals" $
transItem (Abs.Terminal "foo bar") `shouldBe` [Right "foo", Right "bar"]
describe "checkRule" $ do
it "returns an error if the rule uses an unknown category" $ do
let rule = npRule "Foo" (Cat "Bar") [Left (Cat "Baz")] Parsable
cf = CFG [] mempty [] [] [] [] [rule] mempty
expected =
"no production for Baz, appearing in rule\n Foo. Bar ::= Baz"
checkRule cf rule `shouldBe` Just expected
|