diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Tests/Readers/Docx.hs | 4 | ||||
-rw-r--r-- | tests/Tests/Readers/Org.hs | 196 | ||||
-rw-r--r-- | tests/Tests/Writers/Docx.hs | 99 | ||||
-rw-r--r-- | tests/Tests/Writers/LaTeX.hs | 2 | ||||
-rw-r--r-- | tests/docx/custom-style-reference.docx | bin | 0 -> 14846 bytes | |||
-rw-r--r-- | tests/docx/custom-style-roundtrip-end.native | 5 | ||||
-rw-r--r-- | tests/docx/custom-style-roundtrip-start.native | 5 | ||||
-rw-r--r-- | tests/docx/nested_anchors_in_header.docx | bin | 0 -> 17535 bytes | |||
-rw-r--r-- | tests/docx/nested_anchors_in_header.native | 10 | ||||
-rw-r--r-- | tests/writer.org | 4 |
10 files changed, 219 insertions, 106 deletions
diff --git a/tests/Tests/Readers/Docx.hs b/tests/Tests/Readers/Docx.hs index a9a9094f1..8ae0532e4 100644 --- a/tests/Tests/Readers/Docx.hs +++ b/tests/Tests/Readers/Docx.hs @@ -182,6 +182,10 @@ tests = [ testGroup "inlines" "docx/already_auto_ident.docx" "docx/already_auto_ident.native" , testCompare + "nested anchor spans in header" + "docx/nested_anchors_in_header.docx" + "docx/nested_anchors_in_header.native" + , testCompare "single numbered item not made into list" "docx/numbered_header.docx" "docx/numbered_header.native" diff --git a/tests/Tests/Readers/Org.hs b/tests/Tests/Readers/Org.hs index 0a3f9c222..d4fedc797 100644 --- a/tests/Tests/Readers/Org.hs +++ b/tests/Tests/Readers/Org.hs @@ -467,7 +467,14 @@ tests = , "Author" =: "#+author: Albert /Emacs-Fanboy/ Krewinkel" =?> let author = toList . spcSep $ [ "Albert", emph "Emacs-Fanboy", "Krewinkel" ] - meta = setMeta "author" (MetaInlines author) $ nullMeta + meta = setMeta "author" (MetaList [MetaInlines author]) $ nullMeta + in Pandoc meta mempty + + , "Multiple authors" =: + "#+author: James Dewey Watson, Francis Harry Compton Crick " =?> + let watson = MetaInlines $ toList "James Dewey Watson" + crick = MetaInlines $ toList "Francis Harry Compton Crick" + meta = setMeta "author" (MetaList [watson, crick]) $ nullMeta in Pandoc meta mempty , "Date" =: @@ -478,8 +485,8 @@ tests = , "Description" =: "#+DESCRIPTION: Explanatory text" =?> - let description = toList . spcSep $ [ "Explanatory", "text" ] - meta = setMeta "description" (MetaInlines description) $ nullMeta + let description = "Explanatory text" + meta = setMeta "description" (MetaString description) $ nullMeta in Pandoc meta mempty , "Properties drawer" =: @@ -489,6 +496,38 @@ tests = ] =?> (mempty::Blocks) + , "LaTeX_headers options are translated to header-includes" =: + "#+LaTeX_header: \\usepackage{tikz}" =?> + let latexInlines = rawInline "latex" "\\usepackage{tikz}" + inclList = MetaList [MetaInlines (toList latexInlines)] + meta = setMeta "header-includes" inclList nullMeta + in Pandoc meta mempty + + , "LaTeX_class option is translated to documentclass" =: + "#+LATEX_CLASS: article" =?> + let meta = setMeta "documentclass" (MetaString "article") nullMeta + in Pandoc meta mempty + + , "LaTeX_class_options is translated to classoption" =: + "#+LATEX_CLASS_OPTIONS: [a4paper]" =?> + let meta = setMeta "classoption" (MetaString "a4paper") nullMeta + in Pandoc meta mempty + + , "LaTeX_class_options is translated to classoption" =: + "#+html_head: <meta/>" =?> + let html = rawInline "html" "<meta/>" + inclList = MetaList [MetaInlines (toList html)] + meta = setMeta "header-includes" inclList nullMeta + in Pandoc meta mempty + + , "later meta definitions take precedence" =: + unlines [ "#+AUTHOR: this will not be used" + , "#+author: Max" + ] =?> + let author = MetaInlines [Str "Max"] + meta = setMeta "author" (MetaList [author]) $ nullMeta + in Pandoc meta mempty + , "Logbook drawer" =: unlines [ " :LogBook:" , " - State \"DONE\" from \"TODO\" [2014-03-03 Mon 11:00]" @@ -563,69 +602,91 @@ tests = ] =?> (para (link "http://example.com/foo" "" "bar")) - , "Export option: Disable simple sub/superscript syntax" =: - unlines [ "#+OPTIONS: ^:nil" - , "a^b" - ] =?> - para "a^b" - , "Export option: directly select drawers to be exported" =: - unlines [ "#+OPTIONS: d:(\"IMPORTANT\")" - , ":IMPORTANT:" - , "23" - , ":END:" - , ":BORING:" - , "very boring" - , ":END:" - ] =?> - divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "23") - - , "Export option: exclude drawers from being exported" =: - unlines [ "#+OPTIONS: d:(not \"BORING\")" - , ":IMPORTANT:" - , "5" - , ":END:" - , ":BORING:" - , "very boring" - , ":END:" - ] =?> - divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "5") - - , "Export option: don't include archive trees" =: - unlines [ "#+OPTIONS: arch:nil" - , "* old :ARCHIVE:" - ] =?> - (mempty ::Blocks) + , testGroup "export options" + + [ "disable simple sub/superscript syntax" =: + unlines [ "#+OPTIONS: ^:nil" + , "a^b" + ] =?> + para "a^b" + + , "directly select drawers to be exported" =: + unlines [ "#+OPTIONS: d:(\"IMPORTANT\")" + , ":IMPORTANT:" + , "23" + , ":END:" + , ":BORING:" + , "very boring" + , ":END:" + ] =?> + divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "23") + + , "exclude drawers from being exported" =: + unlines [ "#+OPTIONS: d:(not \"BORING\")" + , ":IMPORTANT:" + , "5" + , ":END:" + , ":BORING:" + , "very boring" + , ":END:" + ] =?> + divWith (mempty, ["IMPORTANT", "drawer"], mempty) (para "5") + + , "don't include archive trees" =: + unlines [ "#+OPTIONS: arch:nil" + , "* old :ARCHIVE:" + ] =?> + (mempty ::Blocks) + + , "include complete archive trees" =: + unlines [ "#+OPTIONS: arch:t" + , "* old :ARCHIVE:" + , " boring" + ] =?> + let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty + in mconcat [ headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE") + , para "boring" + ] - , "Export option: include complete archive trees" =: - unlines [ "#+OPTIONS: arch:t" - , "* old :ARCHIVE:" - , " boring" - ] =?> - let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty - in mconcat [ headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE") - , para "boring" - ] + , "include archive tree header only" =: + unlines [ "#+OPTIONS: arch:headline" + , "* old :ARCHIVE:" + , " boring" + ] =?> + let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty + in headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE") + + , "limit headline depth" =: + unlines [ "#+OPTIONS: H:2" + , "* section" + , "** subsection" + , "*** list item 1" + , "*** list item 2" + ] =?> + mconcat [ headerWith ("section", [], []) 1 "section" + , headerWith ("subsection", [], []) 2 "subsection" + , orderedList [ para "list item 1", para "list item 2" ] + ] - , "Export option: include archive tree header only" =: - unlines [ "#+OPTIONS: arch:headline" - , "* old :ARCHIVE:" - , " boring" - ] =?> - let tagSpan t = spanWith ("", ["tag"], [("data-tag-name", t)]) mempty - in headerWith ("old", [], mempty) 1 ("old" <> tagSpan "ARCHIVE") - - , "Export option: limit headline depth" =: - unlines [ "#+OPTIONS: H:2" - , "* section" - , "** subsection" - , "*** list item 1" - , "*** list item 2" - ] =?> - mconcat [ headerWith ("section", [], []) 1 "section" - , headerWith ("subsection", [], []) 2 "subsection" - , orderedList [ para "list item 1", para "list item 2" ] - ] + , "disable author export" =: + unlines [ "#+OPTIONS: author:nil" + , "#+AUTHOR: ShyGuy" + ] =?> + Pandoc nullMeta mempty + + , "disable creator export" =: + unlines [ "#+OPTIONS: creator:nil" + , "#+creator: The Architect" + ] =?> + Pandoc nullMeta mempty + + , "disable email export" =: + unlines [ "#+OPTIONS: email:nil" + , "#+email: no-mail-please@example.com" + ] =?> + Pandoc nullMeta mempty + ] ] , testGroup "Basic Blocks" $ @@ -757,6 +818,15 @@ tests = ] =?> headerWith ("fubar", [], [("bar", "baz")]) 1 "foo" + + , "Headers marked with a unnumbered property get a class of the same name" =: + unlines [ "* Not numbered" + , " :PROPERTIES:" + , " :UNNUMBERED: t" + , " :END:" + ] =?> + headerWith ("not-numbered", ["unnumbered"], []) 1 "Not numbered" + , "Paragraph starting with an asterisk" =: "*five" =?> para "*five" diff --git a/tests/Tests/Writers/Docx.hs b/tests/Tests/Writers/Docx.hs index 8dba0ea55..31fc3a47b 100644 --- a/tests/Tests/Writers/Docx.hs +++ b/tests/Tests/Writers/Docx.hs @@ -13,120 +13,137 @@ import System.FilePath ((</>)) type Options = (WriterOptions, ReaderOptions) compareOutput :: Options - -> FilePath - -> IO (Pandoc, Pandoc) -compareOutput opts nativeFile = do - nf <- Prelude.readFile nativeFile + -> FilePath + -> FilePath + -> IO (Pandoc, Pandoc) +compareOutput opts nativeFileIn nativeFileOut = do + nf <- Prelude.readFile nativeFileIn + nf' <- Prelude.readFile nativeFileOut let wopts = fst opts df <- writeDocx wopts{writerUserDataDir = Just (".." </> "data")} (handleError $ readNative nf) let (p, _) = handleError $ readDocx (snd opts) df - return (p, handleError $ readNative nf) + return (p, handleError $ readNative nf') -testCompareWithOptsIO :: Options -> String -> FilePath -> IO Test -testCompareWithOptsIO opts name nativeFile = do - (dp, np) <- compareOutput opts nativeFile +testCompareWithOptsIO :: Options -> String -> FilePath -> FilePath -> IO Test +testCompareWithOptsIO opts name nativeFileIn nativeFileOut = do + (dp, np) <- compareOutput opts nativeFileIn nativeFileOut return $ test id name (dp, np) -testCompareWithOpts :: Options -> String -> FilePath -> Test -testCompareWithOpts opts name nativeFile = - buildTest $ testCompareWithOptsIO opts name nativeFile +testCompareWithOpts :: Options -> String -> FilePath -> FilePath -> Test +testCompareWithOpts opts name nativeFileIn nativeFileOut = + buildTest $ testCompareWithOptsIO opts name nativeFileIn nativeFileOut -testCompare :: String -> FilePath -> Test -testCompare = testCompareWithOpts def +roundTripCompareWithOpts :: Options -> String -> FilePath -> Test +roundTripCompareWithOpts opts name nativeFile = + testCompareWithOpts opts name nativeFile nativeFile + +-- testCompare :: String -> FilePath -> FilePath -> Test +-- testCompare = testCompareWithOpts def + +roundTripCompare :: String -> FilePath -> Test +roundTripCompare = roundTripCompareWithOpts def tests :: [Test] tests = [ testGroup "inlines" - [ testCompare + [ roundTripCompare "font formatting" "docx/inline_formatting_writer.native" - , testCompare + , roundTripCompare "font formatting with character styles" "docx/char_styles.native" - , testCompare + , roundTripCompare "hyperlinks" "docx/links_writer.native" - , testCompare + , roundTripCompare "inline image" "docx/image_no_embed_writer.native" - , testCompare + , roundTripCompare "inline image in links" "docx/inline_images_writer.native" - , testCompare + , roundTripCompare "handling unicode input" "docx/unicode.native" - , testCompare + , roundTripCompare "literal tabs" "docx/tabs.native" - , testCompare + , roundTripCompare "normalizing inlines" "docx/normalize.native" - , testCompare + , roundTripCompare "normalizing inlines deep inside blocks" "docx/deep_normalize.native" - , testCompare + , roundTripCompare "move trailing spaces outside of formatting" "docx/trailing_spaces_in_formatting.native" - , testCompare + , roundTripCompare "inline code (with VerbatimChar style)" "docx/inline_code.native" - , testCompare + , roundTripCompare "inline code in subscript and superscript" "docx/verbatim_subsuper.native" ] , testGroup "blocks" - [ testCompare + [ roundTripCompare "headers" "docx/headers.native" - , testCompare + , roundTripCompare "headers already having auto identifiers" "docx/already_auto_ident.native" - , testCompare + , roundTripCompare "numbered headers automatically made into list" "docx/numbered_header.native" - , testCompare + , roundTripCompare "i18n blocks (headers and blockquotes)" "docx/i18n_blocks.native" -- Continuation does not survive round-trip - , testCompare + , roundTripCompare "lists" "docx/lists_writer.native" - , testCompare + , roundTripCompare "definition lists" "docx/definition_list.native" - , testCompare + , roundTripCompare "custom defined lists in styles" "docx/german_styled_lists.native" - , testCompare + , roundTripCompare "footnotes and endnotes" "docx/notes.native" - , testCompare + , roundTripCompare "blockquotes (parsing indent as blockquote)" "docx/block_quotes_parse_indent.native" - , testCompare + , roundTripCompare "hanging indents" "docx/hanging_indent.native" -- tables headers do not survive round-trip, should look into that - , testCompare + , roundTripCompare "tables" "docx/tables.native" - , testCompare + , roundTripCompare "tables with lists in cells" "docx/table_with_list_cell.native" - , testCompare + , roundTripCompare "code block" "docx/codeblock.native" - , testCompare + , roundTripCompare "dropcap paragraphs" "docx/drop_cap.native" ] , testGroup "metadata" - [ testCompareWithOpts (def,def{readerStandalone=True}) + [ roundTripCompareWithOpts (def,def{readerStandalone=True}) "metadata fields" "docx/metadata.native" - , testCompareWithOpts (def,def{readerStandalone=True}) + , roundTripCompareWithOpts (def,def{readerStandalone=True}) "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" + ] ] diff --git a/tests/Tests/Writers/LaTeX.hs b/tests/Tests/Writers/LaTeX.hs index 4a1232db2..afab7d628 100644 --- a/tests/Tests/Writers/LaTeX.hs +++ b/tests/Tests/Writers/LaTeX.hs @@ -75,5 +75,7 @@ tests = [ testGroup "code blocks" "\\sout{\\texttt{foo} bar}" , "single quotes" =: code "dog's" =?> "\\texttt{dog\\textquotesingle{}s}" + , "backtick" =: + code "`nu?`" =?> "\\texttt{{`}nu?{`}}" ] ] diff --git a/tests/docx/custom-style-reference.docx b/tests/docx/custom-style-reference.docx Binary files differnew file mode 100644 index 000000000..0f53c6c88 --- /dev/null +++ b/tests/docx/custom-style-reference.docx diff --git a/tests/docx/custom-style-roundtrip-end.native b/tests/docx/custom-style-roundtrip-end.native new file mode 100644 index 000000000..4313c3595 --- /dev/null +++ b/tests/docx/custom-style-roundtrip-end.native @@ -0,0 +1,5 @@ +[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "test",Space,Str "of",Space,Str "custom-styles."] +,Para [Str "Here",Space,Str "is",Space,Str "something",Space,Emph [Str "emphasized"],Str ".",Space,Str "And",Space,Str "here",Space,Str "is",Space,Str "something",Space,Strong [Str "strong"],Str "."] +,BlockQuote + [Para [Str "One",Space,Str "paragraph",Space,Str "of",Space,Str "text."] + ,Para [Str "And",Space,Str "another",Space,Str "paragraph",Space,Str "of",Space,Emph [Str "really",Space,Str "cool"],Space,Str "text."]]] diff --git a/tests/docx/custom-style-roundtrip-start.native b/tests/docx/custom-style-roundtrip-start.native new file mode 100644 index 000000000..c4566ed85 --- /dev/null +++ b/tests/docx/custom-style-roundtrip-start.native @@ -0,0 +1,5 @@ +[Para [Str "This",Space,Str "is",Space,Str "a",Space,Str "test",Space,Str "of",Space,Str "custom-styles."] +,Para [Str "Here",Space,Str "is",Space,Str "something",Space,Span ("",[],[("custom-style","Emphatic")]) [Str "emphasized"],Str ".",Space,Str "And",SoftBreak,Str "here",Space,Str "is",Space,Str "something",Space,Span ("",[],[("custom-style","Strengthened")]) [Str "strong"],Str "."] +,Div ("",[],[("custom-style","My Block Style")]) + [Para [Str "One",Space,Str "paragraph",Space,Str "of",Space,Str "text."] + ,Para [Str "And",Space,Str "another",Space,Str "paragraph",Space,Str "of",Space,Span ("",[],[("custom-style","Emphatic")]) [Str "really",SoftBreak,Str "cool"],Space,Str "text."]]] diff --git a/tests/docx/nested_anchors_in_header.docx b/tests/docx/nested_anchors_in_header.docx Binary files differnew file mode 100644 index 000000000..ddebb7ff4 --- /dev/null +++ b/tests/docx/nested_anchors_in_header.docx diff --git a/tests/docx/nested_anchors_in_header.native b/tests/docx/nested_anchors_in_header.native new file mode 100644 index 000000000..e2b6eb1ef --- /dev/null +++ b/tests/docx/nested_anchors_in_header.native @@ -0,0 +1,10 @@ +[Header 1 ("short-instructions",[],[]) [Str "Short",Space,Str "instructions"] +,Para [Link ("",[],[]) [Str "Open",Space,Str "remote",Space,Str "folder"] ("#remote-folder-or-longlonglonglonglong-file-with-manymanymanymany-letters-inside-opening","")] +,Para [Str "Do",Space,Str "staff"] +,Para [Link ("",[],[]) [Str "Close",Space,Str "remote",Space,Str "folder"] ("#remote-folder-or-longlonglonglonglong-file-with-manymanymanymany-letters-inside-closing","")] +,Header 1 ("some-instructions",[],[]) [Str "Some",Space,Str "instructions"] +,Para [Str "Lines"] +,Header 2 ("remote-folder-or-longlonglonglonglong-file-with-manymanymanymany-letters-inside-opening",[],[]) [Str "Remote",Space,Str "folder",Space,Str "or",Space,Str "longlonglonglonglong",Space,Str "file",Space,Str "with",Space,Str "manymanymanymany",Space,Str "letters",Space,Str "inside",Space,Str "opening"] +,Para [Str "Open",Space,Str "folder"] +,Header 2 ("remote-folder-or-longlonglonglonglong-file-with-manymanymanymany-letters-inside-closing",[],[]) [Str "Remote",Space,Str "folder",Space,Str "or",Space,Str "longlonglonglonglong",Space,Str "file",Space,Str "with",Space,Str "manymanymanymany",Space,Str "letters",Space,Str "inside",Space,Str "closing"] +,Para [Str "Close",Space,Str "folder"]] diff --git a/tests/writer.org b/tests/writer.org index cf6305ec9..6a86a4e3f 100644 --- a/tests/writer.org +++ b/tests/writer.org @@ -808,9 +808,9 @@ Auto-links should not occur here: =<http://example.com/>= From "Voyage dans la Lune" by Georges Melies (1902): #+CAPTION: lalune +[[file:lalune.jpg]] -[[lalune.jpg]] -Here is a movie [[movie.jpg]] icon. +Here is a movie [[file:movie.jpg]] icon. -------------- |