Commit b38dd561 authored by Hans-Peter Deifel's avatar Hans-Peter Deifel
Browse files

Add some tests for the symbol table

parent a3bff752
......@@ -137,6 +137,8 @@ test-suite spec
, megaparsec
, hspec-megaparsec
, microlens-platform
, unordered-containers
, containers
, ma
test-suite doctests
......
......@@ -81,7 +81,7 @@ checkUndefinedRefs = use (symbolTable . to M.toList . to (filter isUndefined)) >
where
isUndefined = (==Undefined) . snd . snd
newtype SymbolTable = SymbolTable (M.HashMap State Text)
newtype SymbolTable = SymbolTable { fromSymbolTable :: M.HashMap State Text }
deriving (Show,Eq,Ord)
finalizeState ::
......
......@@ -10,10 +10,12 @@ import Control.Exception (evaluate)
import Type.Reflection
import Data.List (nub)
import qualified Data.Set as S
import qualified Data.Vector as V
import Data.Text (Text)
import Text.Megaparsec
import Lens.Micro.Platform
import qualified Data.HashMap.Strict as HM
import Data.MorphismEncoding (Encoding)
import qualified Data.MorphismEncoding as Encoding
......@@ -81,6 +83,19 @@ parseMorphismsSpec = describe "parseMorphisms" $ do
`shouldBe`
Right [ (1, SomeH1 ("a" :: Text)), (2, SomeH1 ("a" :: Text)) ]
context "the symbol table" $ do
let p x = fromSymbolTable . fst <$> parseMorphisms (Functor 1 (P Variable)) "" x
it "contains the defined symbols" $ do
(HM.elems <$> p "a: []\nb: []\nc: []") `shouldParse` ["a", "b", "c"]
it "maps all symbols to different nodes" $ do
(HM.keys <$> p "a: [b]\nb: [c]\nc: [d]\nd: [a]") `parseSatisfies` allDifferent
allDifferent :: Ord a => [a] -> Bool
allDifferent lst = length (S.fromList lst) == length lst
data Id a = Id a
deriving (Functor)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment