diff options
Diffstat (limited to 'tests/Tests/Writers')
-rw-r--r-- | tests/Tests/Writers/ConTeXt.hs | 70 | ||||
-rw-r--r-- | tests/Tests/Writers/HTML.hs | 46 | ||||
-rw-r--r-- | tests/Tests/Writers/LaTeX.hs | 35 | ||||
-rw-r--r-- | tests/Tests/Writers/Markdown.hs | 34 | ||||
-rw-r--r-- | tests/Tests/Writers/Native.hs | 21 |
5 files changed, 206 insertions, 0 deletions
diff --git a/tests/Tests/Writers/ConTeXt.hs b/tests/Tests/Writers/ConTeXt.hs new file mode 100644 index 000000000..beb6411f0 --- /dev/null +++ b/tests/Tests/Writers/ConTeXt.hs @@ -0,0 +1,70 @@ +{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} +module Tests.Writers.ConTeXt (tests) where + +import Test.Framework +import Text.Pandoc.Builder +import Text.Pandoc +import Tests.Helpers +import Tests.Arbitrary() + +context :: (ToString a, ToPandoc a) => a -> String +context = writeConTeXt defaultWriterOptions . toPandoc + +context' :: (ToString a, ToPandoc a) => a -> String +context' = writeConTeXt defaultWriterOptions{ writerWrapText = False } + . toPandoc + +{- + "my test" =: X =?> Y + +is shorthand for + + test context "my test" $ X =?> Y + +which is in turn shorthand for + + test context "my test" (X,Y) +-} + +infix 4 =: +(=:) :: (ToString a, ToPandoc a) + => String -> (a, String) -> Test +(=:) = test context + +tests :: [Test] +tests = [ testGroup "inline code" + [ "with '}'" =: code "}" =?> "\\mono{\\}}" + , "without '}'" =: code "]" =?> "\\type{]}" + , property "code property" $ \s -> null s || + if '{' `elem` s || '}' `elem` s + then (context' $ code s) == "\\mono{" ++ + (context' $ str s) ++ "}" + else (context' $ code s) == "\\type{" ++ s ++ "}" + ] + , testGroup "headers" + [ "level 1" =: + header 1 "My header" =?> "\\section[my-header]{My header}" + ] + , testGroup "bullet lists" + [ "nested" =: + bulletList [plain (text "top") + ,bulletList [plain (text "next") + ,bulletList [plain (text "bot")]]] + =?> [_LIT| +\startitemize +\item + top +\item + \startitemize + \item + next + \item + \startitemize + \item + bot + \stopitemize + \stopitemize +\stopitemize|] + ] + ] + diff --git a/tests/Tests/Writers/HTML.hs b/tests/Tests/Writers/HTML.hs new file mode 100644 index 000000000..8561aa421 --- /dev/null +++ b/tests/Tests/Writers/HTML.hs @@ -0,0 +1,46 @@ +{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} +module Tests.Writers.HTML (tests) where + +import Test.Framework +import Text.Pandoc.Builder +import Text.Pandoc +import Tests.Helpers +import Tests.Arbitrary() +import Text.Pandoc.Highlighting (languages) -- null if no hl support + +html :: (ToString a, ToPandoc a) => a -> String +html = writeHtmlString defaultWriterOptions{ writerWrapText = False } . toPandoc + +{- + "my test" =: X =?> Y + +is shorthand for + + test html "my test" $ X =?> Y + +which is in turn shorthand for + + test html "my test" (X,Y) +-} + +infix 4 =: +(=:) :: (ToString a, ToPandoc a) + => String -> (a, String) -> Test +(=:) = test html + +tests :: [Test] +tests = [ testGroup "inline code" + [ "basic" =: code "@&" =?> "<code>@&</code>" + , "haskell" =: codeWith ("",["haskell"],[]) ">>=" + =?> if null languages + then "<code class=\"haskell\">>>=</code>" + else "<code class=\"sourceCode haskell\"><span class=\"fu\">>>=</span></code>" + , "nolanguage" =: codeWith ("",["nolanguage"],[]) ">>=" + =?> "<code class=\"nolanguage\">>>=</code>" + ] + , testGroup "images" + [ "alt with formatting" =: + image "/url" "title" ("my " <> emph "image") + =?> "<img src=\"/url\" title=\"title\" alt=\"my image\" />" + ] + ] diff --git a/tests/Tests/Writers/LaTeX.hs b/tests/Tests/Writers/LaTeX.hs new file mode 100644 index 000000000..7987716f3 --- /dev/null +++ b/tests/Tests/Writers/LaTeX.hs @@ -0,0 +1,35 @@ +{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} +module Tests.Writers.LaTeX (tests) where + +import Test.Framework +import Text.Pandoc.Builder +import Text.Pandoc +import Tests.Helpers +import Tests.Arbitrary() + +latex :: (ToString a, ToPandoc a) => a -> String +latex = writeLaTeX defaultWriterOptions . toPandoc + +{- + "my test" =: X =?> Y + +is shorthand for + + test latex "my test" $ X =?> Y + +which is in turn shorthand for + + test latex "my test" (X,Y) +-} + +infix 4 =: +(=:) :: (ToString a, ToPandoc a) + => String -> (a, String) -> Test +(=:) = test latex + +tests :: [Test] +tests = [ testGroup "code blocks" + [ "in footnotes" =: note (para "hi" <> codeBlock "hi") =?> + "\\footnote{hi\n\n\\begin{Verbatim}\nhi\n\\end{Verbatim}\n}" + ] + ] diff --git a/tests/Tests/Writers/Markdown.hs b/tests/Tests/Writers/Markdown.hs new file mode 100644 index 000000000..d90dc83b1 --- /dev/null +++ b/tests/Tests/Writers/Markdown.hs @@ -0,0 +1,34 @@ +{-# LANGUAGE OverloadedStrings, QuasiQuotes #-} +module Tests.Writers.Markdown (tests) where + +import Test.Framework +import Text.Pandoc.Builder +import Text.Pandoc +import Tests.Helpers +import Tests.Arbitrary() + +markdown :: (ToString a, ToPandoc a) => a -> String +markdown = writeMarkdown defaultWriterOptions . toPandoc + +{- + "my test" =: X =?> Y + +is shorthand for + + test markdown "my test" $ X =?> Y + +which is in turn shorthand for + + test markdown "my test" (X,Y) +-} + +infix 4 =: +(=:) :: (ToString a, ToPandoc a) + => String -> (a, String) -> Test +(=:) = test markdown + +tests :: [Test] +tests = [ "indented code after list" + =: (orderedList [ para "one" <> para "two" ] <> codeBlock "test") + =?> "1. one\n\n two\n\n<!-- -->\n\n test" + ] diff --git a/tests/Tests/Writers/Native.hs b/tests/Tests/Writers/Native.hs new file mode 100644 index 000000000..19740e0f4 --- /dev/null +++ b/tests/Tests/Writers/Native.hs @@ -0,0 +1,21 @@ +module Tests.Writers.Native (tests) where + +import Test.Framework +import Text.Pandoc.Builder +import Text.Pandoc +import Tests.Helpers +import Tests.Arbitrary() + +p_write_rt :: Pandoc -> Bool +p_write_rt d = + read (writeNative defaultWriterOptions{ writerStandalone = True } d) == d + +p_write_blocks_rt :: [Block] -> Bool +p_write_blocks_rt bs = length bs > 20 || + read (writeNative defaultWriterOptions (Pandoc (Meta [] [] []) bs)) == + bs + +tests :: [Test] +tests = [ property "p_write_rt" p_write_rt + , property "p_write_blocks_rt" p_write_blocks_rt + ] |