summaryrefslogtreecommitdiff
path: root/src/Tests/Writers
diff options
context:
space:
mode:
authordr@jones.dk <dr@jones.dk>2011-02-04 00:01:35 +0100
committerdr@jones.dk <dr@jones.dk>2011-02-04 00:01:35 +0100
commit91179df4907bec919e0884019da785be1ceb01b3 (patch)
tree2a6655fb4ec4655c554ea17ad074859d707b7709 /src/Tests/Writers
parent1f6b4aee268fefc72c84bd305b10d4f9103901eb (diff)
Imported Upstream version 1.8.0.1
Diffstat (limited to 'src/Tests/Writers')
-rw-r--r--src/Tests/Writers/ConTeXt.hs72
-rw-r--r--src/Tests/Writers/HTML.hs41
-rw-r--r--src/Tests/Writers/Native.hs20
3 files changed, 133 insertions, 0 deletions
diff --git a/src/Tests/Writers/ConTeXt.hs b/src/Tests/Writers/ConTeXt.hs
new file mode 100644
index 000000000..704571e95
--- /dev/null
+++ b/src/Tests/Writers/ConTeXt.hs
@@ -0,0 +1,72 @@
+{-# 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 5 =:
+(=:) :: (ToString a, ToPandoc a)
+ => String -> (a, String) -> Test
+(=:) = test context
+
+tests :: [Test]
+tests = [ testGroup "inline code"
+ [ "with '}'" =: code "}" =?> "\\mono{\\letterclosebrace{}}"
+ , "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" =?> "\\subject{My header}"
+ , property "header 1 property" $ \ils ->
+ context' (header 1 ils) == "\\subject{" ++ context' ils ++ "}"
+ ]
+ , 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/src/Tests/Writers/HTML.hs b/src/Tests/Writers/HTML.hs
new file mode 100644
index 000000000..e13d0dc87
--- /dev/null
+++ b/src/Tests/Writers/HTML.hs
@@ -0,0 +1,41 @@
+{-# 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 5 =:
+(=:) :: (ToString a, ToPandoc a)
+ => String -> (a, String) -> Test
+(=:) = test html
+
+tests :: [Test]
+tests = [ testGroup "inline code"
+ [ "basic" =: code "@&" =?> "<code>@&amp;</code>"
+ , "haskell" =: codeWith ("",["haskell"],[]) ">>="
+ =?> if null languages
+ then "<code class=\"haskell\">&gt;&gt;=</code>"
+ else "<code class=\"sourceCode haskell\"><span class=\"fu\">&gt;&gt;=</span></code>"
+ , "nolanguage" =: codeWith ("",["nolanguage"],[]) ">>="
+ =?> "<code class=\"nolanguage\">&gt;&gt;=</code>"
+ ]
+ ]
diff --git a/src/Tests/Writers/Native.hs b/src/Tests/Writers/Native.hs
new file mode 100644
index 000000000..234fe938a
--- /dev/null
+++ b/src/Tests/Writers/Native.hs
@@ -0,0 +1,20 @@
+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 =
+ 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
+ ]