Examples.hs 1.1 KB
Newer Older
1
2
3
4
5
6
7
{-# LANGUAGE LambdaCase #-}

module Main (main) where

import           Control.Monad.ST
import           Data.List

8
import           Data.List.Extra (dropSuffix)
9
10
11
12
13
14
15
16
17
18
19
import qualified Data.Text as T
import           System.Directory
import           Test.Hspec

import           MA.Algorithm
import           MA.Parser
import           MA.PartitionPrinter

main :: IO ()
main = do
  let exampleDir = "examples/"
20
  files <- filter isOutput <$> listDirectory exampleDir
21
22
23
24
25
26
27
28
29
30
31
32
  hspec $ testFiles (map (exampleDir ++) files)

outSuffix :: String
outSuffix = ".out"

isOutput :: FilePath -> Bool
isOutput = (outSuffix `isSuffixOf`)

testFiles :: [FilePath] -> Spec
testFiles = mapM_ testFile

testFile :: FilePath -> Spec
33
34
35
36
37
testFile outfile =
  let file = dropSuffix outSuffix outfile
   in specify file $ do
        output <- readFile (file ++ outSuffix)
        process file `shouldReturn` output
38
39
40
41
42
43
44

process :: FilePath -> IO String
process file = readCoalgebraFromFile file >>= \case
  Left err -> return err
  Right (f, (symTab, enc)) -> do
    partition <- stToIO (refine f enc)
    return $ T.unpack (showPartition enc symTab partition)