Add DocX automated tests.

Note this makes use of input and output files in the tests/ dir.
This commit is contained in:
Jesse Rosenthal 2014-06-15 14:55:17 -04:00
parent 3bc818d2d3
commit f928e4c8dc
19 changed files with 139 additions and 0 deletions

View file

@ -0,0 +1,68 @@
module Tests.Readers.DocX (tests) where
import Text.Pandoc.Options
import Text.Pandoc.Readers.Native
import Text.Pandoc.Definition
import Tests.Helpers
import Test.Framework
import qualified Data.ByteString.Lazy as B
import Text.Pandoc.Readers.DocX
compareOutput :: FilePath -> FilePath -> IO (Pandoc, Pandoc)
compareOutput docxFile nativeFile = do
df <- B.readFile docxFile
nf <- Prelude.readFile nativeFile
return $ (readDocX def df, readNative nf)
testCompare' :: String -> FilePath -> FilePath -> IO Test
testCompare' name docxFile nativeFile = do
(dp, np) <- compareOutput docxFile nativeFile
return $ test id name (dp, np)
testCompare :: String -> FilePath -> FilePath -> Test
testCompare name docxFile nativeFile =
buildTest $ testCompare' name docxFile nativeFile
tests :: [Test]
tests = [ testGroup "inlines"
[ testCompare
"font formatting"
"docx.inline_formatting.docx"
"docx.inline_formatting.native"
, testCompare
"hyperlinks"
"docx.links.docx"
"docx.links.native"
, testCompare
"inline image with reference output"
"docx.image.docx"
"docx.image_no_embed.native"
, testCompare
"handling unicode input"
"docx.unicode.docx"
"docx.unicode.native"]
, testGroup "blocks"
[ testCompare
"headers"
"docx.headers.docx"
"docx.headers.native"
, testCompare
"lists"
"docx.lists.docx"
"docx.lists.native"
, testCompare
"footnotes and endnotes"
"docx.notes.docx"
"docx.notes.native"
, testCompare
"blockquotes (parsing indent as blockquote)"
"docx.block_quotes.docx"
"docx.block_quotes_parse_indent.native"
, testCompare
"tables"
"docx.tables.docx"
"docx.tables.native"
]
]

Binary file not shown.

View file

@ -0,0 +1,8 @@
[Header 2 ("",[],[]) [Str "Some",Space,Str "block",Space,Str "quotes,",Space,Str "in",Space,Str "different",Space,Str "ways"]
,Para [Str "This",Space,Str "is",Space,Str "the",Space,Str "proper",Space,Str "way,",Space,Str "with",Space,Str "a",Space,Str "style"]
,BlockQuote
[Para [Str "I",Space,Str "don\8217t",Space,Str "know",Space,Str "why",Space,Str "this",Space,Str "would",Space,Str "be",Space,Str "in",Space,Str "italics,",Space,Str "but",Space,Str "so",Space,Str "it",Space,Str "appears",Space,Str "to",Space,Str "be",Space,Str "on",Space,Str "my",Space,Str "screen."]]
,Para [Str "And",Space,Str "this",Space,Str "is",Space,Str "the",Space,Str "way",Space,Str "that",Space,Str "most",Space,Str "people",Space,Str "do",Space,Str "it:"]
,BlockQuote
[Para [Str "I",Space,Str "just",Space,Str "indented",Space,Str "this,",Space,Str "so",Space,Str "it",Space,Str "looks",Space,Str "like",Space,Str "a",Space,Str "block",Space,Str "quote.",Space,Str "I",Space,Str "think",Space,Str "this",Space,Str "is",Space,Str "how",Space,Str "most",Space,Str "people",Space,Str "do",Space,Str "block",Space,Str "quotes",Space,Str "in",Space,Str "their",Space,Str "documents."]]
,Para [Str "And",Space,Str "back",Space,Str "to",Space,Str "the",Space,Str "normal",Space,Str "style."]]

BIN
tests/docx.headers.docx Normal file

Binary file not shown.

View file

@ -0,0 +1,5 @@
[Header 1 ("",[],[]) [Str "A",Space,Str "Test",Space,Str "of",Space,Str "Headers"]
,Header 2 ("",[],[]) [Str "Second",Space,Str "Level"]
,Para [Str "Some",Space,Str "plain",Space,Str "text."]
,Header 3 ("",[],[]) [Str "Third",Space,Str "level"]
,Para [Str "Some",Space,Str "more",Space,Str "plain",Space,Str "text."]]

BIN
tests/docx.image.docx Normal file

Binary file not shown.

View file

@ -0,0 +1,2 @@
[Header 2 ("",[],[]) [Str "An",Space,Str "image"]
,Para [Image [] ("word/media/image1.jpeg","")]]

Binary file not shown.

View file

