Add testing suite

This commit is contained in:
Marko Andjelic 2026-01-27 20:36:58 +00:00
commit d63c8c43c6

46
test/Spec.hs Normal file
View 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