2018-03-18 18:46:28 +01:00
|
|
|
{-# LANGUAGE NoImplicitPrelude #-}
|
2013-01-23 17:47:43 +01:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2011-01-30 01:26:00 +01:00
|
|
|
module Tests.Writers.HTML (tests) where
|
|
|
|
|
2018-03-18 18:46:28 +01:00
|
|
|
import Prelude
|
2017-06-10 23:39:49 +02:00
|
|
|
import Data.Text (unpack)
|
2017-03-14 17:05:36 +01:00
|
|
|
import Test.Tasty
|
2011-01-30 01:26:00 +01:00
|
|
|
import Tests.Helpers
|
2017-03-04 13:03:41 +01:00
|
|
|
import Text.Pandoc
|
|
|
|
import Text.Pandoc.Arbitrary ()
|
|
|
|
import Text.Pandoc.Builder
|
2011-01-30 01:26:00 +01:00
|
|
|
|
2016-07-14 17:54:06 +02:00
|
|
|
html :: (ToPandoc a) => a -> String
|
2017-06-10 23:39:49 +02:00
|
|
|
html = unpack . purely (writeHtml4String def{ writerWrapText = WrapNone }) . toPandoc
|
2011-01-30 01:26:00 +01:00
|
|
|
|
2019-10-25 07:27:49 +02:00
|
|
|
htmlQTags :: (ToPandoc a) => a -> String
|
|
|
|
htmlQTags = unpack
|
|
|
|
. purely (writeHtml4String def{ writerWrapText = WrapNone, writerHtmlQTags = True })
|
|
|
|
. toPandoc
|
|
|
|
|
2011-01-30 01:26:00 +01:00
|
|
|
{-
|
|
|
|
"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)
|
|
|
|
-}
|
|
|
|
|
2012-02-05 22:23:06 +01:00
|
|
|
infix 4 =:
|
2011-01-30 01:26:00 +01:00
|
|
|
(=:) :: (ToString a, ToPandoc a)
|
2017-03-14 17:05:36 +01:00
|
|
|
=> String -> (a, String) -> TestTree
|
2011-01-30 01:26:00 +01:00
|
|
|
(=:) = test html
|
|
|
|
|
2017-03-14 17:05:36 +01:00
|
|
|
tests :: [TestTree]
|
2011-01-30 01:26:00 +01:00
|
|
|
tests = [ testGroup "inline code"
|
|
|
|
[ "basic" =: code "@&" =?> "<code>@&</code>"
|
|
|
|
, "haskell" =: codeWith ("",["haskell"],[]) ">>="
|
2019-02-10 17:06:53 +01:00
|
|
|
=?> "<code class=\"sourceCode haskell\"><span class=\"op\">>>=</span></code>"
|
2011-01-30 01:26:00 +01:00
|
|
|
, "nolanguage" =: codeWith ("",["nolanguage"],[]) ">>="
|
|
|
|
=?> "<code class=\"nolanguage\">>>=</code>"
|
|
|
|
]
|
2011-02-05 17:16:34 +01:00
|
|
|
, testGroup "images"
|
|
|
|
[ "alt with formatting" =:
|
2011-12-13 23:29:07 +01:00
|
|
|
image "/url" "title" ("my " <> emph "image")
|
2011-02-05 17:16:34 +01:00
|
|
|
=?> "<img src=\"/url\" title=\"title\" alt=\"my image\" />"
|
|
|
|
]
|
2018-09-11 12:12:00 +02:00
|
|
|
, testGroup "blocks"
|
|
|
|
[ "definition list with empty <dt>" =:
|
|
|
|
definitionList [(mempty, [para $ text "foo bar"])]
|
|
|
|
=?> "<dl><dt></dt><dd><p>foo bar</p></dd></dl>"
|
|
|
|
]
|
2019-10-25 07:27:49 +02:00
|
|
|
, testGroup "quotes"
|
|
|
|
[ "quote with cite attribute (without q-tags)" =:
|
|
|
|
doubleQuoted (spanWith ("", [], [("cite", "http://example.org")]) (str "examples"))
|
|
|
|
=?> "“<span cite=\"http://example.org\">examples</span>”"
|
|
|
|
, tQ "quote with cite attribute (with q-tags)" $
|
|
|
|
doubleQuoted (spanWith ("", [], [("cite", "http://example.org")]) (str "examples"))
|
|
|
|
=?> "<q cite=\"http://example.org\">examples</q>"
|
|
|
|
]
|
2019-11-04 17:42:30 +01:00
|
|
|
, testGroup "sample"
|
|
|
|
[ "sample should be rendered correctly" =:
|
|
|
|
plain (codeWith ("",["sample"],[]) "Answer is 42") =?>
|
|
|
|
"<samp>Answer is 42</samp>"
|
|
|
|
]
|
|
|
|
, testGroup "variable"
|
|
|
|
[ "variable should be rendered correctly" =:
|
|
|
|
plain (codeWith ("",["variable"],[]) "result") =?>
|
|
|
|
"<var>result</var>"
|
|
|
|
]
|
|
|
|
, testGroup "sample with style"
|
|
|
|
[ "samp should wrap highlighted code" =:
|
|
|
|
codeWith ("",["sample","haskell"],[]) ">>="
|
2020-02-07 17:32:47 +01:00
|
|
|
=?> ("<samp><code class=\"sourceCode haskell\">" ++
|
2019-11-04 17:42:30 +01:00
|
|
|
"<span class=\"op\">>>=</span></code></samp>")
|
|
|
|
]
|
|
|
|
, testGroup "variable with style"
|
|
|
|
[ "var should wrap highlighted code" =:
|
|
|
|
codeWith ("",["haskell","variable"],[]) ">>="
|
2020-02-07 17:32:47 +01:00
|
|
|
=?> ("<var><code class=\"sourceCode haskell\">" ++
|
2019-11-04 17:42:30 +01:00
|
|
|
"<span class=\"op\">>>=</span></code></var>")
|
|
|
|
]
|
2011-01-30 01:26:00 +01:00
|
|
|
]
|
2019-10-25 07:27:49 +02:00
|
|
|
where
|
|
|
|
tQ :: (ToString a, ToPandoc a)
|
|
|
|
=> String -> (a, String) -> TestTree
|
|
|
|
tQ = test htmlQTags
|