pandoc/tests/Tests/Readers/Markdown.hs

108 lines
4.1 KiB
Haskell
Raw Normal View History

2011-01-27 07:09:09 +01:00
{-# LANGUAGE OverloadedStrings, QuasiQuotes #-}
module Tests.Readers.Markdown (tests) where
import Text.Pandoc.Definition
import Test.Framework
import Tests.Helpers
import Tests.Arbitrary()
import Text.Pandoc.Builder
-- import Text.Pandoc.Shared ( normalize )
2011-01-27 07:09:09 +01:00
import Text.Pandoc
markdown :: String -> Pandoc
markdown = readMarkdown def
2011-01-27 07:09:09 +01:00
markdownSmart :: String -> Pandoc
markdownSmart = readMarkdown def { readerSmart = True }
infix 4 =:
2011-01-27 07:09:09 +01:00
(=:) :: ToString c
=> String -> (String, c) -> Test
(=:) = test markdown
{-
p_markdown_round_trip :: Block -> Bool
p_markdown_round_trip b = matches d' d''
where d' = normalize $ Pandoc (Meta [] [] []) [b]
d'' = normalize
$ readMarkdown def { readerSmart = True }
$ writeMarkdown def d'
matches (Pandoc _ [Plain []]) (Pandoc _ []) = True
matches (Pandoc _ [Para []]) (Pandoc _ []) = True
matches (Pandoc _ [Plain xs]) (Pandoc _ [Para xs']) = xs == xs'
matches x y = x == y
-}
2011-01-27 07:09:09 +01:00
tests :: [Test]
tests = [ testGroup "inline code"
[ "with attribute" =:
"`document.write(\"Hello\");`{.javascript}"
=?> para
(codeWith ("",["javascript"],[]) "document.write(\"Hello\");")
, "with attribute space" =:
"`*` {.haskell .special x=\"7\"}"
=?> para (codeWith ("",["haskell","special"],[("x","7")]) "*")
]
, testGroup "backslash escapes"
[ "in URL" =:
"[hi](/there\\))"
2011-12-06 06:13:06 +01:00
=?> para (link "/there)" "" "hi")
, "in title" =:
"[hi](/there \"a\\\"a\")"
2011-12-06 06:13:06 +01:00
=?> para (link "/there" "a\"a" "hi")
, "in reference link title" =:
"[hi]\n\n[hi]: /there (a\\)a)"
2011-12-06 06:13:06 +01:00
=?> para (link "/there" "a)a" "hi")
, "in reference link URL" =:
"[hi]\n\n[hi]: /there\\.0"
=?> para (link "/there.0" "" "hi")
]
, testGroup "smart punctuation"
[ test markdownSmart "quote before ellipses"
("'...hi'"
=?> para (singleQuoted ("…hi")))
, test markdownSmart "apostrophe before emph"
("D'oh! A l'*aide*!"
=?> para ("Doh! A l" <> emph "aide" <> "!"))
, test markdownSmart "apostrophe in French"
("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
=?> para ("À larrivée de la guerre, le thème de l«impossibilité du socialisme»"))
]
, testGroup "mixed emphasis and strong"
[ "emph and strong emph alternating" =:
"*xxx* ***xxx*** xxx\n*xxx* ***xxx*** xxx"
2011-12-13 23:29:07 +01:00
=?> para (emph "xxx" <> space <> strong (emph "xxx") <>
space <> "xxx" <> space <>
emph "xxx" <> space <> strong (emph "xxx") <>
space <> "xxx")
, "emph with spaced strong" =:
"*x **xx** x*"
2011-12-13 23:29:07 +01:00
=?> para (emph ("x" <> space <> strong "xx" <> space <> "x"))
]
, testGroup "footnotes"
2011-02-01 16:37:22 +01:00
[ "indent followed by newline and flush-left text" =:
"[^1]\n\n[^1]: my note\n\n \nnot in note\n"
2011-12-13 23:29:07 +01:00
=?> para (note (para "my note")) <> para "not in note"
2011-02-01 16:37:22 +01:00
, "indent followed by newline and indented text" =:
"[^1]\n\n[^1]: my note\n \n in note\n"
2011-12-13 23:29:07 +01:00
=?> para (note (para "my note" <> para "in note"))
, "recursive note" =:
"[^1]\n\n[^1]: See [^1]\n"
=?> para (note (para "See [^1]"))
]
, testGroup "lhs"
[ test (readMarkdown def{ readerLiterateHaskell = True })
"inverse bird tracks and html" $
"> a\n\n< b\n\n<div>\n"
=?> codeBlockWith ("",["sourceCode","literate","haskell"],[]) "a"
2011-12-13 23:29:07 +01:00
<>
codeBlockWith ("",["sourceCode","haskell"],[]) "b"
2011-12-13 23:29:07 +01:00
<>
rawBlock "html" "<div>\n\n"
]
-- the round-trip properties frequently fail
-- , testGroup "round trip"
-- [ property "p_markdown_round_trip" p_markdown_round_trip
-- ]
2011-01-27 07:09:09 +01:00
]