@ -0,0 +1,5 @@
[Para [Str "Regular",Space,Str "text",Space,Emph [Str "italics"],Space,Strong [Str "bold",Space,Emph [Str "bold",Space,Str "italics"]],Str "."]
,Para [Str "This",Space,Str "is",Space,SmallCaps [Str "Small",Space,Str "Caps"],Str ",",Space,Str "and",Space,Str "this",Space,Str "is",Space,Strikeout [Str "strikethrough"],Str "."]
,Para [Str "Some",Space,Str "people",Space,Str "use",Space,Span ("",[],[("underline","single")]) [Str "single",Space,Str "underlines",Space,Str "for",Space,Emph [Str "emphasis"]],Str "."]
,Para [Str "Above",Space,Str "the",Space,Str "line",Space,Str "is",Space,Superscript [Str "superscript"],Space,Str "and",Space,Str "below",Space,Str "the",Space,Str "line",Space,Str "is",Space,Subscript [Str "subscript"],Str "."]
,Para [Str "A",Space,Str "line",LineBreak,Str "break."]]

BIN
tests/docx.links.docx Normal file

Binary file not shown.

6
tests/docx.links.native Normal file
View file

@ -0,0 +1,6 @@
[Header 2 ("",[],[]) [Str "An",Space,Str "internal",Space,Str "link",Space,Str "and",Space,Str "an",Space,Str "external",Space,Str "link"]
,Para [Str "An",Space,Link [Str "external",Space,Str "link"] ("http://google.com",""),Space,Str "to",Space,Str "a",Space,Str "popular",Space,Str "website."]
,Para [Str "An",Space,Link [Str "internal",Space,Str "link"] ("#_A_section_for",""),Space,Str "to",Space,Str "a",Space,Str "section",Space,Str "header."]
,Para [Str "An",Space,Link [Str "internal",Space,Str "link"] ("#my_bookmark",""),Space,Str "to",Space,Str "a",Space,Str "bookmark."]
,Header 2 ("_A_section_for",[],[]) [Str "A",Space,Str "section",Space,Str "for",Space,Str "testing",Space,Str "link",Space,Str "targets"]
,Para [Str "A",Space,Str "bookmark",Space,Str "right",Space,Span ("my_bookmark",["anchor"],[]) [],Str "here"]]

BIN
tests/docx.lists.docx Normal file

Binary file not shown.

18
tests/docx.lists.native Normal file
View file

@ -0,0 +1,18 @@
[Header 2 ("",[],[]) [Str "Some",Space,Str "nested",Space,Str "lists"]
,OrderedList (1,Decimal,Period)
[[Para [Str "one"]]
,[Para [Str "two"]
,OrderedList (1,LowerAlpha,DefaultDelim)
[[Para [Str "a"]]
,[Para [Str "b"]]]]]
,BulletList
[[Para [Str "one"]]
,[Para [Str "two"]
,BulletList
[[Para [Str "three"]
,BulletList
[[Para [Str "four"]
,Para [Str "Sub",Space,Str "paragraph"]]]]]]
,[Para [Str "Same",Space,Str "list"]]]
,BulletList
[[Para [Str "Different",Space,Str "list",Space,Str "adjacent",Space,Str "to",Space,Str "the",Space,Str "one",Space,Str "above."]]]]

BIN
tests/docx.notes.docx Normal file

Binary file not shown.

2
tests/docx.notes.native Normal file
View file

@ -0,0 +1,2 @@
[Header 2 ("",[],[]) [Str "A",Space,Str "footnote"]
,Para [Str "Test",Space,Str "footnote.",Note [Para [Space,Str "My",Space,Str "note."]],Space,Str "Test",Space,Str "endnote.",Note [Para [Space,Str "This",Space,Str "is",Space,Str "an",Space,Str "endnote",Space,Str "at",Space,Str "the",Space,Str "end",Space,Str "of",Space,Str "the",Space,Str "document."]]]]

BIN
tests/docx.tables.docx Normal file

Binary file not shown.

24
tests/docx.tables.native Normal file
View file

@ -0,0 +1,24 @@
[Header 2 ("",[],[]) [Str "A",Space,Str "table,",Space,Str "with",Space,Str "and",Space,Str "without",Space,Str "a",Space,Str "header",Space,Str "row"]
,Table [] [AlignDefault,AlignDefault,AlignDefault,AlignDefault] [0.0,0.0,0.0,0.0]
[[Para [Str "Name"]]
,[Para [Str "Game"]]
,[Para [Str "Fame"]]
,[Para [Str "Blame"]]]
[[[Para [Str "Lebron",Space,Str "James"]]
,[Para [Str "Basketball"]]
,[Para [Str "Very",Space,Str "High"]]
,[Para [Str "Leaving",Space,Str "Cleveland"]]]
,[[Para [Str "Ryan",Space,Str "Braun"]]
,[Para [Str "Baseball"]]
,[Para [Str "Moderate"]]
,[Para [Str "Steroids"]]]
,[[Para [Str "Russell",Space,Str "Wilson"]]
,[Para [Str "Football"]]
,[Para [Str "High"]]
,[Para [Str "Tacky",Space,Str "uniform"]]]]
,Table [] [AlignDefault,AlignDefault] [0.0,0.0]
[]
[[[Para [Str "Sinple"]]
,[Para [Str "Table"]]]
,[[Para [Str "Without"]]
,[Para [Str "Header"]]]]]

BIN
tests/docx.unicode.docx Normal file

Binary file not shown.

View file

@ -0,0 +1 @@
[Para [Str "Hello,",Space,Str "\19990\30028.",Space,Str "This",Space,Str "costs",Space,Str "\8364\&10."]]