1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Tests.Readers.Creole
Copyright : © 2017 Sascha Wilde
2017-2023 John MacFarlane
License : GNU GPL, version 2 or above
Maintainer : Sascha Wilde <wilde@sha-bang.de>
Stability : alpha
Portability : portable
Tests for the creole reader.
-}
module Tests.Readers.Creole (tests) where
import Data.Text (Text)
import qualified Data.Text as T
import Test.Tasty
import Test.Tasty.HUnit (HasCallStack)
import Tests.Helpers
import Text.Pandoc
import Text.Pandoc.Arbitrary ()
import Text.Pandoc.Builder
creole :: Text -> Pandoc
creole = purely $ readCreole def{ readerStandalone = True }
infix 4 =:
(=:) :: (ToString c, HasCallStack)
=> String -> (Text, c) -> TestTree
(=:) = test creole
tests :: [TestTree]
tests = [
testGroup "Basic Text Formatting" [
"bold, single line, fully delimited" =:
"only **bold** is bold"
=?> para ("only " <> strong "bold" <> " is bold")
, "italics, single line, fully delimited" =:
"only //this// is in italics"
=?> para ("only " <> emph "this" <> " is in italics")
, "bold in italics, fully delimited" =:
"//**this**// is in bold italics"
=?> para (emph (strong "this") <> " is in bold italics")
, "italics in bold, fully delimited" =:
"**//this//** is in bold italics"
=?> para (strong (emph "this") <> " is in bold italics")
, "escape bold marker" =:
"~**not bold" =?> para "**not bold"
, "escape italics marker" =:
"~//not in italics" =?> para "//not in italics"
, "inline nowiki, simple" =:
"this is {{{**not** ~interpreted}}} at all"
=?> para ("this is " <> code "**not** ~interpreted" <> " at all")
, "inline nowiki, curly braces inside" =:
"this is {{{{{{//including// some `}' chars}}}}}}"
=?> para ("this is " <> code "{{{//including// some `}' chars}}}")
, "placeholder" =:
"foo <<<place holder>>> bar"
=?> para "foo bar"
, "placeholder escaped" =:
"foo ~<<<no place holder>>> bar"
=?> para "foo <<<no place holder>>> bar"
]
, testGroup "Headers" [
"header level 1, no space, no trailing =" =:
"= Top-Level Header"
=?> header 1 (str "Top-Level Header")
, "header level 1, leading space, trailing =" =:
" = Top-Level Header = "
=?> header 1 (str "Top-Level Header")
, "header level 2, no space, no trailing =" =:
"== Second Level"
=?> header 2 (str "Second Level")
, "header level 2, leading space, no trailing =" =:
" == Second Level"
=?> header 2 (str "Second Level")
, "header level 3, no space, no trailing =" =:
"=== Third"
=?> header 3 (str "Third")
, "header level 3, no space, > 3 trailing =" =:
"=== Third ======="
=?> header 3 (str "Third")
, "header level 4, no space, no trailing =" =:
"==== Fourth Level Heading"
=?> header 4 (str "Fourth Level Heading")
, "header level 4, no space, < 4 trailing =" =:
"==== Fourth Level Heading =="
=?> header 4 (str "Fourth Level Heading")
, "header level 5, no space, no trailing =" =:
"===== Fifth"
=?> header 5 (str "Fifth")
, "header level 6, no space, no trailing =" =:
"====== Sixth"
=?> header 6 (str "Sixth")
]
, testGroup "Paragraphs" [
"paragraphs: multiple, one line" =:
"first line\n\nanother line\n"
=?> para "first line" <> para "another line"
]
, testGroup "Lists" [
"unordered list, two entries, one separating space" =:
"* foo\n* bar"
=?> bulletList [ plain "foo", plain "bar" ]
, "unordered list, three entries, one separating space" =:
"* foo\n* bar\n* baz"
=?> bulletList [ plain "foo", plain "bar", plain "baz" ]
, "para followed by, unordered list, two entries, one separating space" =:
"blubber\n* foo\n* bar"
=?> para "blubber" <> bulletList [ plain "foo", plain "bar" ]
, "nested unordered list, one separating space" =:
"* foo\n** bar\n** baz\n* blubb"
=?> bulletList [ plain "foo"
<> bulletList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "nested many unordered lists, one separating space" =:
("* foo\n** bar\n*** third\n*** third two\n** baz\n*** third again\n"
<> "**** fourth\n***** fifth\n* blubb")
=?> bulletList [ plain "foo"
<> bulletList [ plain "bar"
<> bulletList [ plain "third"
, plain "third two"]
, plain "baz"
<> bulletList [ plain "third again"
<> bulletList [
plain "fourth"
<> bulletList [
plain "fifth"
]
]
]
]
, plain "blubb" ]
, "nested unordered list, mixed separating space" =:
"*foo\n ** bar\n **baz\n * blubb"
=?> bulletList [ plain "foo"
<> bulletList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "nested unordered list, one separating space, trailing space" =:
"* foo \n** bar \n** baz \n* blubb "
=?> bulletList [ plain "foo"
<> bulletList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "ordered list, two entries, one separating space" =:
"# foo\n# bar"
=?> orderedList [ plain "foo", plain "bar" ]
, "ordered list, three entries, one separating space" =:
"# foo\n# bar\n# baz"
=?> orderedList [ plain "foo", plain "bar", plain "baz" ]
, "para followed by, ordered list, two entries, one separating space" =:
"blubber\n# foo\n# bar"
=?> para "blubber" <> orderedList [ plain "foo", plain "bar" ]
, "nested ordered list, one separating space" =:
"# foo\n## bar\n## baz\n# blubb"
=?> orderedList [ plain "foo"
<> orderedList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "nested ordered list, one separating space, trailing space" =:
"# foo \n## bar \n## baz \n# blubb "
=?> orderedList [ plain "foo"
<> orderedList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "nested many ordered lists, one separating space" =:
("# foo\n## bar\n### third\n### third two\n## baz\n### third again\n"
<> "#### fourth\n##### fifth\n# blubb")
=?> orderedList [ plain "foo"
<> orderedList [ plain "bar"
<> orderedList [ plain "third"
, plain "third two"]
, plain "baz"
<> orderedList [ plain "third again"
<> orderedList [
plain "fourth"
<> orderedList [
plain "fifth"
]
]
]
]
, plain "blubb" ]
, "nested ordered list, mixed separating space" =:
"#foo\n ## bar\n ##baz\n # blubb"
=?> orderedList [ plain "foo"
<> orderedList [ plain "bar", plain "baz" ]
, plain "blubb" ]
, "mixed nested ordered and unordered lists, one separating space" =:
("# foo\n** bar\n### third\n### third two\n** baz\n### third again\n"
<> "#### fourth\n***** fifth\n# blubb")
=?> orderedList [ plain "foo"
<> bulletList [ plain "bar"
<> orderedList [ plain "third"
, plain "third two"]
, plain "baz"
<> orderedList [ plain "third again"
<> orderedList [
plain "fourth"
<> bulletList [
plain "fifth"
]
]
]
]
, plain "blubb" ]
]
, testGroup "NoWiki" [
"quoted block, simple" =:
"{{{\nfoo bar\n //baz//\n}}}"
=?> codeBlock "foo bar\n //baz//"
, "quoted block, curly bracket exception" =:
"{{{\nfoo bar\n }}}\nbaz\n }}}\n}}}"
=?> codeBlock "foo bar\n }}}\nbaz\n}}}"
, "forced line breaks" =:
"{{{no break!\\\\here}}} but a break\\\\here!"
=?> para (code "no break!\\\\here" <> " but a break"
<> linebreak <> "here!"),
"quoted block, after trailing white space" =:
"this is a paragraph \n{{{\nfoo bar\n //baz//\n}}}"
=?> para "this is a paragraph" <> codeBlock "foo bar\n //baz//"
]
, testGroup "Images and Links" [
"image simple" =:
"{{foo.png}}" =?> para (image "foo.png" "" (str ""))
, "image with alt text" =:
"Image of a bar: {{/path/to/bar.png|A Bar}} look at it!"
=?> para ("Image of a bar: "
<> image "/path/to/bar.png" "" (str "A Bar") <> " look at it!")
, "auto link" =:
"foo http://foo.example.com/bar/baz.html bar"
=?> para ("foo "
<> link "http://foo.example.com/bar/baz.html" ""
(str "http://foo.example.com/bar/baz.html")
<> " bar")
, "escaped auto link" =:
"foo ~http://foo.example.com/bar/baz.html bar"
=?> para "foo http://foo.example.com/bar/baz.html bar"
, "wiki link simple" =:
"foo [[http://foo.example.com/foo.png]] bar"
=?> para ("foo "
<> link "http://foo.example.com/foo.png" ""
(str "http://foo.example.com/foo.png")
<> " bar")
, "wiki link with name" =:
"foo [[http://foo.example.com/foo.png|my link]] bar"
=?> para ("foo "
<> link "http://foo.example.com/foo.png" ""
(str "my link")
<> " bar")
, "image link" =:
"[[http://foo.example.com/|{{foo.png}}]]"
=?> para (link "http://foo.example.com/" "" (image "foo.png" "" (str "")))
]
, testGroup "Table" [
"Table with Header" =:
T.unlines [ "|= Foo |= Bar |= Baz |"
, "| One | Two | Three |"
, "| 1 | 2 | 3 |"
, "| A | B | C |"
]
=?> simpleTable
[plain "Foo", plain "Bar" , plain "Baz"]
[[plain "One", plain "Two" , plain "Three"]
,[plain "1", plain "2" , plain "3"]
,[plain "A", plain "B" , plain "C"]]
, "Table without Header" =:
T.unlines [ "| One | Two | Three |"
, "| 1 | 2 | 3 |"
, "| A | B | C |"
]
=?> simpleTable [mempty]
[[plain "One", plain "Two" , plain "Three"]
,[plain "1", plain "2" , plain "3"]
,[plain "A", plain "B" , plain "C"]]
, "Table without Header, no markers at line ends" =:
T.unlines [ "| One | Two | Three"
, "| 1 | 2 | 3"
, "| A | B | C "
]
=?> simpleTable [mempty]
[[plain "One", plain "Two" , plain "Three"]
,[plain "1", plain "2" , plain "3"]
,[plain "A", plain "B" , plain "C"]]
, "Table with Header, with formatting" =:
T.unlines [ "|= **Foo** |= **Bar** |= **Baz** |"
, "|//one// element |//second// elt|Three |"
, "| {{{1}}} | {{{{}}}} | [[link]] |"
]
=?> simpleTable
[plain $ strong "Foo", plain $ strong "Bar" , plain $ strong "Baz"]
[[plain (emph "one" <> " element"), plain (emph "second" <> " elt")
,plain "Three"]
,[plain $ code "1", plain $ code "{}"
,plain $ link "link" "" (str "link")]]
]
]
|