{-# LANGUAGE OverloadedStrings #-}
module Tests.Readers.Muse (tests) where
import Data.List (intersperse)
import Data.Text (Text)
import qualified Data.Text as T
import Test.Tasty
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
import Text.Pandoc.Class
muse :: Text -> Pandoc
muse = purely $ \s -> do
putCommonState
def { stInputFiles = Just ["in"]
, stOutputFile = Just "out"
}
readMuse def s
infix 4 =:
(=:) :: ToString c
=> String -> (Text, c) -> TestTree
(=:) = test muse
spcSep :: [Inlines] -> Inlines
spcSep = mconcat . intersperse space
tests :: [TestTree]
tests =
[ testGroup "Inlines"
[ "Plain String" =:
"Hello, World" =?>
para (spcSep [ "Hello,", "World" ])
, "Emphasis" =: "*Foo bar*" =?> para (emph . spcSep $ ["Foo", "bar"])
, "Emphasis tag" =: "Foo bar" =?> para (emph . spcSep $ ["Foo", "bar"])
, "Strong" =:
"**Cider**" =?>
para (strong "Cider")
, "Strong tag" =: "Strong" =?> para (strong "Strong")
, "Strong Emphasis" =:
"***strength***" =?>
para (strong . emph $ "strength")
, "Superscript tag" =: "Superscript" =?> para (superscript "Superscript")
, "Subscript tag" =: "Subscript" =?> para (subscript "Subscript")
, "Strikeout tag" =: "Strikeout" =?> para (strikeout "Strikeout")
, "Linebreak" =: "Line
break" =?> para ("Line" <> linebreak <> "break")
, "Code" =: "=foo(bar)=" =?> para (code "foo(bar)")
, "Not code" =: "a=b= =c=d" =?> para (text "a=b= =c=d")
, "Code tag" =: "foo(bar)
" =?> para (code "foo(bar)")
, testGroup "Links"
[ "Link without description" =:
"[[https://amusewiki.org/]]" =?>
para (link "https://amusewiki.org/" "" (str "https://amusewiki.org/"))
, "Link with description" =:
"[[https://amusewiki.org/][A Muse Wiki]]" =?>
para (link "https://amusewiki.org/" "" (text "A Muse Wiki"))
, "Image" =:
"[[image.jpg]]" =?>
para (image "image.jpg" "" mempty)
, "Image with description" =:
"[[image.jpg][Image]]" =?>
para (image "image.jpg" "" (text "Image"))
, "Image link" =:
"[[URL:image.jpg]]" =?>
para (link "image.jpg" "" (str "image.jpg"))
, "Image link with description" =:
"[[URL:image.jpg][Image]]" =?>
para (link "image.jpg" "" (text "Image"))
-- Implicit links are supported in Emacs Muse, but not in Amusewiki:
-- https://github.com/melmothx/text-amuse/issues/18
--
-- This test also makes sure '=' without whitespace is not treated as code markup
, "No implicit links" =: "http://example.org/index.php?action=view&id=1"
=?> para "http://example.org/index.php?action=view&id=1"
]
]
, testGroup "Blocks"
[ "Block elements end paragraphs" =:
T.unlines [ "First paragraph"
, "----"
, "Second paragraph"
] =?> para (text "First paragraph") <> horizontalRule <> para (text "Second paragraph")
, testGroup "Horizontal rule"
[ "Less than 4 dashes is not a horizontal rule" =: "---" =?> para (text "---")
, "4 dashes is a horizontal rule" =: "----" =?> horizontalRule
, "5 dashes is a horizontal rule" =: "-----" =?> horizontalRule
, "4 dashes with spaces is a horizontal rule" =: "---- " =?> horizontalRule
]
, "Quote tag" =: "Hello, world
" =?> blockQuote (para $ text "Hello, world")
, "Quote" =: " This is a quotation\n" =?> blockQuote (para $ text "This is a quotation")
, "Multiline quote" =: T.unlines [ " This is a quotation"
, " with a continuation"
]
=?> blockQuote (para $ text "This is a quotation with a continuation")
, "Center" =: "