Commit b1d2a7f1 authored by Bastian Kauschke's avatar Bastian Kauschke

update tests

parent 80ad7fed
......@@ -11,6 +11,7 @@ import Type.Reflection
import qualified Data.Vector as V
import Copar.Coalgebra.Parser
import Copar.Coalgebra.Printer
import Copar.FunctorExpression.Sorts
import Copar.FunctorExpression.Type
import Copar.FunctorDescription
......@@ -97,6 +98,8 @@ instance RefinementInterface Identity where
update = undefined
instance ParseMorphism Identity where
parseMorphismPoint = undefined
instance PrintMorphism Identity where
printMorphismPoint = undefined
data Twice a = Twice a a
deriving (Functor, Foldable, Traversable)
......@@ -120,6 +123,8 @@ instance RefinementInterface Twice where
update = undefined
instance ParseMorphism Twice where
parseMorphismPoint = undefined
instance PrintMorphism Twice where
printMorphismPoint = undefined
instance Show1 Twice where
liftShowsPrec = undefined
......@@ -139,6 +144,8 @@ instance FunctorDescription Maybe where
instance RefinementInterface Maybe where
init = undefined
update = undefined
instance PrintMorphism Maybe where
printMorphismPoint = undefined
instance ParseMorphism Maybe where
parseMorphismPoint = undefined
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
module Main (main) where
import Control.Monad.ST
import Control.Exception (evaluate)
import Data.List
import Data.Proxy
import Data.List.Extra (dropSuffix)
import qualified Data.Text as T
import qualified Data.Text.Lazy as LT
import qualified Data.Text.Lazy.Builder as Build
import System.Directory
import Test.Hspec
import Copar.Algorithm
import qualified Copar.Parser as P
import Copar.PartitionPrinter
import Copar.CoalgebraPrinter
import Copar.FunctorPrinter
import Copar.Functors.SomeFunctor
import Copar.FunctorExpression.Desorting (Desorted)
import Copar.FunctorExpression.Sorts (sortTable)
main :: IO ()
main = do
let exampleDir = "examples/"
files <- filter isOutput <$> listDirectory exampleDir
hspec $ testFiles (map (exampleDir ++) files)
files <- listDirectory exampleDir
hspec $ testFiles testFileRefine (map (exampleDir ++) (filter isOutput files))
hspec $ testFiles testFileMinimize (map (exampleDir ++) (filter isTestFile files))
outSuffix :: String
outSuffix = ".out"
......@@ -26,22 +37,46 @@ outSuffix = ".out"
isOutput :: FilePath -> Bool
isOutput = (outSuffix `isSuffixOf`)
testFiles :: [FilePath] -> Spec
testFiles = mapM_ testFile
isTestFile :: FilePath -> Bool
isTestFile path = (not $ isOutput path) && (not $ ".md" `isSuffixOf` path)
testFile :: FilePath -> Spec
testFile outfile =
testFiles :: (FilePath -> Spec) -> [FilePath] -> Spec
testFiles testFile = mapM_ testFile
testFileRefine :: FilePath -> Spec
testFileRefine outfile =
let file = dropSuffix outSuffix outfile
in specify file $ do
in specify ("refine " <> file) $ do
output <- readFile (file ++ outSuffix)
process file `shouldReturn` output
where
-- | FIXME: Run each example twice, once with and once without transformations.
process :: FilePath -> IO String
process file =
P.readFile P.defaultConfig file
>>= \case
Left err -> return err
Right (f, (symTab, enc)) -> do
partition <- stToIO (refine (Proxy :: Proxy (Desorted SomeFunctor)) enc True)
return $ T.unpack (showPartition enc symTab partition)
-- | FIXME: Run each example twice, once with and once without transformations.
process :: FilePath -> IO String
process file =
P.readFile P.defaultConfig file
>>= \case
Left err -> return err
Right (f, (symTab, enc)) -> do
partition <- stToIO (refine f enc True)
return $ T.unpack (showPartition enc symTab partition)
testFileMinimize :: FilePath -> Spec
testFileMinimize file =
specify ("minimize " <> file) $ do
P.readFile P.defaultConfig file >>=
\case
Left err -> expectationFailure $ "initialParse: " <> err
Right (f, (symTab, enc)) ->
let
coalgebra = Build.fromText (printParseableFunctor f)
<> "\n"
<> printEncoding enc symTab (sortTable f)
reparsed = P.parseCoalgebra P.defaultConfig "(minized)" $ LT.toStrict (Build.toLazyText coalgebra)
in case reparsed of
Left err -> expectationFailure $ "parseMinimized: " <> err
Right (f', (symTab', enc')) -> (
Build.fromText (printParseableFunctor f')
<> "\n"
<> printEncoding enc' symTab' (sortTable f')
) `shouldBe` coalgebra
Markdown is supported
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