From d63c8c43c63151b76310fff2d04a28c86b1ba721 Mon Sep 17 00:00:00 2001 From: Marko Andjelic Date: Tue, 27 Jan 2026 20:36:58 +0000 Subject: [PATCH] Add testing suite --- test/Spec.hs | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 test/Spec.hs diff --git a/test/Spec.hs b/test/Spec.hs new file mode 100644 index 0000000..7cd6f49 --- /dev/null +++ b/test/Spec.hs @@ -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