pandoc/tests/Tests/Writers/Docx.hs

153 lines
5.4 KiB
Haskell
Raw Normal View History

2015-03-03 12:37:02 +01:00
module Tests.Writers.Docx (tests) where
import Text.Pandoc.Options
import Text.Pandoc.Readers.Native
import Text.Pandoc.Definition
import Tests.Helpers
import Test.Framework
import Text.Pandoc.Readers.Docx
import Text.Pandoc.Writers.Docx
import Text.Pandoc.Error
import System.FilePath ((</>))
import Text.Pandoc.Class (runIOorExplode)
2015-03-03 12:37:02 +01:00
type Options = (WriterOptions, ReaderOptions)
compareOutput :: Options
-> FilePath
-> FilePath
-> IO (Pandoc, Pandoc)
compareOutput opts nativeFileIn nativeFileOut = do
nf <- Prelude.readFile nativeFileIn
nf' <- Prelude.readFile nativeFileOut
let wopts = fst opts
2016-11-27 16:38:46 +01:00
df <- runIOorExplode $ do
d <- handleError <$> readNative nf
writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
df' <- handleError <$> runIOorExplode (readNative nf')
let (p, _) = handleError $ readDocx (snd opts) df
2016-11-27 16:38:46 +01:00
return (p, df')
2015-03-03 12:37:02 +01:00
testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test
testCompareWithOptsIO opts name nativeFileIn nativeFileOut = do
(dp, np) <- compareOutput opts nativeFileIn nativeFileOut
2015-03-03 12:37:02 +01:00
return $ test id name (dp, np)
testCompareWithOpts :: Options -> String -> FilePath -> FilePath -> Test
testCompareWithOpts opts name nativeFileIn nativeFileOut =
buildTest $ testCompareWithOptsIO opts name nativeFileIn nativeFileOut
2015-03-03 12:37:02 +01:00
roundTripCompareWithOpts :: Options -> String -> FilePath -> Test
roundTripCompareWithOpts opts name nativeFile =
testCompareWithOpts opts name nativeFile nativeFile
-- testCompare :: String -> FilePath -> FilePath -> Test
-- testCompare = testCompareWithOpts def
2015-03-03 12:37:02 +01:00
roundTripCompare :: String -> FilePath -> Test
roundTripCompare = roundTripCompareWithOpts def
2015-03-03 12:37:02 +01:00
tests :: [Test]
tests = [ testGroup "inlines"
[ roundTripCompare
2015-03-03 12:37:02 +01:00
"font formatting"
"docx/inline_formatting_writer.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"font formatting with character styles"
"docx/char_styles.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"hyperlinks"
"docx/links_writer.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"inline image"
"docx/image_no_embed_writer.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"inline image in links"
"docx/inline_images_writer.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"handling unicode input"
"docx/unicode.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"literal tabs"
"docx/tabs.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"normalizing inlines"
"docx/normalize.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"normalizing inlines deep inside blocks"
"docx/deep_normalize.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"move trailing spaces outside of formatting"
"docx/trailing_spaces_in_formatting.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"inline code (with VerbatimChar style)"
"docx/inline_code.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"inline code in subscript and superscript"
"docx/verbatim_subsuper.native"
]
, testGroup "blocks"
[ roundTripCompare
2015-03-03 12:37:02 +01:00
"headers"
"docx/headers.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"headers already having auto identifiers"
"docx/already_auto_ident.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"numbered headers automatically made into list"
"docx/numbered_header.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"i18n blocks (headers and blockquotes)"
"docx/i18n_blocks.native"
2015-03-08 01:59:48 +01:00
-- Continuation does not survive round-trip
, roundTripCompare
2015-03-08 01:59:48 +01:00
"lists"
"docx/lists_writer.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"definition lists"
"docx/definition_list.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"custom defined lists in styles"
"docx/german_styled_lists.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"footnotes and endnotes"
"docx/notes.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"blockquotes (parsing indent as blockquote)"
"docx/block_quotes_parse_indent.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"hanging indents"
"docx/hanging_indent.native"
-- tables headers do not survive round-trip, should look into that
, roundTripCompare
2015-03-08 02:42:50 +01:00
"tables"
"docx/tables.native"
, roundTripCompare
2015-03-08 02:42:50 +01:00
"tables with lists in cells"
"docx/table_with_list_cell.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"code block"
"docx/codeblock.native"
, roundTripCompare
2015-03-03 12:37:02 +01:00
"dropcap paragraphs"
"docx/drop_cap.native"
]
, testGroup "metadata"
[ roundTripCompareWithOpts (def,def{readerStandalone=True})
2015-03-03 12:37:02 +01:00
"metadata fields"
"docx/metadata.native"
, roundTripCompareWithOpts (def,def{readerStandalone=True})
2015-03-03 12:37:02 +01:00
"stop recording metadata with normal text"
"docx/metadata_after_normal.native"
]
, testGroup "customized styles"
[ testCompareWithOpts
( def{writerReferenceDocx=Just "docx/custom-style-reference.docx"}
, def)
"simple customized blocks and inlines"
"docx/custom-style-roundtrip-start.native"
"docx/custom-style-roundtrip-end.native"
]
2015-03-03 12:37:02 +01:00
]