Add testing suite
This commit is contained in:
parent
2c06dda760
commit
d63c8c43c6
1 changed files with 46 additions and 0 deletions
46
test/Spec.hs
Normal file
46
test/Spec.hs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
import System.Environment (getArgs)
|
||||
import Control.Monad.Reader (runReaderT)
|
||||
import System.Exit (exitFailure)
|
||||
|
||||
import EpubParser (openEpub, resolveSpine, getChapter, EpubEnv)
|
||||
|
||||
-- Run this as: cabal run svitak-test -- "path/to/book.epub"
|
||||
|
||||
main :: IO ()
|
||||
main = do
|
||||
args <- getArgs
|
||||
case args of
|
||||
[path] -> runRawDump path
|
||||
_ -> do
|
||||
putStrLn "cabal run svitak-test -- \"path/to/book.epub\""
|
||||
exitFailure
|
||||
|
||||
runRawDump :: FilePath -> IO ()
|
||||
runRawDump path = do
|
||||
putStrLn $ "Testing EPUB: " ++ path
|
||||
result <- openEpub path
|
||||
case result of
|
||||
Left err -> do
|
||||
putStrLn $ "Failed to open: " ++ err
|
||||
exitFailure
|
||||
Right env -> do
|
||||
spine <- resolveSpineList env
|
||||
putStrLn $ "Spine resolved. Found " ++ show (length spine) ++ " items."
|
||||
mapM_ (dumpChapter env) spine
|
||||
|
||||
resolveSpineList :: EpubEnv -> IO [FilePath]
|
||||
resolveSpineList env = runReaderT resolveSpine env
|
||||
|
||||
dumpChapter :: EpubEnv -> FilePath -> IO ()
|
||||
dumpChapter env filename = do
|
||||
putStrLn $ "\n START OF FILE: " ++ filename
|
||||
putStrLn (replicate 40 '-')
|
||||
|
||||
tags <- runReaderT (getChapter filename) env
|
||||
|
||||
mapM_ print tags
|
||||
|
||||
putStrLn (replicate 40 '-')
|
||||
putStrLn $ "END OF FILE: " ++ filename
|
||||
Loading…
Reference in a new issue