Commit 3c59ac8e authored by Bastian Kauschke's avatar Bastian Kauschke
Browse files

add tests for printParseableFunctor

parent beb6a13d
......@@ -154,6 +154,7 @@ test-suite spec
, Copar.FunctorExpression.ParserSpec
, Copar.FunctorExpression.PrettySpec
, Copar.FunctorExpression.SortsSpec
, Copar.FunctorPrinterSpec
, Copar.Coalgebra.ParserSpec
, Copar.ParserSpec
, Copar.Parser.LexerSpec
......
module Copar.FunctorPrinterSpec (spec) where
import Test.Hspec
import Data.Bifunctor
import Data.Either
import Data.Text (unpack, Text)
import Copar.Functors.SomeFunctor
import Copar.FunctorExpression.Type
import Copar.FunctorExpression.Sorts
import Copar.FunctorPrinter
import Copar.Parser
spec :: Spec
spec = do
printParseableFunctorSpec
printParseableFunctorSpec:: Spec
printParseableFunctorSpec = describe "printParseableFunctor" $ do
let
idFunctor :: FunctorExpression SomeFunctor Sort -> Either String (FunctorExpression SomeFunctor Sort)
idFunctor = parseFunctor "" . printParseableFunctor
it_is_id :: Text -> Spec
it_is_id s = it (unpack ("is the identity for `" <> s <> "`")) $
(parseFunctor "" s) `shouldSatisfy`\res -> (res >>= idFunctor) == res && isRight res
it_is_eq :: Text -> Text -> Spec
it_is_eq s expected = it (unpack ("is the identity for `" <> s <> "`")) $
(printParseableFunctor <$> (parseFunctor "" s) `shouldSatisfy` (\res -> fromRight False ((== expected) <$> res)))
it_is_id "D(PX)"
it_is_id "{n, f}xPX"
it_is_id "D({f,n}xPX)"
it_is_id "D({f,n}xP(DX)^{a, b, c}+({f, n}xX + (Z, min)^({f ,n})))"
it_is_id "(Z, min)^X"
it_is_eq "D(PX)" "D(PX)"
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