File: GetCFSpec.hs

package info (click to toggle)
bnfc 2.9.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,300 kB
  • sloc: haskell: 16,920; yacc: 240; makefile: 91
file content (35 lines) | stat: -rw-r--r-- 1,046 bytes parent folder | download | duplicates (3)
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