packages feed

pandoc-3.14: test/Tests/Readers/Pptx.hs

{-# LANGUAGE OverloadedStrings #-}
{- |
   Module      : Tests.Readers.Pptx
   Copyright   : © 2025 Anton Antic
   License     : GNU GPL, version 2 or above

   Maintainer  : Anton Antic <anton@everworker.ai>
   Stability   : alpha
   Portability : portable

Tests for the PPTX reader.
-}
module Tests.Readers.Pptx (tests) where

import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as B
import Test.Tasty
import Test.Tasty.Golden.Advanced
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.UTF8 as UTF8

defopts :: ReaderOptions
defopts = def{ readerExtensions = getDefaultExtensions "pptx" }

testCompare :: String -> FilePath -> FilePath -> TestTree
testCompare = testCompareWithOpts defopts

testCompareWithOpts :: ReaderOptions -> String -> FilePath -> FilePath -> TestTree
testCompareWithOpts opts testName pptxFP nativeFP =
  goldenTest
  testName
  (do nf <- UTF8.toText <$> BS.readFile nativeFP
      runIOorExplode (readNative def nf))
  (do df <- B.readFile pptxFP
      runIOorExplode (readPptx opts df))
  (nativeDiff nativeFP)
  (\a -> runIOorExplode (writeNative def{ writerTemplate = Just mempty} a)
            >>= BS.writeFile nativeFP . UTF8.fromText)

tests :: [TestTree]
tests = [ testGroup "basic"
          [ testCompare
            "charts"
            "pptx-reader/charts.pptx"
            "pptx-reader/charts.native"
          , testCompare
            "run formatting and hyperlinks"
            "pptx-reader/formatting.pptx"
            "pptx-reader/formatting.native"
          , testCompare
            "group shapes"
            "pptx-reader/groups.pptx"
            "pptx-reader/groups.native"
          , testCompare
            "slide number placeholders"
            "pptx-reader/slide-numbers.pptx"
            "pptx-reader/slide-numbers.native"
          , testCompare
            "text extraction"
            "pptx-reader/basic.pptx"
            "pptx-reader/basic.native"
          , testCompare
            "text runs and line breaks"
            "pptx-reader/runs.pptx"
            "pptx-reader/runs.native"
          ]
        , testGroup "slides"
          [ testCompare
            "hidden slides"
            "pptx-reader/hidden.pptx"
            "pptx-reader/hidden.native"
          ]
        , testGroup "tables"
          [ testCompare
            "merged cells"
            "pptx-reader/table-spans.pptx"
            "pptx-reader/table-spans.native"
          ]
        , testGroup "markup compatibility"
          [ testCompare
            "equations and alternate content"
            "pptx-reader/equations.pptx"
            "pptx-reader/equations.native"
          ]
        , testGroup "lists"
          [ testCompare
            "inherited bullets, nesting and numbering"
            "pptx-reader/lists.pptx"
            "pptx-reader/lists.native"
          , testCompare
            "lists written by the pptx writer"
            "pptx-reader/lists-writer.pptx"
            "pptx-reader/lists-writer.native"
          ]
        , testGroup "notes"
          [ testCompare
            "speaker notes"
            "pptx-reader/notes.pptx"
            "pptx-reader/notes.native"
          ]
        ]