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
|
2011-02-05 03:33:08 +01:00
|
|
|
|
-- import Text.Pandoc.Shared ( normalize )
|
2011-01-27 07:09:09 +01:00
|
|
|
|
import Text.Pandoc
|
|
|
|
|
|
|
|
|
|
markdown :: String -> Pandoc
|
2012-07-26 07:35:41 +02:00
|
|
|
|
markdown = readMarkdown def
|
2011-01-27 07:09:09 +01:00
|
|
|
|
|
2011-07-26 08:49:45 +02:00
|
|
|
|
markdownSmart :: String -> Pandoc
|
2012-07-26 07:35:41 +02:00
|
|
|
|
markdownSmart = readMarkdown def { readerSmart = True }
|
2011-07-26 08:49:45 +02:00
|
|
|
|
|
2012-02-05 22:23:06 +01:00
|
|
|
|
infix 4 =:
|
2011-01-27 07:09:09 +01:00
|
|
|
|
(=:) :: ToString c
|
|
|
|
|
=> String -> (String, c) -> Test
|
|
|
|
|
(=:) = test markdown
|
|
|
|
|
|
2011-02-05 03:33:08 +01:00
|
|
|
|
{-
|
|
|
|
|
p_markdown_round_trip :: Block -> Bool
|
|
|
|
|
p_markdown_round_trip b = matches d' d''
|
|
|
|
|
where d' = normalize $ Pandoc (Meta [] [] []) [b]
|
|
|
|
|
d'' = normalize
|
2012-07-26 07:35:41 +02:00
|
|
|
|
$ readMarkdown def { readerSmart = True }
|
2012-07-27 07:59:56 +02:00
|
|
|
|
$ writeMarkdown def d'
|
2011-02-05 03:33:08 +01:00
|
|
|
|
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")]) "*")
|
|
|
|
|
]
|
2011-12-02 04:47:25 +01:00
|
|
|
|
, testGroup "backslash escapes"
|
|
|
|
|
[ "in URL" =:
|
|
|
|
|
"[hi](/there\\))"
|
2011-12-06 06:13:06 +01:00
|
|
|
|
=?> para (link "/there)" "" "hi")
|
2011-12-05 07:37:28 +01:00
|
|
|
|
, "in title" =:
|
2011-12-06 06:16:30 +01:00
|
|
|
|
"[hi](/there \"a\\\"a\")"
|
2011-12-06 06:13:06 +01:00
|
|
|
|
=?> para (link "/there" "a\"a" "hi")
|
2011-12-06 04:07:17 +01:00
|
|
|
|
, "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")
|
2011-12-06 04:07:17 +01:00
|
|
|
|
, "in reference link URL" =:
|
2011-12-06 06:16:30 +01:00
|
|
|
|
"[hi]\n\n[hi]: /there\\.0"
|
|
|
|
|
=?> para (link "/there.0" "" "hi")
|
2011-12-02 04:47:25 +01:00
|
|
|
|
]
|
2011-07-26 08:49:45 +02:00
|
|
|
|
, testGroup "smart punctuation"
|
|
|
|
|
[ test markdownSmart "quote before ellipses"
|
|
|
|
|
("'...hi'"
|
2011-12-28 00:45:34 +01:00
|
|
|
|
=?> para (singleQuoted ("…hi")))
|
2011-12-27 08:03:20 +01:00
|
|
|
|
, test markdownSmart "apostrophe before emph"
|
|
|
|
|
("D'oh! A l'*aide*!"
|
|
|
|
|
=?> para ("D’oh! A l’" <> emph "aide" <> "!"))
|
|
|
|
|
, test markdownSmart "apostrophe in French"
|
|
|
|
|
("À l'arrivée de la guerre, le thème de l'«impossibilité du socialisme»"
|
|
|
|
|
=?> para ("À l’arrivée de la guerre, le thème de l’«impossibilité du socialisme»"))
|
2011-07-26 08:49:45 +02:00
|
|
|
|
]
|
2011-06-23 05:37:57 +02:00
|
|
|
|
, testGroup "mixed emphasis and strong"
|
|
|
|
|
[ "emph and strong emph alternating" =:
|
2011-06-23 05:18:32 +02:00
|
|
|
|
"*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")
|
2011-06-23 05:37:57 +02:00
|
|
|
|
, "emph with spaced strong" =:
|
|
|
|
|
"*x **xx** x*"
|
2011-12-13 23:29:07 +01:00
|
|
|
|
=?> para (emph ("x" <> space <> strong "xx" <> space <> "x"))
|
2011-06-23 05:18:32 +02:00
|
|
|
|
]
|
2011-02-01 05:05:11 +01:00
|
|
|
|
, testGroup "footnotes"
|
2011-02-01 16:37:22 +01:00
|
|
|
|
[ "indent followed by newline and flush-left text" =:
|
2011-02-01 05:42:49 +01:00
|
|
|
|
"[^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" =:
|
2011-02-02 07:35:27 +01:00
|
|
|
|
"[^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"))
|
2011-04-20 20:42:27 +02:00
|
|
|
|
, "recursive note" =:
|
|
|
|
|
"[^1]\n\n[^1]: See [^1]\n"
|
|
|
|
|
=?> para (note (para "See [^1]"))
|
2011-02-01 05:05:11 +01:00
|
|
|
|
]
|
2011-03-02 20:18:38 +01:00
|
|
|
|
, testGroup "lhs"
|
2012-07-26 07:35:41 +02:00
|
|
|
|
[ test (readMarkdown def{ readerLiterateHaskell = True })
|
2011-03-02 20:18:38 +01:00
|
|
|
|
"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
|
|
|
|
<>
|
2011-03-02 20:18:38 +01:00
|
|
|
|
codeBlockWith ("",["sourceCode","haskell"],[]) "b"
|
2011-12-13 23:29:07 +01:00
|
|
|
|
<>
|
2011-03-02 20:18:38 +01:00
|
|
|
|
rawBlock "html" "<div>\n\n"
|
|
|
|
|
]
|
2011-02-05 03:33:08 +01:00
|
|
|
|
-- 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
|
|
|
|
]
|