2015-03-03 12:37:02 +01:00
|
|
|
module Tests.Writers.Docx (tests) where
|
|
|
|
|
2017-03-04 13:03:41 +01:00
|
|
|
import System.FilePath ((</>))
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
2017-03-04 13:03:41 +01:00
|
|
|
import Tests.Helpers
|
|
|
|
import Text.Pandoc.Class (runIOorExplode)
|
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import Text.Pandoc.Options
|
2015-03-03 12:37:02 +01:00
|
|
|
import Text.Pandoc.Readers.Docx
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc.Readers.Native
|
2015-03-03 12:37:02 +01:00
|
|
|
import Text.Pandoc.Writers.Docx
|
2017-03-14 17:05:36 +01:00
|
|
|
import System.IO.Unsafe (unsafePerformIO) -- TODO temporary
|
2017-06-10 18:26:44 +02:00
|
|
|
import qualified Data.ByteString as BS
|
|
|
|
import qualified Text.Pandoc.UTF8 as UTF8
|
2015-03-03 12:37:02 +01:00
|
|
|
|
|
|
|
type Options = (WriterOptions, ReaderOptions)
|
|
|
|
|
|
|
|
compareOutput :: Options
|
2016-08-15 21:23:25 +02:00
|
|
|
-> FilePath
|
|
|
|
-> FilePath
|
|
|
|
-> IO (Pandoc, Pandoc)
|
|
|
|
compareOutput opts nativeFileIn nativeFileOut = do
|
2017-06-10 18:26:44 +02:00
|
|
|
nf <- UTF8.toText <$> BS.readFile nativeFileIn
|
|
|
|
nf' <- UTF8.toText <$> BS.readFile nativeFileOut
|
2015-09-09 19:16:57 +02:00
|
|
|
let wopts = fst opts
|
2016-11-27 16:38:46 +01:00
|
|
|
df <- runIOorExplode $ do
|
2016-12-10 16:52:35 +01:00
|
|
|
d <- readNative def nf
|
2016-11-27 16:38:46 +01:00
|
|
|
writeDocx wopts{writerUserDataDir = Just (".." </> "data")} d
|
2016-12-10 16:52:35 +01:00
|
|
|
df' <- runIOorExplode (readNative def nf')
|
2016-12-01 18:47:05 +01:00
|
|
|
p <- runIOorExplode $ readDocx (snd opts) df
|
2016-11-27 16:38:46 +01:00
|
|
|
return (p, df')
|
2015-03-03 12:37:02 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO TestTree
|
2016-08-15 21:23:25 +02:00
|
|
|
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)
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
testCompareWithOpts :: Options -> String -> FilePath -> FilePath -> TestTree
|
2016-08-15 21:23:25 +02:00
|
|
|
testCompareWithOpts opts name nativeFileIn nativeFileOut =
|
2017-03-14 17:05:36 +01:00
|
|
|
unsafePerformIO $ testCompareWithOptsIO opts name nativeFileIn nativeFileOut
|
2015-03-03 12:37:02 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
roundTripCompareWithOpts :: Options -> String -> FilePath -> TestTree
|
2016-08-15 21:23:25 +02:00
|
|
|
roundTripCompareWithOpts opts name nativeFile =
|
|
|
|
testCompareWithOpts opts name nativeFile nativeFile
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
-- testCompare :: String -> FilePath -> FilePath -> TestTree
|
2016-08-15 21:39:34 +02:00
|
|
|
-- testCompare = testCompareWithOpts def
|
2015-03-03 12:37:02 +01:00
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
roundTripCompare :: String -> FilePath -> TestTree
|
2016-08-15 21:23:25 +02:00
|
|
|
roundTripCompare = roundTripCompareWithOpts def
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2015-03-03 12:37:02 +01:00
|
|
|
tests = [ testGroup "inlines"
|
2016-08-15 21:23:25 +02:00
|
|
|
[ roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"font formatting"
|
|
|
|
"docx/inline_formatting_writer.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"font formatting with character styles"
|
|
|
|
"docx/char_styles.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"hyperlinks"
|
|
|
|
"docx/links_writer.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"inline image"
|
|
|
|
"docx/image_no_embed_writer.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"inline image in links"
|
|
|
|
"docx/inline_images_writer.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"handling unicode input"
|
|
|
|
"docx/unicode.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"literal tabs"
|
|
|
|
"docx/tabs.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"normalizing inlines"
|
|
|
|
"docx/normalize.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"normalizing inlines deep inside blocks"
|
|
|
|
"docx/deep_normalize.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"move trailing spaces outside of formatting"
|
|
|
|
"docx/trailing_spaces_in_formatting.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"inline code (with VerbatimChar style)"
|
|
|
|
"docx/inline_code.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"inline code in subscript and superscript"
|
|
|
|
"docx/verbatim_subsuper.native"
|
|
|
|
]
|
|
|
|
, testGroup "blocks"
|
2016-08-15 21:23:25 +02:00
|
|
|
[ roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"headers"
|
|
|
|
"docx/headers.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"headers already having auto identifiers"
|
|
|
|
"docx/already_auto_ident.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"numbered headers automatically made into list"
|
|
|
|
"docx/numbered_header.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, 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
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-08 01:59:48 +01:00
|
|
|
"lists"
|
|
|
|
"docx/lists_writer.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"definition lists"
|
|
|
|
"docx/definition_list.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"custom defined lists in styles"
|
|
|
|
"docx/german_styled_lists.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"footnotes and endnotes"
|
|
|
|
"docx/notes.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"blockquotes (parsing indent as blockquote)"
|
|
|
|
"docx/block_quotes_parse_indent.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, 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
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-08 02:42:50 +01:00
|
|
|
"tables"
|
|
|
|
"docx/tables.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-08 02:42:50 +01:00
|
|
|
"tables with lists in cells"
|
|
|
|
"docx/table_with_list_cell.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"code block"
|
|
|
|
"docx/codeblock.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompare
|
2015-03-03 12:37:02 +01:00
|
|
|
"dropcap paragraphs"
|
|
|
|
"docx/drop_cap.native"
|
|
|
|
]
|
|
|
|
, testGroup "metadata"
|
2016-08-15 21:23:25 +02:00
|
|
|
[ roundTripCompareWithOpts (def,def{readerStandalone=True})
|
2015-03-03 12:37:02 +01:00
|
|
|
"metadata fields"
|
|
|
|
"docx/metadata.native"
|
2016-08-15 21:23:25 +02:00
|
|
|
, roundTripCompareWithOpts (def,def{readerStandalone=True})
|
2015-03-03 12:37:02 +01:00
|
|
|
"stop recording metadata with normal text"
|
|
|
|
"docx/metadata_after_normal.native"
|
|
|
|
]
|
2016-08-15 21:33:06 +02:00
|
|
|
, testGroup "customized styles"
|
|
|
|
[ testCompareWithOpts
|
2016-12-10 10:39:44 +01:00
|
|
|
( def{writerReferenceDoc=Just "docx/custom-style-reference.docx"}
|
2016-08-15 21:33:06 +02:00
|
|
|
, 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
|
|
|
|
|
|
|
]
|