@@ -1,161 +1,147 @@
1module Tests.Writers.Docx (tests) where
1module Tests.Writers.Docx (tests) where
3−import qualified Data.ByteString as BS
3+import Text.Pandoc
4−import System.FilePath ((</>))
5−import System.IO.Unsafe (unsafePerformIO)
6import Test.Tasty
4import Test.Tasty
7−import Tests.Helpers
5+import Tests.Writers.OOXML
8−import Text.Pandoc.Class (runIOorExplode, setUserDataDir)
6+import Test.Tasty.HUnit
9−import Text.Pandoc.Definition
7+import Data.List (isPrefixOf)
10−import Text.Pandoc.Options
11−import Text.Pandoc.Readers.Docx
12−import Text.Pandoc.Readers.Native
13−import qualified Text.Pandoc.UTF8 as UTF8
14−import Text.Pandoc.Walk
15−import Text.Pandoc.Writers.Docx
17−type Options = (WriterOptions, ReaderOptions)
9+-- we add an extra check to make sure that we're not writing in the
18−
10+-- toplevel docx directory. We don't want to accidentally overwrite an
19−compareOutput :: Options
11+-- Word-generated docx file used to test the reader.
20− -> FilePath
12+docxTest :: String -> WriterOptions -> FilePath -> FilePath -> TestTree
21− -> FilePath
13+docxTest testName opts nativeFP goldenFP =
22− -> IO (Pandoc, Pandoc)
14+ if "docx/golden/" `isPrefixOf` goldenFP
23−compareOutput (wopts, ropts) nativeFileIn nativeFileOut = do
15+ then ooxmlTest writeDocx testName opts nativeFP goldenFP
24− nf <- UTF8.toText <$> BS.readFile nativeFileIn
16+ else testCase testName $
25− nf' <- UTF8.toText <$> BS.readFile nativeFileOut
17+ assertFailure $
26− runIOorExplode $ do
18+ goldenFP ++ " is not in `test/docx/golden`"
27− setUserDataDir $ Just (".." </> "data")
28− roundtripped <- readNative def nf >>=
29− writeDocx wopts >>= readDocx ropts
30− orig <- readNative def nf'
31− return (walk fixImages roundtripped, walk fixImages orig)
33−-- make all image filenames "image", since otherwise round-trip
34−-- tests fail because of different behavior of Data.Unique in
35−-- different ghc versions...
36−fixImages :: Inline -> Inline
37−fixImages (Image attr alt (_,tit)) = Image attr alt ("image",tit)
40−testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO TestTree
41−testCompareWithOptsIO opts name nativeFileIn nativeFileOut = do
42− (dp, np) <- compareOutput opts nativeFileIn nativeFileOut
43− return $ test id name (dp, np)
45−testCompareWithOpts :: Options -> String -> FilePath -> FilePath -> TestTree
46−testCompareWithOpts opts name nativeFileIn nativeFileOut =
47− unsafePerformIO $ testCompareWithOptsIO opts name nativeFileIn nativeFileOut
49−roundTripCompareWithOpts :: Options -> String -> FilePath -> TestTree
50−roundTripCompareWithOpts opts name nativeFile =
51− testCompareWithOpts opts name nativeFile nativeFile
53−-- testCompare :: String -> FilePath -> FilePath -> TestTree
54−-- testCompare = testCompareWithOpts def
56−roundTripCompare :: String -> FilePath -> TestTree
57−roundTripCompare = roundTripCompareWithOpts def
59tests :: [TestTree]
20tests :: [TestTree]
60tests = [ testGroup "inlines"
21tests = [ testGroup "inlines"
61− [ roundTripCompare
22+ [ docxTest
62 "font formatting"
23 "font formatting"
63− "docx/inline_formatting_writer.native"
24+ def
64− , roundTripCompare
25+ "docx/inline_formatting.native"
65− "font formatting with character styles"
26+ "docx/golden/inline_formatting.docx"
66− "docx/char_styles.native"
27+ , docxTest
68 "hyperlinks"
28 "hyperlinks"
69− "docx/links_writer.native"
30+ "docx/links.native"
70− , roundTripCompare
31+ "docx/golden/links.docx"
71 "inline image"
33 "inline image"
72− "docx/image_no_embed_writer.native"
34+ def
73− , roundTripCompare
35+ "docx/image_writer_test.native"
36+ "docx/golden/image.docx"
74− "inline image in links"
38+ "inline images"
75− "docx/inline_images_writer.native"
39+ def
76− , roundTripCompare
40+ "docx/inline_images_writer_test.native"
41+ "docx/golden/inline_images.docx"
77 "handling unicode input"
43 "handling unicode input"
78 "docx/unicode.native"
45 "docx/unicode.native"
79− , roundTripCompare
46+ "docx/golden/unicode.docx"
80− "literal tabs"
47+ , docxTest
83− "normalizing inlines"
84− "docx/normalize.native"
86− "normalizing inlines deep inside blocks"
87− "docx/deep_normalize.native"
89− "move trailing spaces outside of formatting"
90− "docx/trailing_spaces_in_formatting.native"
92− "inline code (with VerbatimChar style)"
48+ "inline code"
93 "docx/inline_code.native"
50 "docx/inline_code.native"
94− , roundTripCompare
51+ "docx/golden/inline_code.docx"
95 "inline code in subscript and superscript"
53 "inline code in subscript and superscript"
96 "docx/verbatim_subsuper.native"
55 "docx/verbatim_subsuper.native"
56+ "docx/golden/verbatim_subsuper.docx"
98 , testGroup "blocks"
58 , testGroup "blocks"
99− [ roundTripCompare
59+ [ docxTest
100 "headers"
60 "headers"
101 "docx/headers.native"
62 "docx/headers.native"
102− , roundTripCompare
63+ "docx/golden/headers.docx"
103− "headers already having auto identifiers"
64+ , docxTest
104− "docx/already_auto_ident.native"
65+ "nested anchor spans in header"
105− , roundTripCompare
66+ def
106− "numbered headers automatically made into list"
67+ "docx/nested_anchors_in_header.native"
107− "docx/numbered_header.native"
68+ "docx/golden/nested_anchors_in_header.docx"
108− , roundTripCompare
69+ , docxTest
109− "i18n blocks (headers and blockquotes)"
110− "docx/i18n_blocks.native"
111− -- Continuation does not survive round-trip
73+ "docx/golden/lists.docx"
75+ "lists continuing after interruption"
77+ "docx/lists_continuing.native"
78+ "docx/golden/lists_continuing.docx"
80+ "lists restarting after interruption"
114− "docx/lists_writer.native"
82+ "docx/lists_restarting.native"
115− , roundTripCompare
83+ "docx/golden/lists_restarting.docx"
116 "definition lists"
85 "definition lists"
117 "docx/definition_list.native"
87 "docx/definition_list.native"
118− , roundTripCompare
88+ "docx/golden/definition_list.docx"
119− "custom defined lists in styles"
89+ , docxTest
120− "docx/german_styled_lists.native"
122 "footnotes and endnotes"
90 "footnotes and endnotes"
123 "docx/notes.native"
92 "docx/notes.native"
124− , roundTripCompare
93+ "docx/golden/notes.docx"
95+ "links in footnotes and endnotes"
97+ "docx/link_in_notes.native"
98+ "docx/golden/link_in_notes.docx"
125− "blockquotes (parsing indent as blockquote)"
100+ "blockquotes"
126 "docx/block_quotes_parse_indent.native"
102 "docx/block_quotes_parse_indent.native"
127− , roundTripCompare
103+ "docx/golden/block_quotes.docx"
128− "hanging indents"
104+ , docxTest
129− "docx/hanging_indent.native"
130− -- tables headers do not survive round-trip, should look into that
133 "docx/tables.native"
107 "docx/tables.native"
134− , roundTripCompare
108+ "docx/golden/tables.docx"
135 "tables with lists in cells"
110 "tables with lists in cells"
136 "docx/table_with_list_cell.native"
112 "docx/table_with_list_cell.native"
137− , roundTripCompare
113+ "docx/golden/table_with_list_cell.docx"
115+ "tables with one row"
117+ "docx/table_one_row.native"
118+ "docx/golden/table_one_row.docx"
138 "code block"
120 "code block"
139 "docx/codeblock.native"
122 "docx/codeblock.native"
140− , roundTripCompare
123+ "docx/golden/codeblock.docx"
141− "dropcap paragraphs"
142− "docx/drop_cap.native"
144− , testGroup "metadata"
125+ , testGroup "track changes"
145− [ roundTripCompareWithOpts (def,def{readerStandalone=True})
126+ [ docxTest
146− "metadata fields"
127+ "insertion"
147− "docx/metadata.native"
128+ def
148− , roundTripCompareWithOpts (def,def{readerStandalone=True})
129+ "docx/track_changes_insertion_all.native"
149− "stop recording metadata with normal text"
130+ "docx/golden/track_changes_insertion.docx"
150− "docx/metadata_after_normal.native"
131+ , docxTest
134+ "docx/track_changes_deletion_all.native"
135+ "docx/golden/track_changes_deletion.docx"
139+ "docx/track_changes_move_all.native"
140+ "docx/golden/track_changes_move.docx"
144+ "docx/comments.native"
145+ "docx/golden/comments.docx"
152− , testGroup "customized styles"
153− [ testCompareWithOpts
154− ( def{writerReferenceDoc=Just "docx/custom-style-reference.docx"}
156− "simple customized blocks and inlines"
157− "docx/custom-style-roundtrip-start.native"
158− "docx/custom-style-roundtrip-end.native"