aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorNikolay Yakimov <root@livid.pp.ru>2020-04-16 02:20:01 +0300
committerGitHub <noreply@github.com>2020-04-15 16:20:01 -0700
commit83c1ce1d77d3ef058e4e5c645a8eb0379fab780f (patch)
treed51a2d822bd147127695dd362d4875bae76628bd /test
parentb64ece76cb9f21e41b19678dc8ae247dbe9ab4cc (diff)
downloadpandoc-83c1ce1d77d3ef058e4e5c645a8eb0379fab780f.tar.gz
Markdown Reader: Fix inline code in lists (#6284)
Closes #6284. Previously inline code containing list markers was sometimes parsed incorrectly.
Diffstat (limited to 'test')
-rw-r--r--test/Tests/Readers/Markdown.hs47
1 files changed, 47 insertions, 0 deletions
diff --git a/test/Tests/Readers/Markdown.hs b/test/Tests/Readers/Markdown.hs
index d33c0e64a..228777496 100644
--- a/test/Tests/Readers/Markdown.hs
+++ b/test/Tests/Readers/Markdown.hs
@@ -171,6 +171,53 @@ tests = [ testGroup "inline code"
=?> para (code "*" <> space <> str "{.haskell" <> space <>
str ".special" <> space <> str "x=\"7\"}")
]
+ , testGroup "inline code in lists (regression tests for #6284)" $
+ let lists = [("ordered", "1. ", ol), ("bullet", "- ", ul)]
+ ol = orderedListWith (1, Decimal, Period)
+ ul = bulletList
+ items =
+ [ ("in text" , ["If `(1) x`, then `2`"], [text "If " <> code "(1) x" <> text ", then " <> code "2"])
+ , ("at start" , ["`#. x`" ], [code "#. x" ])
+ , ("at start" , ["`- x`" ], [code "- x" ])
+ , ("after literal backticks", ["`x``#. x`" ], [code "x``#. x" ])
+ , ("after literal backticks", ["`x``- x`" ], [code "x``- x" ])
+ ]
+ lis = ["`text","y","x`"]
+ lis' = ["text","y","x"]
+ bldLsts w lsts txts
+ = let (res, res', f) =
+ foldr (\((_, _, lt), lc) (acc, tacc, t) ->
+ if lt [] == t []
+ then (acc, lc : tacc, lt)
+ else (join t tacc acc, [lc], lt))
+ (mempty, [], mconcat)
+ (zip lsts (map text txts))
+ join t tacc acc = case tacc of
+ [] -> acc
+ [x] -> t [plain x] <> acc
+ xs -> t (map w xs) <> acc
+ in join f res' res
+ in ["code with list marker "<>mp<>" in " <> ln <> " list" =:
+ T.intercalate "\n" (map (lstr <>) istrs) =?> lbld (map plain iblds)
+ | (ln, lstr, lbld) <- lists, (mp, istrs, iblds) <- items]
+ <> [ "lists with newlines in backticks" =:
+ T.intercalate "\n" (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
+ =?> bldLsts plain lsts lis
+ | lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
+ ]
+ <> [ "lists with newlines and indent in backticks" =:
+ T.intercalate ("\n" <> T.replicate 4 " ") (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
+ =?> let (_, _, f) = head lsts
+ in f [plain $ code $ T.intercalate (T.replicate 5 " ") $ head lis' : zipWith (\i (_, lt, _) -> lt <> i) (tail lis') (tail lsts)]
+ | lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
+ ]
+ <> [ "lists with blank lines and indent in backticks" =:
+ T.intercalate ("\n\n" <> T.replicate 4 " ") (zipWith (\i (_, lt, _) -> lt <> i) lis lsts)
+ <> "\n"
+ =?> let (_, _, f) = head lsts
+ in f . pure $ (para . text $ head lis) <> bldLsts para (tail lsts) (tail lis)
+ | lsts <- [ [i, j, k] | i <- lists, j <- lists, k <- lists]
+ ]
, testGroup "emph and strong"
[ "two strongs in emph" =:
"***a**b **c**d*" =?> para (emph (strong (str "a") <> str "b" <> space