Blame test/Tests/Writers/Docbook.hs

Packit Service d2f85f
{-# LANGUAGE OverloadedStrings #-}
Packit Service d2f85f
module Tests.Writers.Docbook (tests) where
Packit Service d2f85f
Packit Service d2f85f
import Data.Text (unpack)
Packit Service d2f85f
import Test.Tasty
Packit Service d2f85f
import Tests.Helpers
Packit Service d2f85f
import Text.Pandoc
Packit Service d2f85f
import Text.Pandoc.Arbitrary ()
Packit Service d2f85f
import Text.Pandoc.Builder
Packit Service d2f85f
Packit Service d2f85f
docbook :: (ToPandoc a) => a -> String
Packit Service d2f85f
docbook = docbookWithOpts def{ writerWrapText = WrapNone }
Packit Service d2f85f
Packit Service d2f85f
docbookWithOpts :: ToPandoc a => WriterOptions -> a -> String
Packit Service d2f85f
docbookWithOpts opts = unpack . purely (writeDocbook4 opts) . toPandoc
Packit Service d2f85f
Packit Service d2f85f
{-
Packit Service d2f85f
  "my test" =: X =?> Y
Packit Service d2f85f
Packit Service d2f85f
is shorthand for
Packit Service d2f85f
Packit Service d2f85f
  test docbook "my test" $ X =?> Y
Packit Service d2f85f
Packit Service d2f85f
which is in turn shorthand for
Packit Service d2f85f
Packit Service d2f85f
  test docbook "my test" (X,Y)
Packit Service d2f85f
-}
Packit Service d2f85f
Packit Service d2f85f
infix 4 =:
Packit Service d2f85f
(=:) :: (ToString a, ToPandoc a)
Packit Service d2f85f
     => String -> (a, String) -> TestTree
Packit Service d2f85f
(=:) = test docbook
Packit Service d2f85f
Packit Service d2f85f
lineblock :: Blocks
Packit Service d2f85f
lineblock = para ("some text" <> linebreak <>
Packit Service d2f85f
                  "and more lines" <> linebreak <>
Packit Service d2f85f
                  "and again")
Packit Service d2f85f
lineblock_out :: [String]
Packit Service d2f85f
lineblock_out = [ "<literallayout>some text"
Packit Service d2f85f
                , "and more lines"
Packit Service d2f85f
                , "and again</literallayout>"
Packit Service d2f85f
                ]
Packit Service d2f85f
Packit Service d2f85f
tests :: [TestTree]
Packit Service d2f85f
tests = [ testGroup "line blocks"
Packit Service d2f85f
          [ "none"       =: para "This is a test"
Packit Service d2f85f
                              =?> unlines
Packit Service d2f85f
                                    [ "<para>"
Packit Service d2f85f
                                    , "  This is a test"
Packit Service d2f85f
                                    , "</para>"
Packit Service d2f85f
                                    ]
Packit Service d2f85f
          , "basic"      =: lineblock
Packit Service d2f85f
                              =?> unlines lineblock_out
Packit Service d2f85f
          , "blockquote" =: blockQuote lineblock
Packit Service d2f85f
                              =?> unlines
Packit Service d2f85f
                                    ( [ "
" ] ++
Packit Service d2f85f
                                      lineblock_out ++
Packit Service d2f85f
                                      [ "" ]
Packit Service d2f85f
                                    )
Packit Service d2f85f
          , "footnote"   =: para ("This is a test" <>
Packit Service d2f85f
                                  note lineblock <>
Packit Service d2f85f
                                  " of footnotes")
Packit Service d2f85f
                              =?> unlines
Packit Service d2f85f
                                    ( [ "<para>"
Packit Service d2f85f
                                      , "  This is a test<footnote>" ] ++
Packit Service d2f85f
                                      lineblock_out ++
Packit Service d2f85f
                                      [ "  </footnote> of footnotes"
Packit Service d2f85f
                                      , "</para>" ]
Packit Service d2f85f
                                    )
Packit Service d2f85f
          ]
Packit Service d2f85f
        , testGroup "compact lists"
Packit Service d2f85f
          [ testGroup "bullet"
Packit Service d2f85f
            [ "compact"    =: bulletList [plain "a", plain "b", plain "c"]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<itemizedlist spacing=\"compact\">"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      b"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      c"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "</itemizedlist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            , "loose"      =: bulletList [para "a", para "b", para "c"]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<itemizedlist>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      b"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      c"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "</itemizedlist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            ]
Packit Service d2f85f
          , testGroup "ordered"
Packit Service d2f85f
            [ "compact"    =: orderedList [plain "a", plain "b", plain "c"]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<orderedlist spacing=\"compact\">"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      b"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      c"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "</orderedlist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            , "loose"      =: orderedList [para "a", para "b", para "c"]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<orderedlist>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      b"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "  <listitem>"
Packit Service d2f85f
                                      , "    <para>"
Packit Service d2f85f
                                      , "      c"
Packit Service d2f85f
                                      , "    </para>"
Packit Service d2f85f
                                      , "  </listitem>"
Packit Service d2f85f
                                      , "</orderedlist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            ]
Packit Service d2f85f
          , testGroup "definition"
Packit Service d2f85f
            [ "compact"    =: definitionList [ ("an", [plain "apple" ])
Packit Service d2f85f
                                             , ("a",  [plain "banana"])
Packit Service d2f85f
                                             , ("an", [plain "orange"])]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<variablelist spacing=\"compact\">"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      an"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        apple"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        banana"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      an"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        orange"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "</variablelist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            , "loose"      =: definitionList [ ("an", [para "apple" ])
Packit Service d2f85f
                                             , ("a",  [para "banana"])
Packit Service d2f85f
                                             , ("an", [para "orange"])]
Packit Service d2f85f
                                =?> unlines
Packit Service d2f85f
                                      [ "<variablelist>"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      an"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        apple"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      a"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        banana"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "  <varlistentry>"
Packit Service d2f85f
                                      , "    <term>"
Packit Service d2f85f
                                      , "      an"
Packit Service d2f85f
                                      , "    </term>"
Packit Service d2f85f
                                      , "    <listitem>"
Packit Service d2f85f
                                      , "      <para>"
Packit Service d2f85f
                                      , "        orange"
Packit Service d2f85f
                                      , "      </para>"
Packit Service d2f85f
                                      , "    </listitem>"
Packit Service d2f85f
                                      , "  </varlistentry>"
Packit Service d2f85f
                                      , "</variablelist>"
Packit Service d2f85f
                                      ]
Packit Service d2f85f
            ]
Packit Service d2f85f
          ]
Packit Service d2f85f
        , testGroup "writer options" $
Packit Service d2f85f
          [ testGroup "top-level division" $
Packit Service d2f85f
            let
Packit Service d2f85f
              headers =  header 1 (text "header1")
Packit Service d2f85f
                      <> header 2 (text "header2")
Packit Service d2f85f
                      <> header 3 (text "header3")
Packit Service d2f85f
Packit Service d2f85f
              docbookTopLevelDiv :: (ToPandoc a)
Packit Service d2f85f
                                 => TopLevelDivision -> a -> String
Packit Service d2f85f
              docbookTopLevelDiv division =
Packit Service d2f85f
                docbookWithOpts def{ writerTopLevelDivision = division }
Packit Service d2f85f
            in
Packit Service d2f85f
            [ test (docbookTopLevelDiv TopLevelSection) "sections as top-level" $
Packit Service d2f85f
              headers =?>
Packit Service d2f85f
              unlines [ "<sect1>"
Packit Service d2f85f
                      , "  <title>header1</title>"
Packit Service d2f85f
                      , "  <sect2>"
Packit Service d2f85f
                      , "    <title>header2</title>"
Packit Service d2f85f
                      , "    <sect3>"
Packit Service d2f85f
                      , "      <title>header3</title>"
Packit Service d2f85f
                      , "      <para>"
Packit Service d2f85f
                      , "      </para>"
Packit Service d2f85f
                      , "    </sect3>"
Packit Service d2f85f
                      , "  </sect2>"
Packit Service d2f85f
                      , "</sect1>"
Packit Service d2f85f
                      ]
Packit Service d2f85f
            , test (docbookTopLevelDiv TopLevelChapter) "chapters as top-level" $
Packit Service d2f85f
              headers =?>
Packit Service d2f85f
              unlines [ "<chapter>"
Packit Service d2f85f
                      , "  <title>header1</title>"
Packit Service d2f85f
                      , "  <sect1>"
Packit Service d2f85f
                      , "    <title>header2</title>"
Packit Service d2f85f
                      , "    <sect2>"
Packit Service d2f85f
                      , "      <title>header3</title>"
Packit Service d2f85f
                      , "      <para>"
Packit Service d2f85f
                      , "      </para>"
Packit Service d2f85f
                      , "    </sect2>"
Packit Service d2f85f
                      , "  </sect1>"
Packit Service d2f85f
                      , "</chapter>"
Packit Service d2f85f
                      ]
Packit Service d2f85f
            , test (docbookTopLevelDiv TopLevelPart) "parts as top-level" $
Packit Service d2f85f
              headers =?>
Packit Service d2f85f
              unlines [ "<part>"
Packit Service d2f85f
                      , "  <title>header1</title>"
Packit Service d2f85f
                      , "  <chapter>"
Packit Service d2f85f
                      , "    <title>header2</title>"
Packit Service d2f85f
                      , "    <sect1>"
Packit Service d2f85f
                      , "      <title>header3</title>"
Packit Service d2f85f
                      , "      <para>"
Packit Service d2f85f
                      , "      </para>"
Packit Service d2f85f
                      , "    </sect1>"
Packit Service d2f85f
                      , "  </chapter>"
Packit Service d2f85f
                      , "</part>"
Packit Service d2f85f
                      ]
Packit Service d2f85f
            , test (docbookTopLevelDiv TopLevelDefault) "default top-level" $
Packit Service d2f85f
              headers =?>
Packit Service d2f85f
              unlines [ "<sect1>"
Packit Service d2f85f
                      , "  <title>header1</title>"
Packit Service d2f85f
                      , "  <sect2>"
Packit Service d2f85f
                      , "    <title>header2</title>"
Packit Service d2f85f
                      , "    <sect3>"
Packit Service d2f85f
                      , "      <title>header3</title>"
Packit Service d2f85f
                      , "      <para>"
Packit Service d2f85f
                      , "      </para>"
Packit Service d2f85f
                      , "    </sect3>"
Packit Service d2f85f
                      , "  </sect2>"
Packit Service d2f85f
                      , "</sect1>"
Packit Service d2f85f
                      ]
Packit Service d2f85f
            ]
Packit Service d2f85f
          ]
Packit Service d2f85f
        ]