2017-12-28 10:39:47 -05:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
|
|
|
|
|
|
|
module Tests.Writers.Powerpoint (tests) where
|
|
|
|
|
2017-12-28 12:06:38 -08:00
|
|
|
import Control.Exception (throwIO)
|
2017-12-28 10:39:47 -05:00
|
|
|
import Text.Pandoc
|
|
|
|
import Text.Pandoc.Builder
|
|
|
|
import Test.Tasty
|
|
|
|
import Test.Tasty.HUnit
|
|
|
|
import Codec.Archive.Zip
|
|
|
|
import Data.List (isPrefixOf, isSuffixOf)
|
|
|
|
|
|
|
|
----- Number of Slides -----------
|
|
|
|
|
2017-12-28 12:06:38 -08:00
|
|
|
numberOfSlides :: WriterOptions -> Pandoc -> IO Int
|
2017-12-28 10:39:47 -05:00
|
|
|
numberOfSlides opts pd = do
|
2017-12-28 12:06:38 -08:00
|
|
|
mbs <- runIO $
|
|
|
|
do setUserDataDir $ Just "../data"
|
2017-12-28 10:39:47 -05:00
|
|
|
writePowerpoint opts pd
|
2017-12-28 12:06:38 -08:00
|
|
|
case mbs of
|
|
|
|
Left e -> throwIO e
|
|
|
|
Right bs -> do
|
|
|
|
let archive = toArchive bs
|
|
|
|
return $
|
|
|
|
length $
|
|
|
|
filter (isSuffixOf ".xml") $
|
|
|
|
filter (isPrefixOf "ppt/slides/slide") $
|
|
|
|
filesInArchive archive
|
2017-12-28 10:39:47 -05:00
|
|
|
|
|
|
|
testNumberOfSlides :: TestName -> Int -> WriterOptions -> Pandoc -> TestTree
|
|
|
|
testNumberOfSlides name n opts pd =
|
2017-12-28 12:06:38 -08:00
|
|
|
testCase name $ do
|
|
|
|
n' <- numberOfSlides opts pd
|
|
|
|
n' @=? n
|
2017-12-28 10:39:47 -05:00
|
|
|
|
|
|
|
numSlideTests :: TestTree
|
|
|
|
numSlideTests = testGroup "Number of slides in output"
|
|
|
|
[ testNumberOfSlides
|
|
|
|
"simple one-slide deck" 1
|
|
|
|
def
|
|
|
|
(doc $ para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"with metadata (header slide)" 2
|
|
|
|
def
|
|
|
|
(setTitle "My Title" $ doc $ para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With h1 slide (using default slide-level)" 2
|
|
|
|
def
|
|
|
|
(doc $ header 1 "Header" <> para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With h2 slide (using default slide-level)" 2
|
|
|
|
def
|
|
|
|
(doc $ header 1 "Header" <> header 2 "subeader" <> para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With h1 slide (using default slide-level)" 2
|
|
|
|
def
|
|
|
|
(doc $ header 1 "Header" <> para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With h2 slide (using default slide-level)" 2
|
|
|
|
def
|
|
|
|
(doc $ header 1 "Header" <> header 2 "subeader" <> para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With image slide, no header" 3
|
|
|
|
def
|
|
|
|
(doc $
|
|
|
|
para "first slide" <>
|
2017-12-28 12:06:38 -08:00
|
|
|
(para $ image "lalune.jpg" "" "") <>
|
2017-12-28 10:39:47 -05:00
|
|
|
para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With image slide, header" 3
|
|
|
|
def
|
|
|
|
(doc $
|
|
|
|
para "first slide" <>
|
|
|
|
header 2 "image header" <>
|
2017-12-28 12:06:38 -08:00
|
|
|
(para $ image "lalune.jpg" "" "") <>
|
2017-12-28 10:39:47 -05:00
|
|
|
para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With table, no header" 3
|
|
|
|
def
|
|
|
|
(doc $
|
|
|
|
para "first slide" <>
|
|
|
|
(simpleTable [para "foo" <> para "bar"] [[para "this" <> para "that"]]) <>
|
|
|
|
para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"With table, header" 3
|
|
|
|
def
|
|
|
|
(doc $
|
|
|
|
para "first slide" <>
|
|
|
|
header 2 "table header" <>
|
|
|
|
(simpleTable [para "foo" <> para "bar"] [[para "this" <> para "that"]]) <>
|
|
|
|
para "foo")
|
|
|
|
, testNumberOfSlides
|
|
|
|
"hrule" 2
|
|
|
|
def
|
|
|
|
(doc $
|
|
|
|
para "first slide" <> horizontalRule <> para "last slide")
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
tests :: [TestTree]
|
|
|
|
tests = [numSlideTests]
|