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 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392
|
{-# LANGUAGE OverloadedStrings #-}
{- |
Module : Tests.Readers.Org.Block.Header
Copyright : © 2014-2023 Albert Krewinkel
License : GNU GPL, version 2 or above
Maintainer : Albert Krewinkel <albert@zeitkraut.de>
Stability : alpha
Portability : portable
Test parsing of org lists.
-}
module Tests.Readers.Org.Block.List (tests) where
import Data.Text (Text)
import Test.Tasty (TestTree)
import Tests.Helpers ((=?>), purely, test)
import Tests.Readers.Org.Shared ((=:), spcSep)
import Text.Pandoc (ReaderOptions (readerExtensions),
Extension (Ext_fancy_lists), def, enableExtension,
getDefaultExtensions, readOrg)
import Text.Pandoc.Builder
import qualified Data.Text as T
orgFancyLists :: Text -> Pandoc
orgFancyLists = purely $
let extensionsFancy = enableExtension Ext_fancy_lists (getDefaultExtensions "org")
in readOrg def{ readerExtensions = extensionsFancy }
tests :: [TestTree]
tests =
[ "Simple Bullet Lists" =:
("- Item1\n" <>
"- Item2\n") =?>
bulletList [ plain "Item1"
, plain "Item2"
]
, "Simple Bullet List with Ignored Counter Cookie" =:
("- [@4] Item1\n" <>
"- Item2\n") =?>
bulletList [ plain "Item1"
, plain "Item2"
]
, "Indented Bullet Lists" =:
(" - Item1\n" <>
" - Item2\n") =?>
bulletList [ plain "Item1"
, plain "Item2"
]
, "Unindented *" =:
("- Item1\n" <>
"* Item2\n") =?>
bulletList [ plain "Item1"
] <>
headerWith ("item2", [], []) 1 "Item2"
, "Multi-line Bullet Lists" =:
("- *Fat\n" <>
" Tony*\n" <>
"- /Sideshow\n" <>
" Bob/") =?>
bulletList [ plain $ strong ("Fat" <> softbreak <> "Tony")
, plain $ emph ("Sideshow" <> softbreak <> "Bob")
]
, "Nested Bullet Lists" =:
("- Discovery\n" <>
" + One More Time\n" <>
" + Harder, Better, Faster, Stronger\n" <>
"- Homework\n" <>
" + Around the World\n"<>
"- Human After All\n" <>
" + Technologic\n" <>
" + Robot Rock\n") =?>
bulletList [ mconcat
[ plain "Discovery"
, bulletList [ plain ("One" <> space <>
"More" <> space <>
"Time")
, plain ("Harder," <> space <>
"Better," <> space <>
"Faster," <> space <>
"Stronger")
]
]
, mconcat
[ plain "Homework"
, bulletList [ plain ("Around" <> space <>
"the" <> space <>
"World")
]
]
, mconcat
[ plain ("Human" <> space <> "After" <> space <> "All")
, bulletList [ plain "Technologic"
, plain ("Robot" <> space <> "Rock")
]
]
]
, "Bullet List with Decreasing Indent" =:
" - Discovery\n\
\ - Human After All\n" =?>
mconcat [ bulletList [ plain "Discovery" ]
, bulletList [ plain ("Human" <> space <> "After" <> space <> "All")]
]
, "Header follows Bullet List" =:
" - Discovery\n\
\ - Human After All\n\
\* Homework" =?>
mconcat [ bulletList [ plain "Discovery"
, plain ("Human" <> space <> "After" <> space <> "All")
]
, headerWith ("homework", [], []) 1 "Homework"
]
, "Bullet List Unindented with trailing Header" =:
"- Discovery\n\
\- Homework\n\
\* NotValidListItem" =?>
mconcat [ bulletList [ plain "Discovery"
, plain "Homework"
]
, headerWith ("notvalidlistitem", [], []) 1 "NotValidListItem"
]
, "Empty bullet points" =:
T.unlines [ "-"
, "- "
] =?>
bulletList [ plain "", plain "" ]
, "Task list" =:
T.unlines [ "- [ ] nope"
, "- [X] yup"
, "- [-] started"
, " 1. [X] sure"
, " 2. [ ] nuh-uh"
] =?>
bulletList [ plain "☐ nope", plain "☒ yup"
, mconcat [ plain "☐ started"
, orderedList [plain "☒ sure", plain "☐ nuh-uh"]
]
]
, "Task List with Counter Cookies" =:
T.unlines [ "- [ ] nope"
, "- [@9] [X] yup"
, "- [@a][-] started"
, " 1. [@3][X] sure"
, " 2. [@b] [ ] nuh-uh"
] =?>
bulletList [ plain "☐ nope", plain "☒ yup"
, mconcat [ plain "☐ started"
, orderedListWith
(3, DefaultStyle, DefaultDelim)
[plain "☒ sure", plain "☐ nuh-uh"]
]
]
, test orgFancyLists "Task with alphabetical markers and counter cookie" $
T.unlines [ "- [ ] nope"
, "- [@9] [X] yup"
, "- [@a][-] started"
, " a) [@D][X] sure"
, " b) [@8] [ ] nuh-uh"
] =?>
bulletList [ plain "☐ nope", plain "☒ yup"
, mconcat [ plain "☐ started"
, orderedListWith
(4, LowerAlpha, OneParen)
[plain "☒ sure", plain "☐ nuh-uh"]
]
]
, "Simple Ordered List" =:
("1. Item1\n" <>
"2. Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, test orgFancyLists "Simple Ordered List with fancy lists extension" $
("1. Item1\n" <>
"2. Item2\n") =?>
let listStyle = (1, Decimal, Period)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, test orgFancyLists "Simple Ordered List with lower alpha marker" $
("a) Item1\n" <>
"b) Item2\n") =?>
let listStyle = (1, LowerAlpha, OneParen)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, test orgFancyLists "Simple Ordered List with upper and lower alpha markers" $
("A. Item1\n" <>
"b) Item2\n") =?>
let listStyle = (1, UpperAlpha, Period)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Simple Ordered List with Counter Cookie" =:
("1. [@1234] Item1\n" <>
"2. Item2\n") =?>
let listStyle = (1234, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Simple Ordered List with Alphabetical Counter Cookie" =:
("1. [@c] Item1\n" <>
"2. Item2\n") =?>
let listStyle = (3, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Simple Ordered List with Ignored Counter Cookie" =:
("1. Item1\n" <>
"2. [@4] Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Simple Ordered List with Parens" =:
("1) Item1\n" <>
"2) Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Indented Ordered List" =:
(" 1. Item1\n" <>
" 2. Item2\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ plain "Item1"
, plain "Item2"
]
in orderedListWith listStyle listStructure
, "Empty ordered list item" =:
T.unlines [ "1."
, "3. "
] =?>
orderedList [ plain "", plain "" ]
, test orgFancyLists "Empty ordered list item with fancy lists extension" $
T.unlines [ "a."
, "2. "
] =?>
orderedListWith (1, LowerAlpha, Period) [ plain "", plain "" ]
, "Empty ordered list item with counter cookie" =:
T.unlines [ "1. [@5]"
, "3. [@e] "
] =?>
let listStyle = (5, DefaultStyle, DefaultDelim)
in orderedListWith listStyle [ plain "", plain "" ]
, "Nested Ordered Lists" =:
("1. One\n" <>
" 1. One-One\n" <>
" 2. One-Two\n" <>
"2. Two\n" <>
" 1. Two-One\n"<>
" 2. Two-Two\n") =?>
let listStyle = (1, DefaultStyle, DefaultDelim)
listStructure = [ mconcat
[ plain "One"
, orderedList [ plain "One-One"
, plain "One-Two"
]
]
, mconcat
[ plain "Two"
, orderedList [ plain "Two-One"
, plain "Two-Two"
]
]
]
in orderedListWith listStyle listStructure
, "Ordered List in Bullet List" =:
("- Emacs\n" <>
" 1. Org\n") =?>
bulletList [ plain "Emacs" <>
orderedList [ plain "Org"]
]
, "Bullet List in Ordered List" =:
("1. GNU\n" <>
" - Freedom\n") =?>
orderedList [ plain "GNU" <> bulletList [ plain "Freedom" ] ]
, "Definition List" =:
T.unlines [ "- PLL :: phase-locked loop"
, "- TTL ::"
, " transistor-transistor logic"
, "- PSK :: phase-shift keying"
, ""
, " a digital modulation scheme"
] =?>
definitionList [ ("PLL", [ plain $ "phase-locked" <> space <> "loop" ])
, ("TTL", [ plain $ "transistor-transistor" <> space <>
"logic" ])
, ("PSK", [ mconcat
[ para $ "phase-shift" <> space <> "keying"
, para $ spcSep [ "a", "digital"
, "modulation", "scheme" ]
]
])
]
, "Definition list with multi-word term" =:
" - Elijah Wood :: He plays Frodo" =?>
definitionList [ ("Elijah" <> space <> "Wood", [plain $ "He" <> space <> "plays" <> space <> "Frodo"])]
, "Compact definition list" =:
T.unlines [ "- ATP :: adenosine 5' triphosphate"
, "- DNA :: deoxyribonucleic acid"
, "- PCR :: polymerase chain reaction"
, ""
] =?>
definitionList
[ ("ATP", [ plain $ spcSep [ "adenosine", "5'", "triphosphate" ] ])
, ("DNA", [ plain $ spcSep [ "deoxyribonucleic", "acid" ] ])
, ("PCR", [ plain $ spcSep [ "polymerase", "chain", "reaction" ] ])
]
, "Definition List With Trailing Header" =:
"- definition :: list\n\
\- cool :: defs\n\
\* header" =?>
mconcat [ definitionList [ ("definition", [plain "list"])
, ("cool", [plain "defs"])
]
, headerWith ("header", [], []) 1 "header"
]
, "Definition lists double-colon markers must be surrounded by whitespace" =:
"- std::cout" =?>
bulletList [ plain "std::cout" ]
, "Loose bullet list" =:
T.unlines [ "- apple"
, ""
, "- orange"
, ""
, "- peach"
] =?>
bulletList [ para "apple"
, para "orange"
, para "peach"
]
, "Recognize preceding paragraphs in non-list contexts" =:
T.unlines [ "CLOSED: [2015-10-19 Mon 15:03]"
, "- Note taken on [2015-10-19 Mon 13:24]"
] =?>
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")
]
]
|