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

Add tests for functor expression parser

parent 62a88a36
......@@ -74,6 +74,7 @@ test-suite spec
, Data.Algorithm.PossibleMajorityCandidateSpec
, Data.BlockQueueSpec
, Data.PartitionSpec
, FunctorExpressionSpec
default-language: Haskell2010
build-depends: base
, hspec
......@@ -82,6 +83,8 @@ test-suite spec
, vector-algorithms
, bytestring
, text
, megaparsec
, hspec-megaparsec
, ma
test-suite doctests
......
......@@ -2,7 +2,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE OverloadedStrings #-}
module Data.Functors.FixedProduct (fixedproduct) where
module Data.Functors.FixedProduct (FixedProduct(..), fixedproduct) where
import Control.Monad (void)
......
......@@ -3,7 +3,7 @@
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TupleSections #-}
module Data.Functors.Powerset (powerset) where
module Data.Functors.Powerset (Powerset(..), powerset) where
import Data.Vector (Vector)
import qualified Data.Vector as V
......
......@@ -5,6 +5,7 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE StandaloneDeriving #-}
module Data.RefinementInterface where
import Data.Text (Text)
......@@ -35,3 +36,5 @@ class (Show h, Show (Label h), Show (H1 h), Show (Weight h), Ord (H1 h), Ord (H3
data SomeRefinementInterface where
SomeRefinementInterface :: RefinementInterface h => h -> SomeRefinementInterface
deriving instance Show SomeRefinementInterface
{-# LANGUAGE OverloadedStrings #-}
module FunctorExpressionSpec (spec) where
import Test.Hspec
import Test.Hspec.Megaparsec
import Data.Text (Text)
import Text.Megaparsec
import Data.Void
import Text.Parser.Functor
import Data.Functors
import Data.RefinementInterface hiding (parse)
spec :: Spec
spec = describe "functorsParser" $ do
it "refuses an empty String" $
parsing `shouldFailOn` ""
it "parses a single X" $
parsing `shouldSucceedOn` "X"
it "parses a complex expression" $
parsing `shouldSucceedOn` "{a,b}xPX"
it "allows arbitrary whitespace" $
parsing `shouldSucceedOn` " { a , b } x P X "
it "binds powerset stronger than fixed product" $
let
Right noParens = parsing "{a,b}xPX"
Right parens = parsing "{a,b}x(PX)"
in
show noParens `shouldBe` show parens
parsing :: Text -> Either (ParseError Char Void) [SomeRefinementInterface]
parsing = parse (functorsParser registeredFunctors) "(input)"
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