gemoire-1.0.0: test/Case/Converter.hs
{-# LANGUAGE OverloadedStrings #-}
module Case.Converter
( converter
) where
import qualified Data.Text as T
import Test.HUnit (Test, (~=?))
import Gemoire.Converter (Conversion (..), convertDocument, defMarkdownConversion, defWebConversion)
import Gemoire.Template (vempty, vlist)
converter :: [Test]
converter = conversion <> rewriting
conversion :: [Test]
conversion =
let document =
T.unlines . map (<> "\CR") $
[ "# title"
, ""
, "=> link.gmi"
, "=> link.gmi with description"
, "> quote"
, "text <escaped> [this too]"
, "## h2"
, "### h3"
, "* item1"
, "* item2"
, "- this is also text"
, "``` 'alt'"
, " preformatted"
, "```"
]
web =
T.unlines
[ "<!DOCTYPE html>"
, "<html>"
, " <head>"
, " <title>overridden</title>"
, " </head>"
, " <body>"
, ""
, "<h1>title</h1>"
, "<p></p>"
, "<a href=\"link.gmi\">link.gmi</a>"
, "<a href=\"link.gmi\">with description</a>"
, "<blockquote>"
, " quote"
, "</blockquote>"
, "<p>text <escaped> [this too]</p>"
, "<h2>h2</h2>"
, "<h3>h3</h3>"
, "<ul>"
, " <li>item1</li>"
, " <li>item2</li>"
, "</ul>"
, "<p>- this is also text</p>"
, "<pre title=\"'alt'\">"
, " preformatted"
, "</pre>"
, ""
, " </body>"
, "</html>"
]
markdown =
T.unlines
[ "# title"
, " "
, "[link.gmi](link.gmi) "
, "[with description](link.gmi) "
, "> quote"
, "text <escaped> \\[this too\\] "
, "## h2"
, "### h3"
, "- item1"
, "- item2"
, "\\- this is also text "
, "```'alt'"
, " preformatted"
, "```"
]
in [ web ~=? convertDocument (vlist [("title", "overridden")]) defWebConversion document
, markdown ~=? convertDocument vempty defMarkdownConversion document
]
rewriting :: [Test]
rewriting =
let document = "=> gemini://example.com/gemlog/post.gmi post\CR\LF"
markdown = "[post](https://example.com/gemlog/post.html) \LF"
in [ markdown
~=? convertDocument
vempty
( defMarkdownConversion
{ rewriteRules =
[
( ".*\\.gmi"
, "((https*)|(gemini))://example.com/(.*)\\.gmi"
, "https://example.com/\\4.html"
, True
, True
)
]
}
)
document
]