aboutsummaryrefslogtreecommitdiff
path: root/test/Tests
diff options
context:
space:
mode:
authorYan Pas <yanp.bugz@gmail.com>2018-10-07 18:10:01 +0300
committerYan Pas <yanp.bugz@gmail.com>2018-10-07 18:10:01 +0300
commit27467189ab184c5d098e244e01f7d1bfdb0d4d45 (patch)
treed1fb96ebbc49ee0c4e73ef354feddd521690d545 /test/Tests
parent4f3dd3b1af7217214287ab886147c5e33a54774d (diff)
parentbd8a66394bc25b52dca9ffd963a560a4ca492f9c (diff)
downloadpandoc-27467189ab184c5d098e244e01f7d1bfdb0d4d45.tar.gz
Merge branch 'master' into groff_reader
Diffstat (limited to 'test/Tests')
-rw-r--r--test/Tests/Lua.hs19
-rw-r--r--test/Tests/Readers/HTML.hs25
-rw-r--r--test/Tests/Readers/Markdown.hs12
-rw-r--r--test/Tests/Readers/Muse.hs85
-rw-r--r--test/Tests/Readers/Org/Block/Header.hs38
-rw-r--r--test/Tests/Readers/Org/Block/List.hs11
-rw-r--r--test/Tests/Readers/Org/Directive.hs23
-rw-r--r--test/Tests/Readers/Org/Inline.hs9
-rw-r--r--test/Tests/Readers/RST.hs16
-rw-r--r--test/Tests/Writers/HTML.hs5
-rw-r--r--test/Tests/Writers/Muse.hs94
-rw-r--r--test/Tests/Writers/RST.hs8
12 files changed, 307 insertions, 38 deletions
diff --git a/test/Tests/Lua.hs b/test/Tests/Lua.hs
index 28a691715..3fe9c1121 100644
--- a/test/Tests/Lua.hs
+++ b/test/Tests/Lua.hs
@@ -7,7 +7,7 @@ import Control.Monad (when)
import Data.Version (Version (versionBranch))
import System.FilePath ((</>))
import Test.Tasty (TestTree, localOption)
-import Test.Tasty.HUnit (Assertion, assertEqual, testCase)
+import Test.Tasty.HUnit (Assertion, assertEqual, assertFailure, testCase)
import Test.Tasty.QuickCheck (QuickCheckTests (..), ioProperty, testProperty)
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder (bulletList, divWith, doc, doubleQuoted, emph,
@@ -109,7 +109,8 @@ tests = map (localOption (QuickCheckTests 20))
assertFilterConversion "pandoc.utils doesn't work as expected."
"test-pandoc-utils.lua"
(doc $ para "doesn't matter")
- (doc $ mconcat [ plain (str "hierarchicalize: OK")
+ (doc $ mconcat [ plain (str "blocks_to_inlines: OK")
+ , plain (str "hierarchicalize: OK")
, plain (str "normalize_date: OK")
, plain (str "pipe: OK")
, plain (str "failing pipe: OK")
@@ -129,7 +130,7 @@ tests = map (localOption (QuickCheckTests 20))
, testCase "Pandoc version is set" . runPandocLua' $ do
Lua.getglobal' "table.concat"
Lua.getglobal "PANDOC_VERSION"
- Lua.push ("." :: String) -- seperator
+ Lua.push ("." :: String) -- separator
Lua.call 2 1
Lua.liftIO . assertEqual "pandoc version is wrong" pandocVersion
=<< Lua.peek Lua.stackTop
@@ -163,11 +164,11 @@ tests = map (localOption (QuickCheckTests 20))
, testCase "informative error messages" . runPandocLua' $ do
Lua.pushboolean True
- err <- Lua.peekEither Lua.stackTop :: Lua.Lua (Either String Pandoc)
- case err of
+ err <- Lua.peekEither Lua.stackTop
+ case (err :: Either String Pandoc) of
Left msg -> do
let expectedMsg = "Could not get Pandoc value: "
- ++ "expected table but got boolean."
+ <> "table expected, got boolean"
Lua.liftIO $ assertEqual "unexpected error message" expectedMsg msg
Right _ -> error "Getting a Pandoc element from a bool should fail."
]
@@ -178,13 +179,13 @@ assertFilterConversion msg filterPath docIn docExpected = do
setUserDataDir (Just "../data")
runLuaFilter def ("lua" </> filterPath) [] docIn
case docEither of
- Left _ -> fail "lua filter failed"
+ Left exception -> assertFailure (show exception)
Right docRes -> assertEqual msg docExpected docRes
-roundtripEqual :: (Eq a, Lua.FromLuaStack a, Lua.ToLuaStack a) => a -> IO Bool
+roundtripEqual :: (Eq a, Lua.Peekable a, Lua.Pushable a) => a -> IO Bool
roundtripEqual x = (x ==) <$> roundtripped
where
- roundtripped :: (Lua.FromLuaStack a, Lua.ToLuaStack a) => IO a
+ roundtripped :: (Lua.Peekable a, Lua.Pushable a) => IO a
roundtripped = runPandocLua' $ do
oldSize <- Lua.gettop
Lua.push x
diff --git a/test/Tests/Readers/HTML.hs b/test/Tests/Readers/HTML.hs
index f61f1f497..eedb99029 100644
--- a/test/Tests/Readers/HTML.hs
+++ b/test/Tests/Readers/HTML.hs
@@ -4,11 +4,14 @@ module Tests.Readers.HTML (tests) where
import Prelude
import Data.Text (Text)
+import qualified Data.Text as T
import Test.Tasty
+import Test.Tasty.QuickCheck
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
+import Text.Pandoc.Walk (walk)
html :: Text -> Pandoc
html = purely $ readHtml def
@@ -16,6 +19,27 @@ html = purely $ readHtml def
htmlNativeDivs :: Text -> Pandoc
htmlNativeDivs = purely $ readHtml def { readerExtensions = enableExtension Ext_native_divs $ readerExtensions def }
+makeRoundTrip :: Block -> Block
+makeRoundTrip CodeBlock{} = Para [Str "code block was here"]
+makeRoundTrip LineBlock{} = Para [Str "line block was here"]
+makeRoundTrip RawBlock{} = Para [Str "raw block was here"]
+makeRoundTrip x = x
+
+removeRawInlines :: Inline -> Inline
+removeRawInlines RawInline{} = Str "raw inline was here"
+removeRawInlines x = x
+
+roundTrip :: Blocks -> Bool
+roundTrip b = d'' == d'''
+ where d = walk removeRawInlines $
+ walk makeRoundTrip $ Pandoc nullMeta $ toList b
+ d' = rewrite d
+ d'' = rewrite d'
+ d''' = rewrite d''
+ rewrite = html . T.pack . (++ "\n") . T.unpack .
+ purely (writeHtml5String def
+ { writerWrapText = WrapPreserve })
+
tests :: [TestTree]
tests = [ testGroup "base tag"
[ test html "simple" $
@@ -53,4 +77,5 @@ tests = [ testGroup "base tag"
, test htmlNativeDivs "<main> followed by text" $ "<main>main content</main>non-main content" =?>
doc (divWith ("", [], [("role", "main")]) (plain (text "main content")) <> plain (text "non-main content"))
]
+ , testProperty "Round trip" (withMaxSuccess 25 roundTrip)
]
diff --git a/test/Tests/Readers/Markdown.hs b/test/Tests/Readers/Markdown.hs
index e44c7fc19..be89e708e 100644
--- a/test/Tests/Readers/Markdown.hs
+++ b/test/Tests/Readers/Markdown.hs
@@ -39,7 +39,7 @@ testBareLink (inp, ils) =
(unpack inp) (inp, doc $ para ils)
autolink :: String -> Inlines
-autolink = autolinkWith nullAttr
+autolink = autolinkWith ("",["uri"],[])
autolinkWith :: Attr -> String -> Inlines
autolinkWith attr s = linkWith attr s "" (str s)
@@ -72,10 +72,12 @@ bareLinkTests =
, ("http://en.wikipedia.org/wiki/Sprite_(computer_graphics)",
autolink "http://en.wikipedia.org/wiki/Sprite_(computer_graphics)")
, ("http://en.wikipedia.org/wiki/Sprite_[computer_graphics]",
- link "http://en.wikipedia.org/wiki/Sprite_%5Bcomputer_graphics%5D" ""
+ linkWith ("",["uri"],[])
+ "http://en.wikipedia.org/wiki/Sprite_%5Bcomputer_graphics%5D" ""
(str "http://en.wikipedia.org/wiki/Sprite_[computer_graphics]"))
, ("http://en.wikipedia.org/wiki/Sprite_{computer_graphics}",
- link "http://en.wikipedia.org/wiki/Sprite_%7Bcomputer_graphics%7D" ""
+ linkWith ("",["uri"],[])
+ "http://en.wikipedia.org/wiki/Sprite_%7Bcomputer_graphics%7D" ""
(str "http://en.wikipedia.org/wiki/Sprite_{computer_graphics}"))
, ("http://example.com/Notification_Center-GitHub-20101108-140050.jpg",
autolink "http://example.com/Notification_Center-GitHub-20101108-140050.jpg")
@@ -199,7 +201,9 @@ tests = [ testGroup "inline code"
]
, testGroup "emoji"
[ test markdownGH "emoji symbols" $
- ":smile: and :+1:" =?> para (text "😄 and 👍")
+ ":smile: and :+1:" =?> para (spanWith ("", ["emoji"], [("data-emoji", "smile")]) "😄" <>
+ space <> str "and" <> space <>
+ spanWith ("", ["emoji"], [("data-emoji", "+1")]) "👍")
]
, "unbalanced brackets" =:
"[[[[[[[[[[[[hi" =?> para (text "[[[[[[[[[[[[hi")
diff --git a/test/Tests/Readers/Muse.hs b/test/Tests/Readers/Muse.hs
index ecdd5fdb0..958a74915 100644
--- a/test/Tests/Readers/Muse.hs
+++ b/test/Tests/Readers/Muse.hs
@@ -39,9 +39,9 @@ makeRoundTrip x = x
-- Demand that any AST produced by Muse reader and written by Muse writer can be read back exactly the same way.
-- Currently we remove tables and compare first rewrite to the second.
-roundTrip :: Block -> Bool
+roundTrip :: Blocks -> Bool
roundTrip b = d' == d''
- where d = walk makeRoundTrip $ Pandoc nullMeta [b]
+ where d = walk makeRoundTrip $ Pandoc nullMeta $ toList b
d' = rewrite d
d'' = rewrite d'
rewrite = amuse . T.pack . (++ "\n") . T.unpack .
@@ -62,6 +62,14 @@ tests =
"*Foo bar*" =?>
para (emph . spcSep $ ["Foo", "bar"])
+ -- Emacs Muse allows this
+ , "Newline in the beginning of emphasis" =:
+ "*\nFoo bar*" =?>
+ para (emph ("Foo" <> space <> "bar"))
+ , "Newline in the end of emphasis" =:
+ "*Foo bar\n*" =?>
+ para (emph ("Foo" <> space <> "bar"))
+
, "Comma after closing *" =:
"Foo *bar*, baz" =?>
para ("Foo " <> emph "bar" <> ", baz")
@@ -74,6 +82,10 @@ tests =
"Foo x*bar* baz" =?>
para "Foo x*bar* baz"
+ , "Digit after closing *" =:
+ "Foo *bar*0 baz" =?>
+ para "Foo *bar*0 baz"
+
, "Emphasis tag" =:
"<em>Foo bar</em>" =?>
para (emph . spcSep $ ["Foo", "bar"])
@@ -138,6 +150,10 @@ tests =
"Foo =bar=, baz" =?>
para (text "Foo " <> code "bar" <> text ", baz")
+ , "Not code if followed by digit" =:
+ "Foo =bar=0 baz" =?>
+ para (text "Foo =bar=0 baz")
+
, "One character code" =: "=c=" =?> para (code "c")
, "Three = characters is not a code" =: "===" =?> para "==="
@@ -194,9 +210,27 @@ tests =
, "Image" =:
"[[image.jpg]]" =?>
para (image "image.jpg" "" mempty)
+ , "Closing bracket is not allowed in image filename" =:
+ "[[foo]bar.jpg]]" =?>
+ para (text "[[foo]bar.jpg]]")
, "Image with description" =:
"[[image.jpg][Image]]" =?>
para (image "image.jpg" "" (text "Image"))
+ , "Image with space in filename" =:
+ "[[image name.jpg]]" =?>
+ para (image "image name.jpg" "" mempty)
+ , "Image with width" =:
+ "[[image.jpg 60]]" =?>
+ para (imageWith ("", [], [("width", "60%")]) "image.jpg" mempty mempty)
+ , "At least one space is required between image filename and width" =:
+ "[[image.jpg60]]" =?>
+ para (link "image.jpg60" mempty (str "image.jpg60"))
+ , "Left-aligned image with width" =:
+ "[[image.png 60 l][Image]]" =?>
+ para (imageWith ("", ["align-left"], [("width", "60%")]) "image.png" "" (str "Image"))
+ , "Right-aligned image with width" =:
+ "[[image.png 60 r][Image]]" =?>
+ para (imageWith ("", ["align-right"], [("width", "60%")]) "image.png" "" (str "Image"))
, "Image link" =:
"[[URL:image.jpg]]" =?>
para (link "image.jpg" "" (str "image.jpg"))
@@ -225,8 +259,8 @@ tests =
]
]
- , testGroup "Blocks" $
- [ testProperty "Round trip" roundTrip
+ , testGroup "Blocks"
+ [ testProperty "Round trip" (withMaxSuccess 25 roundTrip)
, "Block elements end paragraphs" =:
T.unlines [ "First paragraph"
, "----"
@@ -385,6 +419,12 @@ tests =
, "</verse>"
] =?>
lineBlock [ "" ]
+ , "Verse tag with verbatim close tag inside" =:
+ T.unlines [ "<verse>"
+ , "<verbatim></verse></verbatim>"
+ , "</verse>"
+ ] =?>
+ lineBlock [ "</verse>" ]
, testGroup "Example"
[ "Braces on separate lines" =:
T.unlines [ "{{{"
@@ -589,6 +629,18 @@ tests =
T.unlines [ "* Foo"
, "bar"
] =?> header 1 "Foo\nbar"
+ , test (purely $ readMuse def { readerExtensions = extensionsFromList [Ext_amuse, Ext_auto_identifiers]})
+ "Auto identifiers"
+ (T.unlines [ "* foo"
+ , "** Foo"
+ , "* bar"
+ , "** foo"
+ , "* foo"
+ ] =?> headerWith ("foo",[],[]) 1 "foo" <>
+ headerWith ("foo-1",[],[]) 2 "Foo" <>
+ headerWith ("bar",[],[]) 1 "bar" <>
+ headerWith ("foo-2",[],[]) 2 "foo" <>
+ headerWith ("foo-3",[],[]) 1 "foo")
]
, testGroup "Directives"
[ "Title" =:
@@ -710,6 +762,13 @@ tests =
, " > Baz"
] =?>
para ("Foo" <> note (para "Bar" <> lineBlock ["Baz"]))
+ , "Footnote ending in self-terminating element and followed by paragraph" =:
+ T.unlines [ "Foo[1]"
+ , ""
+ , "[1] > bar"
+ , "baz"
+ ] =?>
+ para (str "Foo" <> note (lineBlock ["bar"])) <> para (str "baz")
, test emacsMuse "Emacs multiparagraph footnotes"
(T.unlines
[ "First footnote reference[1] and second footnote reference[2]."
@@ -798,6 +857,14 @@ tests =
[plain "Foo", plain "bar", plain "baz"]
[[plain "First", plain "row", plain "here"],
[plain "Second", plain "row", plain "there"]]
+ , "Table caption with +" =:
+ T.unlines
+ [ "Foo | bar"
+ , "|+ Table + caption +|"
+ ] =?>
+ table (text "Table + caption") (replicate 2 (AlignDefault, 0.0))
+ []
+ [[plain "Foo", plain "bar"]]
, "Caption without table" =:
"|+ Foo bar baz +|" =?>
table (text "Foo bar baz") [] [] []
@@ -972,7 +1039,7 @@ tests =
, para "c"
]
]
- , "List continuation afeter nested list" =:
+ , "List continuation after nested list" =:
T.unlines
[ " - - foo"
, ""
@@ -1118,6 +1185,11 @@ tests =
] =?>
bulletList [ lineBlock [ "foo" ] ] <> bulletList [ para "bar" ]
]
+ , "List ending in self-terminating element and followed by paragraph" =:
+ T.unlines [ " - > Foo"
+ , "bar"
+ ] =?>
+ bulletList [lineBlock ["Foo"]] <> para (str "bar")
-- Test that definition list requires a leading space.
-- Emacs Muse does not require a space, we follow Amusewiki here.
, "Not a definition list" =:
@@ -1335,7 +1407,8 @@ tests =
, " <verse>"
, " </quote>"
, " </verse>"
+ , "</quote>"
] =?>
- para "<quote>" <> bulletList [ para "Foo" <> para "</quote>" <> para "bar" <> lineBlock [ "</quote>" ] ]
+ blockQuote (bulletList [ para "Foo" <> para "</quote>" <> para "bar" <> lineBlock [ "</quote>" ] ])
]
]
diff --git a/test/Tests/Readers/Org/Block/Header.hs b/test/Tests/Readers/Org/Block/Header.hs
index 3b0d7dda9..913c830d6 100644
--- a/test/Tests/Readers/Org/Block/Header.hs
+++ b/test/Tests/Readers/Org/Block/Header.hs
@@ -181,4 +181,42 @@ tests =
, " :END:"
] =?>
headerWith ("not-numbered", ["unnumbered"], []) 1 "Not numbered"
+
+ , testGroup "planning information"
+ [ "Planning info is not included in output" =:
+ T.unlines [ "* important"
+ , T.unwords
+ [ "CLOSED: [2018-09-05 Wed 13:58]"
+ , "DEADLINE: <2018-09-17 Mon>"
+ , "SCHEDULED: <2018-09-10 Mon>"
+ ]
+ ] =?>
+ headerWith ("important", [], []) 1 "important"
+
+ , "Properties after planning info are recognized" =:
+ T.unlines [ "* important "
+ , " " <> T.unwords
+ [ "CLOSED: [2018-09-05 Wed 13:58]"
+ , "DEADLINE: <2018-09-17 Mon>"
+ , "SCHEDULED: <2018-09-10 Mon>"
+ ]
+ , " :PROPERTIES:"
+ , " :custom_id: look"
+ , " :END:"
+ ] =?>
+ headerWith ("look", [], []) 1 "important"
+
+ , "Planning info followed by test" =:
+ T.unlines [ "* important "
+ , " " <> T.unwords
+ [ "CLOSED: [2018-09-05 Wed 13:58]"
+ , "DEADLINE: <2018-09-17 Mon>"
+ , "SCHEDULED: <2018-09-10 Mon>"
+ ]
+ , " :PROPERTIES:"
+ , " :custom_id: look"
+ , " :END:"
+ ] =?>
+ headerWith ("look", [], []) 1 "important"
+ ]
]
diff --git a/test/Tests/Readers/Org/Block/List.hs b/test/Tests/Readers/Org/Block/List.hs
index f273b684d..bdab01404 100644
--- a/test/Tests/Readers/Org/Block/List.hs
+++ b/test/Tests/Readers/Org/Block/List.hs
@@ -243,4 +243,15 @@ tests =
mconcat [ para "CLOSED: [2015-10-19 Mon 15:03]"
, bulletList [ plain "Note taken on [2015-10-19 Mon 13:24]" ]
]
+
+ , "Markup after header and list" =:
+ T.unlines [ "* headline"
+ , "- list"
+ , ""
+ , "~variable name~"
+ ] =?>
+ mconcat [ headerWith ("headline", [], []) 1 "headline"
+ , bulletList [ plain "list" ]
+ , para (code "variable name")
+ ]
]
diff --git a/test/Tests/Readers/Org/Directive.hs b/test/Tests/Readers/Org/Directive.hs
index bb9c52e69..87abb714d 100644
--- a/test/Tests/Readers/Org/Directive.hs
+++ b/test/Tests/Readers/Org/Directive.hs
@@ -150,6 +150,29 @@ tests =
, "* Headline :hello:world:"
] =?>
headerWith ("headline", [], mempty) 1 "Headline"
+
+ , testGroup "planning information"
+ [ "include planning info after headlines" =:
+ T.unlines [ "#+OPTIONS: p:t"
+ , "* important"
+ , " DEADLINE: <2018-10-01 Mon> SCHEDULED: <2018-09-15 Sat>"
+ ] =?>
+ mconcat [ headerWith ("important", mempty, mempty) 1 "important"
+ , plain $ strong "DEADLINE:"
+ <> space
+ <> emph (str "<2018-10-01 Mon>")
+ <> space
+ <> strong "SCHEDULED:"
+ <> space
+ <> emph (str "<2018-09-15 Sat>")
+ ]
+
+ , "empty planning info is not included" =:
+ T.unlines [ "#+OPTIONS: p:t"
+ , "* Wichtig"
+ ] =?>
+ headerWith ("wichtig", mempty, mempty) 1 "Wichtig"
+ ]
]
, testGroup "Include"
diff --git a/test/Tests/Readers/Org/Inline.hs b/test/Tests/Readers/Org/Inline.hs
index 07fe2d2e9..9cfcda79f 100644
--- a/test/Tests/Readers/Org/Inline.hs
+++ b/test/Tests/Readers/Org/Inline.hs
@@ -96,7 +96,7 @@ tests =
"[fn::Schreib mir eine E-Mail]" =?>
para (note $ para "Schreib mir eine E-Mail")
- , "Markup-chars not occuring on word break are symbols" =:
+ , "Markup-chars not occurring on word break are symbols" =:
T.unlines [ "this+that+ +so+on"
, "seven*eight* nine*"
, "+not+funny+"
@@ -280,6 +280,13 @@ tests =
)
"echo 'Hello, World'")
+ , "Inline code block with a blank argument array" =:
+ "src_sh[]{echo 'Hello, World'}" =?>
+ para (codeWith ( ""
+ , [ "bash" ]
+ , [ ("org-language", "sh") ])
+ "echo 'Hello, World'")
+
, "Inline code block with toggle" =:
"src_sh[:toggle]{echo $HOME}" =?>
para (codeWith ( ""
diff --git a/test/Tests/Readers/RST.hs b/test/Tests/Readers/RST.hs
index 906ed4ff9..963e7530d 100644
--- a/test/Tests/Readers/RST.hs
+++ b/test/Tests/Readers/RST.hs
@@ -177,7 +177,7 @@ tests = [ "line block with blank line" =:
=: ".. role:: haskell(code)\n.. role:: lhs(haskell)\n\n:lhs:`text`"
=?> para (codeWith ("", ["lhs", "haskell", "sourceCode"], []) "text")
, "unknown role" =: ":unknown:`text`" =?>
- para (spanWith ("",[],[("role","unknown")]) (str "text"))
+ para (codeWith ("",["interpreted-text"],[("role","unknown")]) "text")
]
, testGroup "footnotes"
[ "remove space before note" =: T.unlines
@@ -188,4 +188,18 @@ tests = [ "line block with blank line" =:
] =?>
para ("foo" <> note (para "bar"))
]
+ , testGroup "inlines"
+ [ "links can contain an URI without being parsed twice (#4581)" =:
+ "`http://loc <http://loc>`__" =?>
+ para (link "http://loc" "" "http://loc")
+ , "inline markup cannot be nested" =:
+ "**a*b*c**" =?>
+ para (strong "a*b*c")
+ , "bare URI parsing disabled inside emphasis (#4561)" =:
+ "*http://location*" =?>
+ para (emph (text "http://location"))
+ , "include newlines" =:
+ "**before\nafter**" =?>
+ para (strong (text "before\nafter"))
+ ]
]
diff --git a/test/Tests/Writers/HTML.hs b/test/Tests/Writers/HTML.hs
index e771255b3..dfacda608 100644
--- a/test/Tests/Writers/HTML.hs
+++ b/test/Tests/Writers/HTML.hs
@@ -43,4 +43,9 @@ tests = [ testGroup "inline code"
image "/url" "title" ("my " <> emph "image")
=?> "<img src=\"/url\" title=\"title\" alt=\"my image\" />"
]
+ , testGroup "blocks"
+ [ "definition list with empty <dt>" =:
+ definitionList [(mempty, [para $ text "foo bar"])]
+ =?> "<dl><dt></dt><dd><p>foo bar</p></dd></dl>"
+ ]
]
diff --git a/test/Tests/Writers/Muse.hs b/test/Tests/Writers/Muse.hs
index 50c0e78eb..f7287d57d 100644
--- a/test/Tests/Writers/Muse.hs
+++ b/test/Tests/Writers/Muse.hs
@@ -275,7 +275,7 @@ tests = [ testGroup "block elements"
unlines [ "#bar"
, "** Foo"
]
- , "empty heading" =: header 4 (mempty) =?> "**** <verbatim></verbatim>"
+ , "empty heading" =: header 4 mempty =?> "**** <verbatim></verbatim>"
]
, "horizontal rule" =: horizontalRule =?> "----"
, "escape horizontal rule" =: para (text "----") =?> "<verbatim></verbatim>----"
@@ -283,6 +283,7 @@ tests = [ testGroup "block elements"
, "don't escape horizontal inside paragraph" =: para (text "foo ---- bar") =?> "foo ---- bar"
, "escape nonbreaking space" =: para (text "~~") =?> "<verbatim>~~</verbatim>"
, "escape > in the beginning of line" =: para (text "> foo bar") =?> "<verbatim></verbatim>> foo bar"
+ , "escape string with > and space in the beginning of line" =: para (str "> foo bar") =?> "<verbatim></verbatim>> foo bar"
, testGroup "tables"
[ "table without header" =:
let rows = [[para $ text "Para 1.1", para $ text "Para 1.2"]
@@ -341,36 +342,95 @@ tests = [ testGroup "block elements"
, "do not escape colon" =: str ":" =?> ":"
, "escape - to avoid accidental unordered lists" =: text " - foo" =?> "<verbatim></verbatim> - foo"
, "escape - inside a list to avoid accidental nested unordered lists" =:
- bulletList [ (para $ text "foo") <>
- (para $ text "- bar")
+ bulletList [ para (text "foo") <>
+ para (text "- bar")
] =?>
unlines [ " - foo"
, ""
, " <verbatim></verbatim>- bar"
]
+ , "escape strings starting with - inside a list" =:
+ bulletList [ para (str "foo") <>
+ para (str "- bar")
+ ] =?>
+ unlines [ " - foo"
+ , ""
+ , " <verbatim></verbatim>- bar"
+ ]
+ , "escape - inside a note" =:
+ note (para (text "- foo")) =?>
+ unlines [ "[1]"
+ , ""
+ , "[1] <verbatim></verbatim>- foo"
+ ]
+ , "escape - after softbreak in note" =:
+ note (para (str "foo" <> softbreak <> str "- bar")) =?>
+ unlines [ "[1]"
+ , ""
+ , "[1] foo"
+ , " <verbatim></verbatim>- bar"
+ ]
, "escape ; to avoid accidental comments" =: text "; foo" =?> "<verbatim></verbatim>; foo"
+ , "escape strings starting with ; and space" =: str "; foo" =?> "<verbatim></verbatim>; foo"
, "escape ; after softbreak" =: text "foo" <> softbreak <> text "; bar" =?> "foo\n<verbatim></verbatim>; bar"
, "escape ; after linebreak" =: text "foo" <> linebreak <> text "; bar" =?> "foo<br>\n<verbatim></verbatim>; bar"
, "do not escape ; inside paragraph" =: text "foo ; bar" =?> "foo ; bar"
+ , "escape newlines" =: str "foo\nbar" =?> "foo bar"
]
, testGroup "emphasis"
- [ "emph" =: emph (text "foo") =?> "<em>foo</em>"
- , "strong" =: strong (text "foo") =?> "<strong>foo</strong>"
+ [ "emphasis" =: emph (text "foo") =?> "*foo*"
+ , "emphasis inside word" =: text "foo" <> emph (text "bar") <> text "baz" =?> "foo<em>bar</em>baz"
+ , "emphasis before comma" =: emph (text "foo") <> text ", bar" =?> "*foo*, bar"
+ , "emphasis before period" =: emph (text "foobar") <> text "." =?> "*foobar*."
+ , "empty emphasis" =: emph mempty =?> "<em></em>"
+ , "empty strong" =: strong mempty =?> "<strong></strong>"
+ , "empty strong emphasis" =: strong (emph mempty) =?> "**<em></em>**"
+ , "empty emphasized strong" =: emph (strong mempty) =?> "*<strong></strong>*"
+ , "emphasized empty string" =: emph (str "") =?> "<em></em>"
+ , "strong empty string" =: strong (str "") =?> "<strong></strong>"
+ , "strong emphasized empty string" =: strong (emph (str "")) =?> "**<em></em>**"
+ , "emphasized strong empty string" =: emph (strong (str "")) =?> "*<strong></strong>*"
+ , "emphasized string with space" =: emph (str " ") =?> "<em> </em>"
+ , "emphasized string ending with space" =: emph (str "foo ") =?> "<em>foo </em>"
+ , "emphasized string with tab" =: emph (str "\t") =?> "<em>\t</em>"
+ , "emphasized space between empty strings" =: emph (str "" <> space <> str "") =?> "<em> </em>"
+ , "strong" =: strong (text "foo") =?> "**foo**"
+ , "strong inside word" =: text "foo" <> strong (text "bar") <> text "baz" =?> "foo<strong>bar</strong>baz"
+ , "strong emphasis" =: strong (emph (text "foo")) =?> "***foo***"
+ , "strong after emphasis" =: emph (text "foo") <> strong (text "bar") =?> "*foo*<strong>bar</strong>"
+ , "strong emphasis after emphasis" =: emph (text "foo") <> strong (emph (text "bar")) =?> "*foo*<strong>*bar*</strong>"
+ , "strong in the end of emphasis" =: emph (text "foo" <> strong (text "bar")) =?> "*foo<strong>bar</strong>*"
, "strikeout" =: strikeout (text "foo") =?> "<del>foo</del>"
+ , "space at the beginning of emphasis" =: emph (text " foo") =?> "<em> foo</em>"
+ , "space at the end of emphasis" =: emph (text "foo ") =?> "<em>foo </em>"
+ , "space at the beginning of strong" =: strong (text " foo") =?> "<strong> foo</strong>"
+ , "space at the end of strong" =: strong (text "foo ") =?> "<strong>foo </strong>"
+ , "space at the beginning of strong emphasis" =: strong (emph (text " foo")) =?> "**<em> foo</em>**"
+ , "space at the end of strong emphasis" =: strong (emph (text "foo ")) =?> "**<em>foo </em>**"
+ , "space at the beginning of emphasiszed strong" =: emph (strong (text " foo")) =?> "*<strong> foo</strong>*"
+ , "space at the end of emphasized strong" =: emph (strong (text "foo ")) =?> "*<strong>foo </strong>*"
]
, "superscript" =: superscript (text "foo") =?> "<sup>foo</sup>"
, "subscript" =: subscript (text "foo") =?> "<sub>foo</sub>"
- , "smallcaps" =: smallcaps (text "foo") =?> "<em>foo</em>"
- , "smallcaps near emphasis" =: emph (str "foo") <> smallcaps (str "bar") =?> "<em>foobar</em>"
+ , "smallcaps" =: smallcaps (text "foo") =?> "*foo*"
+ , "smallcaps near emphasis" =: emph (str "foo") <> smallcaps (str "bar") =?> "*foobar*"
, "single quoted" =: singleQuoted (text "foo") =?> "‘foo’"
, "double quoted" =: doubleQuoted (text "foo") =?> "“foo”"
-- Cite is trivial
, testGroup "code"
- [ "simple" =: code "foo" =?> "<code>foo</code>"
+ [ "simple" =: code "foo" =?> "=foo="
+ , "empty" =: code "" =?> "<code></code>"
+ , "space" =: code " " =?> "<code> </code>"
+ , "space at the beginning" =: code " foo" =?> "<code> foo</code>"
+ , "space at the end" =: code "foo " =?> "<code>foo </code>"
+ , "use tags for =" =: code "foo = bar" =?> "<code>foo = bar</code>"
, "escape tag" =: code "<code>foo = bar</code> baz" =?> "<code><code>foo = bar<</code><code>/code> baz</code>"
- , "normalization with attributes" =: codeWith ("",["haskell"],[]) "foo" <> code "bar" =?> "<code>foobar</code>"
- , "normalization" =: code "</co" <> code "de>" =?> "<code><</code><code>/code></code>"
- , "normalization with empty string" =: code "</co" <> str "" <> code "de>" =?> "<code><</code><code>/code></code>"
+ , "normalization with attributes" =: codeWith ("",["haskell"],[]) "foo" <> code "bar" =?> "=foobar="
+ , "code tag" =: code "<code>foo</code>" =?> "=<code>foo</code>="
+ , "normalization" =: code "</co" <> code "de>" <> code "=" =?> "<code><</code><code>/code>=</code>"
+ , "normalization with empty string" =: code "</co" <> str "" <> code "de>" <> code "=" =?> "<code><</code><code>/code>=</code>"
+ , "emphasized code" =: emph (code "foo") =?> "*=foo=*"
+ , "strong code" =: strong (code "foo") =?> "**=foo=**"
]
, testGroup "spaces"
[ "space" =: text "a" <> space <> text "b" =?> "a b"
@@ -385,7 +445,7 @@ tests = [ testGroup "block elements"
, testGroup "math"
[ "inline math" =: math "2^3" =?> "2<sup>3</sup>"
, "display math" =: displayMath "2^3" =?> "2<sup>3</sup>"
- , "multiple letters in inline math" =: math "abc" =?> "<em>abc</em>"
+ , "multiple letters in inline math" =: math "abc" =?> "*abc*"
, "expand math before normalization" =: math "[" <> str "2]" =?> "<verbatim>[2]</verbatim>"
, "multiple math expressions inside one inline list" =: math "5_4" <> text ", " <> displayMath "3^2" =?> "5<sub>4</sub>, 3<sup>2</sup>"
]
@@ -441,11 +501,11 @@ tests = [ testGroup "block elements"
=?> "<class name=\"foobar\">Some text</class>"
, "span without class" =: spanWith ("",[],[]) (text "Some text")
=?> "<class>Some text</class>"
- , "span with anchor" =: spanWith ("anchor", [], []) (mempty) <> (text "Foo bar")
+ , "span with anchor" =: spanWith ("anchor", [], []) mempty <> text "Foo bar"
=?> "#anchor Foo bar"
- , "empty span with anchor" =: spanWith ("anchor", [], []) (mempty)
+ , "empty span with anchor" =: spanWith ("anchor", [], []) mempty
=?> "#anchor"
- , "empty span without class and anchor" =: spanWith ("", [], []) (mempty)
+ , "empty span without class and anchor" =: spanWith ("", [], []) mempty
=?> "<class></class>"
, "span with class and anchor" =: spanWith ("anchor", ["foo"], []) (text "bar")
=?> "#anchor <class name=\"foo\">bar</class>"
@@ -461,7 +521,7 @@ tests = [ testGroup "block elements"
"<em>foo</em>bar"
, "emph quoted" =:
para (doubleQuoted (emph (text "foo"))) =?>
- "“<em>foo</em>”"
+ "“*foo*”"
, "strong word before" =:
para (text "foo" <> strong (text "bar")) =?>
"foo<strong>bar</strong>"
@@ -470,7 +530,7 @@ tests = [ testGroup "block elements"
"<strong>foo</strong>bar"
, "strong quoted" =:
para (singleQuoted (strong (text "foo"))) =?>
- "‘<strong>foo</strong>’"
+ "‘**foo**’"
]
]
]
diff --git a/test/Tests/Writers/RST.hs b/test/Tests/Writers/RST.hs
index a1a4510e0..0d5b7c38a 100644
--- a/test/Tests/Writers/RST.hs
+++ b/test/Tests/Writers/RST.hs
@@ -16,6 +16,11 @@ infix 4 =:
=> String -> (a, String) -> TestTree
(=:) = test (purely (writeRST def . toPandoc))
+testTemplate :: (ToString a, ToString c, ToPandoc a) =>
+ String -> String -> (a, c) -> TestTree
+testTemplate t =
+ test (purely (writeRST def{ writerTemplate = Just t }) . toPandoc)
+
tests :: [TestTree]
tests = [ testGroup "rubrics"
[ "in list item" =:
@@ -156,4 +161,7 @@ tests = [ testGroup "rubrics"
, "Header 2"
, "--------"]
]
+ , testTemplate "$subtitle$\n" "subtitle" $
+ (setMeta "subtitle" ("subtitle" :: Inlines) $ doc $ plain "") =?>
+ ("subtitle" :: String)
]