aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlexander <ilabdsf@gmail.com>2018-04-26 22:33:18 +0300
committerJohn MacFarlane <jgm@berkeley.edu>2018-04-26 12:33:18 -0700
commit1927bc9aac0e822bd6179323e00fe38bee5a2cf3 (patch)
tree508b3527a8c09dfe72a790f82270691622af407d /test
parent5f0d407279e453107b28ee71fa0e45c5cc93090c (diff)
downloadpandoc-1927bc9aac0e822bd6179323e00fe38bee5a2cf3.tar.gz
Add FB2 reader (#4539)
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Readers/FB2.hs29
-rw-r--r--test/fb2/reader/emphasis.fb211
-rw-r--r--test/fb2/reader/emphasis.native6
-rw-r--r--test/fb2/reader/epigraph.fb218
-rw-r--r--test/fb2/reader/epigraph.native9
-rw-r--r--test/fb2/reader/meta.fb226
-rw-r--r--test/fb2/reader/meta.native2
-rw-r--r--test/fb2/reader/poem.fb228
-rw-r--r--test/fb2/reader/poem.native14
-rw-r--r--test/fb2/reader/titles.fb218
-rw-r--r--test/fb2/reader/titles.native8
-rw-r--r--test/test-pandoc.hs2
12 files changed, 171 insertions, 0 deletions
diff --git a/test/Tests/Readers/FB2.hs b/test/Tests/Readers/FB2.hs
new file mode 100644
index 000000000..9b2983d57
--- /dev/null
+++ b/test/Tests/Readers/FB2.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE NoImplicitPrelude #-}
+
+module Tests.Readers.FB2 (tests) where
+
+import Prelude
+import Test.Tasty
+import Tests.Helpers
+import Test.Tasty.Golden (goldenVsString)
+import qualified Data.ByteString as BS
+import Text.Pandoc
+import Text.Pandoc.UTF8 (toText, fromTextLazy)
+import Data.Text (Text)
+import Data.Text.Lazy (fromStrict)
+import System.FilePath (replaceExtension)
+
+fb2ToNative :: Text -> Text
+fb2ToNative = purely (writeNative def{ writerTemplate = Just "" }) . purely (readFB2 def)
+
+fb2Test :: TestName -> FilePath -> TestTree
+fb2Test name path = goldenVsString name native (fromTextLazy . fromStrict . fb2ToNative . toText <$> BS.readFile path)
+ where native = replaceExtension path ".native"
+
+tests :: [TestTree]
+tests = [ fb2Test "Emphasis" "fb2/reader/emphasis.fb2"
+ , fb2Test "Titles" "fb2/reader/titles.fb2"
+ , fb2Test "Epigraph" "fb2/reader/epigraph.fb2"
+ , fb2Test "Poem" "fb2/reader/poem.fb2"
+ , fb2Test "Meta" "fb2/reader/meta.fb2"
+ ]
diff --git a/test/fb2/reader/emphasis.fb2 b/test/fb2/reader/emphasis.fb2
new file mode 100644
index 000000000..1a936a9d0
--- /dev/null
+++ b/test/fb2/reader/emphasis.fb2
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
+ <body>
+ <section>
+ <p>Plain, <strong>strong</strong>, <emphasis>emphasis</emphasis>, <strong><emphasis>strong emphasis</emphasis></strong>, <emphasis><strong>emphasized strong</strong></emphasis>.</p>
+ <p>Strikethrough: <strikethrough>deleted</strikethrough></p>
+ <p><sub>Subscript</sub> and <sup>superscript</sup></p>
+ <p>Some <code>code</code></p>
+ </section>
+ </body>
+</FictionBook>
diff --git a/test/fb2/reader/emphasis.native b/test/fb2/reader/emphasis.native
new file mode 100644
index 000000000..422e7bb15
--- /dev/null
+++ b/test/fb2/reader/emphasis.native
@@ -0,0 +1,6 @@
+Pandoc (Meta {unMeta = fromList []})
+[Div ("",["section"],[])
+ [Para [Str "Plain,",Space,Strong [Str "strong"],Str ",",Space,Emph [Str "emphasis"],Str ",",Space,Strong [Emph [Str "strong",Space,Str "emphasis"]],Str ",",Space,Emph [Strong [Str "emphasized",Space,Str "strong"]],Str "."]
+ ,Para [Str "Strikethrough:",Space,Strikeout [Str "deleted"]]
+ ,Para [Subscript [Str "Subscript"],Space,Str "and",Space,Superscript [Str "superscript"]]
+ ,Para [Str "Some",Space,Code ("",[],[]) "code"]]]
diff --git a/test/fb2/reader/epigraph.fb2 b/test/fb2/reader/epigraph.fb2
new file mode 100644
index 000000000..5bb5cd2ef
--- /dev/null
+++ b/test/fb2/reader/epigraph.fb2
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
+ <body>
+ <epigraph>
+ <p>Body epigraph</p>
+ </epigraph>
+ <section>
+ <epigraph>
+ <p>Section epigraph</p>
+ </epigraph>
+ <section>
+ <epigraph>
+ <p>Subsection epigraph</p>
+ </epigraph>
+ </section>
+ </section>
+ </body>
+</FictionBook>
diff --git a/test/fb2/reader/epigraph.native b/test/fb2/reader/epigraph.native
new file mode 100644
index 000000000..a58a3e05b
--- /dev/null
+++ b/test/fb2/reader/epigraph.native
@@ -0,0 +1,9 @@
+Pandoc (Meta {unMeta = fromList []})
+[Div ("",["epigraph"],[])
+ [Para [Str "Body",Space,Str "epigraph"]]
+,Div ("",["section"],[])
+ [Div ("",["epigraph"],[])
+ [Para [Str "Section",Space,Str "epigraph"]]
+ ,Div ("",["section"],[])
+ [Div ("",["epigraph"],[])
+ [Para [Str "Subsection",Space,Str "epigraph"]]]]]
diff --git a/test/fb2/reader/meta.fb2 b/test/fb2/reader/meta.fb2
new file mode 100644
index 000000000..7e1736d64
--- /dev/null
+++ b/test/fb2/reader/meta.fb2
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
+ <description>
+ <title-info>
+ <author>
+ <first-name>First</first-name>
+ <middle-name>Middle</middle-name>
+ <last-name>Last</last-name>
+ </author>
+ <author>
+ <first-name>Another</first-name>
+ <last-name>Author</last-name>
+ </author>
+ <book-title>Book title</book-title>
+ <annotation>
+ <p>Book annotation</p>
+ <p>Second paragraph of book annotation</p>
+ </annotation>
+ <keywords>foo, bar, baz</keywords>
+ <date>2018</date>
+ </title-info>
+ </description>
+ <body>
+ <title><p>Body title</p></title>
+ </body>
+</FictionBook>
diff --git a/test/fb2/reader/meta.native b/test/fb2/reader/meta.native
new file mode 100644
index 000000000..71a8795b6
--- /dev/null
+++ b/test/fb2/reader/meta.native
@@ -0,0 +1,2 @@
+Pandoc (Meta {unMeta = fromList [("abstract",MetaBlocks [Para [Str "Book",Space,Str "annotation"],Para [Str "Second",Space,Str "paragraph",Space,Str "of",Space,Str "book",Space,Str "annotation"]]),("author",MetaList [MetaInlines [Str "First",Space,Str "Middle",Space,Str "Last"],MetaInlines [Str "Another",Space,Str "Author"]]),("date",MetaInlines [Str "2018"]),("keywords",MetaList [MetaString "foo",MetaString "bar",MetaString "baz"]),("title",MetaInlines [Str "Book",Space,Str "title"])]})
+[Header 1 ("",[],[]) [Str "Body",Space,Str "title"]]
diff --git a/test/fb2/reader/poem.fb2 b/test/fb2/reader/poem.fb2
new file mode 100644
index 000000000..fcf4a0c02
--- /dev/null
+++ b/test/fb2/reader/poem.fb2
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
+ <body>
+ <section>
+ <poem>
+ <title>
+ <p>Poem title</p>
+ </title>
+ <epigraph>
+ <p>Poem epigraph</p>
+ </epigraph>
+ <stanza>
+ <subtitle>Subtitle</subtitle>
+ <title>
+ <p>First stanza title</p>
+ </title>
+ <v>Verse</v>
+ <v><emphasis>More</emphasis> verse</v>
+ </stanza>
+ <stanza>
+ <v>One more stanza</v>
+ </stanza>
+ <text-author>Author</text-author>
+ <date>April 2018</date>
+ </poem>
+ </section>
+ </body>
+</FictionBook>
diff --git a/test/fb2/reader/poem.native b/test/fb2/reader/poem.native
new file mode 100644
index 000000000..67be6a672
--- /dev/null
+++ b/test/fb2/reader/poem.native
@@ -0,0 +1,14 @@
+Pandoc (Meta {unMeta = fromList []})
+[Div ("",["section"],[])
+ [Header 2 ("",[],[]) [Str "Poem",Space,Str "title"]
+ ,Div ("",["epigraph"],[])
+ [Para [Str "Poem",Space,Str "epigraph"]]
+ ,Header 2 ("",["unnumbered"],[]) [Str "Subtitle"]
+ ,Header 2 ("",[],[]) [Str "First",Space,Str "stanza",Space,Str "title"]
+ ,LineBlock
+ [[Str "Verse"]
+ ,[Emph [Str "More"],Space,Str "verse"]]
+ ,LineBlock
+ [[Str "One",Space,Str "more",Space,Str "stanza"]]
+ ,Para [Str "Author"]
+ ,Para [Str "April",Space,Str "2018"]]]
diff --git a/test/fb2/reader/titles.fb2 b/test/fb2/reader/titles.fb2
new file mode 100644
index 000000000..cfe9588d8
--- /dev/null
+++ b/test/fb2/reader/titles.fb2
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<FictionBook xmlns="http://www.gribuser.ru/xml/fictionbook/2.0" xmlns:l="http://www.w3.org/1999/xlink">
+ <body>
+ <title><p>Body title</p></title>
+ <section>
+ <title><p>Section title</p></title>
+ <section>
+ <title>
+ <p>Subsection title</p>
+ <p>with multiple paragraphs</p>
+ </title>
+ </section>
+ <section>
+ <title><p>Another subsection title</p></title>
+ </section>
+ </section>
+ </body>
+</FictionBook>
diff --git a/test/fb2/reader/titles.native b/test/fb2/reader/titles.native
new file mode 100644
index 000000000..a6c34f5ea
--- /dev/null
+++ b/test/fb2/reader/titles.native
@@ -0,0 +1,8 @@
+Pandoc (Meta {unMeta = fromList []})
+[Header 1 ("",[],[]) [Str "Body",Space,Str "title"]
+,Div ("",["section"],[])
+ [Header 2 ("",[],[]) [Str "Section",Space,Str "title"]
+ ,Div ("",["section"],[])
+ [Header 3 ("",[],[]) [Str "Subsection",Space,Str "title",LineBreak,Str "with",Space,Str "multiple",Space,Str "paragraphs"]]
+ ,Div ("",["section"],[])
+ [Header 3 ("",[],[]) [Str "Another",Space,Str "subsection",Space,Str "title"]]]]
diff --git a/test/test-pandoc.hs b/test/test-pandoc.hs
index 8613d5dda..b70d2286c 100644
--- a/test/test-pandoc.hs
+++ b/test/test-pandoc.hs
@@ -12,6 +12,7 @@ import qualified Tests.Old
import qualified Tests.Readers.Creole
import qualified Tests.Readers.Docx
import qualified Tests.Readers.EPUB
+import qualified Tests.Readers.FB2
import qualified Tests.Readers.HTML
import qualified Tests.Readers.JATS
import qualified Tests.Readers.LaTeX
@@ -75,6 +76,7 @@ tests = testGroup "pandoc tests" [ Tests.Command.tests
, testGroup "EPUB" Tests.Readers.EPUB.tests
, testGroup "Muse" Tests.Readers.Muse.tests
, testGroup "Creole" Tests.Readers.Creole.tests
+ , testGroup "FB2" Tests.Readers.FB2.tests
]
, testGroup "Lua filters" Tests.Lua.tests
]