test-org-list.el 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402
  1. ;;; test-org-list.el --- Tests for org-list.el
  2. ;; Copyright (C) 2012, 2013, 2014, 2018, 2019 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Code:
  15. (ert-deftest test-org-list/list-ending ()
  16. "Test if lists end at the right place."
  17. ;; With two blank lines.
  18. (org-test-with-temp-text "- item\n\n\n Text"
  19. (goto-line 4)
  20. (should-not (org-in-item-p)))
  21. ;; With text less indented than top items.
  22. (org-test-with-temp-text "- item\nText"
  23. (goto-line 2)
  24. (should-not (org-in-item-p)))
  25. ;; Though, blank lines and text indentation is ignored in blocks.
  26. (org-test-with-temp-text
  27. "- item\n #+begin_quote\n\n\nText at column 0\n #+end_quote\n Text"
  28. (goto-line 7)
  29. (should (org-in-item-p))))
  30. (ert-deftest test-org-list/list-navigation ()
  31. "Test list navigation specifications."
  32. (org-test-with-temp-text "
  33. - item A
  34. - item B
  35. - item 1
  36. - item 1.1
  37. - item 1.2
  38. - item 1.3
  39. - item 2
  40. - item X
  41. - item Y"
  42. (let ((org-list-use-circular-motion nil))
  43. ;; 1. Test `org-next-item'.
  44. ;;
  45. ;; 1.1. Should return an error if at last item in
  46. ;; a list/sub-list, unless `org-list-use-circular-motion'
  47. ;; is non-nil.
  48. (goto-line 9)
  49. (should-error (org-next-item))
  50. (let ((org-list-use-circular-motion t))
  51. (should (progn (org-next-item) t)))
  52. (goto-line 14)
  53. (should-error (org-next-item))
  54. (let ((org-list-use-circular-motion t))
  55. (should (progn (org-next-item) t)))
  56. ;; 1.2. Should jump over sub-lists.
  57. (goto-line 6)
  58. (org-next-item)
  59. (should (looking-at "- item 2"))
  60. ;; 1.3. Shouldn't move to another list.
  61. (goto-line 3)
  62. (should-error (org-next-item))
  63. (should-not (looking-at "- item 1"))
  64. ;; 1.4. Should move to the list/sub-list first item when
  65. ;; `org-list-use-circular-motion' is non-nil.
  66. (let ((org-list-use-circular-motion t))
  67. (goto-line 10)
  68. (org-next-item)
  69. (should (looking-at "- item 1"))
  70. (goto-line 9)
  71. (org-next-item)
  72. (should (looking-at " - item 1.1")))
  73. ;; 2. Test `org-previous-item'.
  74. ;;
  75. ;; 2.1. Should return an error if at first item in
  76. ;; a list/sub-list, unless `org-list-use-circular-motion is
  77. ;; non-nil.
  78. (goto-line 7)
  79. (should-error (org-previous-item))
  80. (let ((org-list-use-circular-motion t))
  81. (should (progn (org-previous-item) t)))
  82. (goto-line 13)
  83. (should-error (org-previous-item))
  84. (let ((org-list-use-circular-motion t))
  85. (should (progn (org-previous-item) t)))
  86. ;; 2.2. Should ignore sub-lists.
  87. (goto-line 10)
  88. (org-previous-item)
  89. (should (looking-at "- item 1"))
  90. ;; 2.3. Shouldn't move to another list.
  91. (goto-line 6)
  92. (should-error (org-previous-item))
  93. (should-not (looking-at "- item B"))
  94. ;; 2.4. Should move to the list/sub-list last item when
  95. ;; `org-list-use-circular-motion' is non-nil.
  96. (let ((org-list-use-circular-motion t))
  97. (goto-line 6)
  98. (org-previous-item)
  99. (should (looking-at "- item 2"))
  100. (goto-line 7)
  101. (org-previous-item)
  102. (should (looking-at " - item 1.3"))))))
  103. (ert-deftest test-org-list/cycle-bullet ()
  104. "Test `org-cycle-list-bullet' specifications."
  105. ;; Error when not at an item.
  106. (should-error
  107. (org-test-with-temp-text "Paragraph"
  108. (org-cycle-list-bullet)))
  109. ;; Cycle through "-", "+", "*", "1.", "1)".
  110. (org-test-with-temp-text " - item"
  111. (org-cycle-list-bullet)
  112. (should (looking-at "[ \t]+\\+"))
  113. (org-cycle-list-bullet)
  114. (should (looking-at "[ \t]+\\*"))
  115. (let ((org-plain-list-ordered-item-terminator t))
  116. (org-cycle-list-bullet))
  117. (should (looking-at "[ \t]+1\\."))
  118. (let ((org-plain-list-ordered-item-terminator t))
  119. (org-cycle-list-bullet))
  120. (should (looking-at "[ \t]+1)")))
  121. ;; Argument is a valid bullet: cycle to that bullet directly.
  122. (should
  123. (equal "1. item"
  124. (org-test-with-temp-text "- item"
  125. (let ((org-plain-list-ordered-item-terminator t))
  126. (org-cycle-list-bullet "1.")
  127. (buffer-string)))))
  128. ;; Argument is an integer N: cycle to the Nth allowed bullet.
  129. (should
  130. (equal "+ item"
  131. (org-test-with-temp-text "1. item"
  132. (let ((org-plain-list-ordered-item-terminator t))
  133. (org-cycle-list-bullet 1)
  134. (buffer-string)))))
  135. ;; Argument is `previous': cycle backwards.
  136. (should
  137. (equal "- item"
  138. (org-test-with-temp-text "+ item"
  139. (let ((org-plain-list-ordered-item-terminator t))
  140. (org-cycle-list-bullet 'previous)
  141. (buffer-string)))))
  142. ;; Do not cycle to "*" bullets when item is at column 0.
  143. (should
  144. (equal "1. item"
  145. (org-test-with-temp-text "+ item"
  146. (let ((org-plain-list-ordered-item-terminator t))
  147. (org-cycle-list-bullet)
  148. (buffer-string)))))
  149. ;; Do not cycle to numbered bullets in a description list.
  150. (should-not
  151. (equal "1. tag :: item"
  152. (org-test-with-temp-text "+ tag :: item"
  153. (let ((org-plain-list-ordered-item-terminator t))
  154. (org-cycle-list-bullet)
  155. (buffer-string)))))
  156. ;; Do not cycle to ordered item terminators if they are not allowed
  157. ;; in `org-plain-list-ordered-item-terminator'.
  158. (should
  159. (equal " 1) item"
  160. (org-test-with-temp-text " * item"
  161. (let ((org-plain-list-ordered-item-terminator 41))
  162. (org-cycle-list-bullet)
  163. (buffer-string)))))
  164. ;; When `org-list-allow-alphabetical' is non-nil, cycle to alpha bullets.
  165. (should
  166. (equal "a. item"
  167. (org-test-with-temp-text "1) item"
  168. (let ((org-plain-list-ordered-item-terminator t)
  169. (org-list-allow-alphabetical t))
  170. (org-cycle-list-bullet)
  171. (buffer-string)))))
  172. ;; Do not cycle to alpha bullets when list has more than 26
  173. ;; elements.
  174. (should-not
  175. (equal "a. item 1"
  176. (org-test-with-temp-text "1) item 1
  177. 2) item 2
  178. 3) item 3
  179. 4) item 4
  180. 5) item 5
  181. 6) item 6
  182. 7) item 7
  183. 8) item 8
  184. 9) item 9
  185. 10) item 10
  186. 11) item 11
  187. 12) item 12
  188. 13) item 13
  189. 14) item 14
  190. 15) item 15
  191. 16) item 16
  192. 17) item 17
  193. 18) item 18
  194. 19) item 19
  195. 20) item 20
  196. 21) item 21
  197. 22) item 22
  198. 23) item 23
  199. 24) item 24
  200. 25) item 25
  201. 26) item 26
  202. 27) item 27"
  203. (let ((org-plain-list-ordered-item-terminator t)
  204. (org-list-allow-alphabetical t))
  205. (org-cycle-list-bullet)
  206. (buffer-substring (point) (line-end-position)))))))
  207. (ert-deftest test-org-list/indent-item ()
  208. "Test `org-indent-item' specifications."
  209. ;; Error when not at an item.
  210. (org-test-with-temp-text "Paragraph."
  211. (should-error (org-indent-item)))
  212. ;; Error when trying to move first item of a list.
  213. (should-error
  214. (org-test-with-temp-text "
  215. - Item 1
  216. - Item 2"
  217. (forward-line)
  218. (org-indent-item)))
  219. (should-error
  220. (org-test-with-temp-text "
  221. - Item 1
  222. - Item 2"
  223. (forward-line)
  224. (let ((org-list-automatic-rules nil)) (org-indent-item))))
  225. ;; Indent a single item, not its children.
  226. (should
  227. (equal "
  228. - Item 1
  229. - Item 2
  230. - Item 2.1"
  231. (org-test-with-temp-text "
  232. - Item 1
  233. - Item 2<point>
  234. - Item 2.1"
  235. (let (org-list-demote-modify-bullet) (org-indent-item))
  236. (buffer-string))))
  237. ;; Follow `org-list-demote-modify-bullet' specifications.
  238. (should
  239. (equal "
  240. - Item 1
  241. + Item 2"
  242. (org-test-with-temp-text "
  243. - Item 1
  244. - Item 2<point>"
  245. (let ((org-list-demote-modify-bullet '(("-" . "+"))))
  246. (org-indent-item))
  247. (buffer-string))))
  248. (should
  249. (equal "
  250. 1. Item 1
  251. + Item 2"
  252. (org-test-with-temp-text "
  253. 1. Item 1
  254. 2. Item 2<point>"
  255. (let ((org-plain-list-ordered-item-terminator t)
  256. (org-list-demote-modify-bullet '(("1." . "+"))))
  257. (org-indent-item))
  258. (buffer-string))))
  259. (should
  260. (equal "
  261. a. Item 1
  262. - Item 2"
  263. (org-test-with-temp-text "
  264. a. Item 1
  265. b. Item 2<point>"
  266. (let ((org-plain-list-ordered-item-terminator t)
  267. (org-list-allow-alphabetical t)
  268. (org-list-demote-modify-bullet '(("A." . "a.") ("a." . "-"))))
  269. (org-indent-item))
  270. (buffer-string))))
  271. ;; When a region is selected, indent every item within.
  272. (should
  273. (equal "
  274. - Item 1
  275. - Item 2
  276. - Item 3
  277. "
  278. (org-test-with-temp-text "
  279. - Item 1
  280. <point>- Item 2
  281. - Item 3
  282. "
  283. (transient-mark-mode 1)
  284. (push-mark (point) t t)
  285. (goto-char (point-max))
  286. (let (org-list-demote-modify-bullet) (org-indent-item))
  287. (buffer-string)))))
  288. (ert-deftest test-org-list/indent-item-tree ()
  289. "Test `org-indent-item-tree' specifications."
  290. ;; 1. Error when not at an item.
  291. (org-test-with-temp-text "Paragraph."
  292. (should-error (org-indent-item-tree)))
  293. ;; 2. Indent item along with its children.
  294. (org-test-with-temp-text "
  295. - Item 1
  296. - Item 2
  297. - Item 2.1"
  298. (search-forward "- Item 2")
  299. (let (org-list-demote-modify-bullet) (org-indent-item-tree))
  300. (should (equal (buffer-string)
  301. "
  302. - Item 1
  303. - Item 2
  304. - Item 2.1")))
  305. ;; 3. Special case: When indenting top item, move the whole list.
  306. (org-test-with-temp-text "
  307. - Item 1
  308. - Item 2"
  309. (search-forward "- Item 1")
  310. (let (org-list-demote-modify-bullet org-odd-levels-only)
  311. (org-indent-item-tree))
  312. (should (equal (buffer-string)
  313. "
  314. - Item 1
  315. - Item 2")))
  316. ;; 4. Follow `org-list-demote-modify-bullet' specifications.
  317. ;;
  318. ;; 4.1. With unordered lists.
  319. (org-test-with-temp-text "
  320. - Item 1
  321. - Item 2
  322. + Item 2.1"
  323. (search-forward "- Item 2")
  324. (let ((org-list-demote-modify-bullet '(("-" . "+") ("+" . "-"))))
  325. (org-indent-item-tree))
  326. (should (equal (buffer-string)
  327. "
  328. - Item 1
  329. + Item 2
  330. - Item 2.1")))
  331. ;; 4.2. and ordered lists.
  332. (org-test-with-temp-text "
  333. 1. Item 1
  334. 2. Item 2
  335. + Item 2.1"
  336. (search-forward "2. Item 2")
  337. (let ((org-plain-list-ordered-item-terminator t)
  338. (org-list-demote-modify-bullet '(("1." . "+") ("+" . "1."))))
  339. (org-indent-item-tree))
  340. (should (equal (buffer-string)
  341. "
  342. 1. Item 1
  343. + Item 2
  344. 1. Item 2.1")))
  345. ;; 5. When a region is selected, indent every item within.
  346. (org-test-with-temp-text "
  347. - Item 1
  348. - Item 2
  349. - Item 2.1
  350. - Item 3
  351. - Item 3.1
  352. "
  353. (search-forward "- Item 2")
  354. (beginning-of-line)
  355. (transient-mark-mode 1)
  356. (push-mark (point) t t)
  357. (goto-char (point-max))
  358. (let (org-list-demote-modify-bullet) (org-indent-item-tree))
  359. (should (equal (buffer-string)
  360. "
  361. - Item 1
  362. - Item 2
  363. - Item 2.1
  364. - Item 3
  365. - Item 3.1
  366. "))))
  367. (ert-deftest test-org-list/outdent-item ()
  368. "Test `org-outdent-item' specifications."
  369. ;; 1. Error when not at an item.
  370. (org-test-with-temp-text "Paragraph."
  371. (should-error (org-outdent-item)))
  372. ;; 2. Error when trying to move first item of a list.
  373. (org-test-with-temp-text "
  374. - Item 1
  375. - Item 2"
  376. (forward-line)
  377. (should-error (org-outdent-item)))
  378. ;; 3. Error when trying to outdent an item without its children.
  379. (org-test-with-temp-text "
  380. - Item 1
  381. - Item 1.1
  382. - Item 1.1.1"
  383. (search-forward "- Item 1.1")
  384. (should-error (org-outdent-item)))
  385. ;; 4. Error when trying to outdent before top item.
  386. (org-test-with-temp-text "
  387. - Item 1
  388. - Item 2"
  389. (search-forward "- Item 2")
  390. (should-error (org-outdent-item)))
  391. ;; 5. When a region is selected, outdent every item within.
  392. (org-test-with-temp-text "
  393. - Item 1
  394. - Item 2
  395. - Item 3
  396. "
  397. (search-forward "- Item 2")
  398. (beginning-of-line)
  399. (transient-mark-mode 1)
  400. (push-mark (point) t t)
  401. (goto-char (point-max))
  402. (let (org-list-demote-modify-bullet) (org-outdent-item))
  403. (should (equal (buffer-string)
  404. "
  405. - Item 1
  406. - Item 2
  407. - Item 3
  408. "))))
  409. (ert-deftest test-org-list/outdent-item-tree ()
  410. "Test `org-outdent-item-tree' specifications."
  411. ;; 1. Error when not at an item.
  412. (org-test-with-temp-text "Paragraph."
  413. (should-error (org-outdent-item-tree)))
  414. ;; 2. Error when trying to outdent before top item.
  415. (org-test-with-temp-text "
  416. - Item 1
  417. - Item 2"
  418. (search-forward "- Item 2")
  419. (should-error (org-outdent-item-tree)))
  420. ;; 3. Outdent item along with its children.
  421. (org-test-with-temp-text "
  422. - Item 1
  423. - Item 2
  424. - Item 2.1"
  425. (search-forward "- Item 2")
  426. (org-outdent-item-tree)
  427. (should (equal (buffer-string)
  428. "
  429. - Item 1
  430. - Item 2
  431. - Item 2.1")))
  432. ;; 3. Special case: When outdenting top item, move the whole list.
  433. (org-test-with-temp-text "
  434. - Item 1
  435. - Item 2"
  436. (search-forward "- Item 1")
  437. (let (org-odd-levels-only) (org-outdent-item-tree))
  438. (should (equal (buffer-string)
  439. "
  440. - Item 1
  441. - Item 2")))
  442. ;; 5. When a region is selected, outdent every item within.
  443. (org-test-with-temp-text "
  444. - Item 1
  445. - Item 2
  446. - Item 2.1
  447. - Item 3
  448. - Item 3.1
  449. "
  450. (search-forward "- Item 2")
  451. (beginning-of-line)
  452. (transient-mark-mode 1)
  453. (push-mark (point) t t)
  454. (goto-char (point-max))
  455. (org-outdent-item-tree)
  456. (should (equal (buffer-string)
  457. "
  458. - Item 1
  459. - Item 2
  460. - Item 2.1
  461. - Item 3
  462. - Item 3.1
  463. "))))
  464. (ert-deftest test-org-list/move-item-down ()
  465. "Test `org-move-item-down' specifications."
  466. ;; Standard test.
  467. (org-test-with-temp-text "- item 1\n- item 2"
  468. (org-move-item-down)
  469. (should (equal (buffer-string)
  470. "- item 2\n- item 1")))
  471. ;; Keep same column in item.
  472. (org-test-with-temp-text "- item 1\n- item 2"
  473. (forward-char 4)
  474. (org-move-item-down)
  475. (should (looking-at "em 1")))
  476. ;; Move sub-items.
  477. (org-test-with-temp-text "- item 1\n - sub-item 1\n- item 2"
  478. (org-move-item-down)
  479. (should (equal (buffer-string)
  480. "- item 2\n- item 1\n - sub-item 1")))
  481. ;; Preserve blank lines.
  482. (should
  483. (equal
  484. "- item 2\n\n- item 1"
  485. (org-test-with-temp-text "- item 1\n\n- item 2"
  486. (org-move-item-down)
  487. (buffer-string))))
  488. ;; Error when trying to move the last item...
  489. (org-test-with-temp-text "- item 1\n- item 2"
  490. (forward-line)
  491. (should-error (org-move-item-down)))
  492. ;; ... unless `org-list-use-circular-motion' is non-nil. In this
  493. ;; case, move to the first item.
  494. (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
  495. (forward-line 2)
  496. (let ((org-list-use-circular-motion t)) (org-move-item-down))
  497. (should (equal (buffer-string) "- item 3\n- item 1\n- item 2\n")))
  498. ;; Preserve item visibility.
  499. (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
  500. (let ((org-cycle-include-plain-lists t))
  501. (search-forward "- item 1")
  502. (org-cycle)
  503. (search-forward "- item 2")
  504. (org-cycle))
  505. (search-backward "- item 1")
  506. (org-move-item-down)
  507. (forward-line)
  508. (should (org-invisible-p2))
  509. (search-backward " body 2")
  510. (should (org-invisible-p2)))
  511. ;; Preserve children visibility.
  512. (org-test-with-temp-text "* Headline
  513. - item 1
  514. - sub-item 1
  515. sub-body 1
  516. - item 2
  517. - sub-item 2
  518. sub-body 2"
  519. (let ((org-cycle-include-plain-lists t))
  520. (search-forward "- sub-item 1")
  521. (org-cycle)
  522. (search-forward "- sub-item 2")
  523. (org-cycle))
  524. (search-backward "- item 1")
  525. (org-move-item-down)
  526. (search-forward "sub-body 1")
  527. (should (org-invisible-p2))
  528. (search-backward "sub-body 2")
  529. (should (org-invisible-p2))))
  530. (ert-deftest test-org-list/move-item-down-contents-visibility ()
  531. "Preserve contents visibility."
  532. (org-test-with-temp-text "
  533. - item 1
  534. #+BEGIN_CENTER
  535. Text1
  536. #+END_CENTER
  537. - item 2
  538. #+BEGIN_CENTER
  539. Text2
  540. #+END_CENTER"
  541. (org-hide-block-all)
  542. (let ((invisible-property-1
  543. (progn
  544. (search-forward "Text1")
  545. (get-char-property (point) 'invisible)))
  546. (invisible-property-2
  547. (progn
  548. (search-forward "Text2")
  549. (get-char-property (point) 'invisible))))
  550. (goto-char (point-min))
  551. (search-forward "- item 1")
  552. (org-move-item-down)
  553. (search-forward "Text1")
  554. (should (eq invisible-property-1 (get-char-property (point) 'invisible)))
  555. (search-backward "Text2")
  556. (should (eq invisible-property-2 (get-char-property (point) 'invisible))))))
  557. (ert-deftest test-org-list/move-item-up ()
  558. "Test `org-move-item-up' specifications."
  559. ;; Standard test.
  560. (org-test-with-temp-text "- item 1\n- item 2"
  561. (forward-line)
  562. (org-move-item-up)
  563. (should (equal (buffer-string)
  564. "- item 2\n- item 1")))
  565. ;; Keep same column in item.
  566. (org-test-with-temp-text "- item 1\n- item 2"
  567. (forward-line)
  568. (forward-char 4)
  569. (org-move-item-up)
  570. (should (looking-at "em 2")))
  571. ;; Move sub-items.
  572. (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
  573. (forward-line)
  574. (org-move-item-up)
  575. (should (equal (buffer-string)
  576. "- item 2\n - sub-item 2\n- item 1")))
  577. ;; Preserve blank lines.
  578. (should
  579. (equal
  580. "- item 2\n\n- item 1"
  581. (org-test-with-temp-text "- item 1\n\n- item 2"
  582. (search-forward "- item 2")
  583. (org-move-item-up)
  584. (buffer-string))))
  585. ;; Error when trying to move the first item...
  586. (org-test-with-temp-text "- item 1\n- item 2"
  587. (should-error (org-move-item-up)))
  588. ;; ... unless `org-list-use-circular-motion' is non-nil. In this
  589. ;; case, move to the first item.
  590. (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
  591. (let ((org-list-use-circular-motion t)) (org-move-item-up))
  592. (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
  593. ;; Preserve item visibility.
  594. (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
  595. (let ((org-cycle-include-plain-lists t))
  596. (search-forward "- item 1")
  597. (org-cycle)
  598. (search-forward "- item 2")
  599. (org-cycle))
  600. (org-move-item-up)
  601. (forward-line)
  602. (should (org-invisible-p2))
  603. (search-forward " body 1")
  604. (should (org-invisible-p2)))
  605. ;; Preserve children visibility.
  606. (org-test-with-temp-text "* Headline
  607. - item 1
  608. - sub-item 1
  609. sub-body 1
  610. - item 2
  611. - sub-item 2
  612. sub-body 2"
  613. (let ((org-cycle-include-plain-lists t))
  614. (search-forward "- sub-item 1")
  615. (org-cycle)
  616. (search-forward "- sub-item 2")
  617. (org-cycle))
  618. (search-backward "- item 2")
  619. (org-move-item-up)
  620. (search-forward "sub-body 2")
  621. (should (org-invisible-p2))
  622. (search-forward "sub-body 1")
  623. (should (org-invisible-p2))))
  624. (ert-deftest test-org-list/move-item-up-contents-visibility ()
  625. (org-test-with-temp-text "
  626. - item 1
  627. #+BEGIN_CENTER
  628. Text1
  629. #+END_CENTER
  630. - item 2
  631. #+BEGIN_CENTER
  632. Text2
  633. #+END_CENTER"
  634. (org-hide-block-all)
  635. (let ((invisible-property-1
  636. (progn
  637. (search-forward "Text1")
  638. (get-char-property (point) 'invisible)))
  639. (invisible-property-2
  640. (progn
  641. (search-forward "Text2")
  642. (get-char-property (point) 'invisible))))
  643. (goto-char (point-min))
  644. (search-forward "- item 2")
  645. (org-move-item-up)
  646. (search-forward "Text2")
  647. (should (eq invisible-property-2 (get-char-property (point) 'invisible)))
  648. (search-forward "Text1")
  649. (should (eq invisible-property-1 (get-char-property (point) 'invisible))))))
  650. (ert-deftest test-org-list/insert-item ()
  651. "Test item insertion."
  652. ;; Blank lines specifications.
  653. ;;
  654. ;; Non-nil `org-blank-before-new-entry': insert a blank line.
  655. (should
  656. (org-test-with-temp-text "- a"
  657. (let ((org-blank-before-new-entry '((plain-list-item . t))))
  658. (end-of-line)
  659. (org-insert-item)
  660. (forward-line -1)
  661. (looking-at "$"))))
  662. ;; Nil `org-blank-before-new-entry': do not insert a blank line.
  663. (should-not
  664. (org-test-with-temp-text "- a"
  665. (let ((org-blank-before-new-entry '((plain-list-item . nil))))
  666. (end-of-line)
  667. (org-insert-item)
  668. (forward-line -1)
  669. (looking-at "$"))))
  670. ;; `org-blank-before-new-entry' set to auto: if there's no blank
  671. ;; line already in the sole item, do not insert one.
  672. (should-not
  673. (org-test-with-temp-text "- a"
  674. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  675. (end-of-line)
  676. (org-insert-item)
  677. (forward-line -1)
  678. (looking-at "$"))))
  679. ;; `org-blank-before-new-entry' set to `auto': if there's a blank
  680. ;; line in the sole item, insert another one.
  681. (should
  682. (org-test-with-temp-text "- a\n\n b<point>"
  683. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  684. (org-insert-item)
  685. (forward-line -1)
  686. (looking-at "$"))))
  687. ;; `org-blank-before-new-entry' set to `auto': if the user specified
  688. ;; a blank line, preserve it.
  689. (should
  690. (org-test-with-temp-text "- a\n\n<point>"
  691. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  692. (org-insert-item)
  693. (forward-line -1)
  694. (looking-at "$"))))
  695. ;; `org-blank-before-new-entry' set to `auto': if some items in list
  696. ;; are already separated by blank lines, insert one.
  697. (should
  698. (org-test-with-temp-text "- a\n\n- b<point>"
  699. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  700. (org-insert-item)
  701. (forward-line -1)
  702. (looking-at "$"))))
  703. (should
  704. (org-test-with-temp-text "- a\n\n- b"
  705. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  706. (org-insert-item)
  707. (forward-line)
  708. (looking-at "$"))))
  709. (should
  710. (org-test-with-temp-text
  711. "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE<point>"
  712. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  713. (org-insert-item)
  714. (forward-line -1)
  715. (looking-at "$"))))
  716. ;; When called before or on the bullet, insert new item before
  717. ;; current one.
  718. (should
  719. (equal "- \n- item"
  720. (org-test-with-temp-text "- item"
  721. (org-insert-item)
  722. (buffer-string))))
  723. (should
  724. (equal "- \n- item"
  725. (org-test-with-temp-text "- <point>item"
  726. (org-insert-item)
  727. (buffer-string))))
  728. ;; When called on tag in a descriptive list, insert new item before
  729. ;; current one too.
  730. (should
  731. (equal "- :: \n- tag :: item"
  732. (org-test-with-temp-text "- tag <point>:: item"
  733. (org-insert-item)
  734. (buffer-string))))
  735. (should
  736. (equal "- :: \n- tag :: item"
  737. (org-test-with-temp-text "- ta<point>g :: item"
  738. (org-insert-item)
  739. (buffer-string))))
  740. ;; Further, it splits the line or add a blank new item after it,
  741. ;; according to `org-M-RET-may-split-line'.
  742. (should
  743. (equal "- it\n- em"
  744. (org-test-with-temp-text "- it<point>em"
  745. (let ((org-M-RET-may-split-line '((default . t))))
  746. (org-insert-item))
  747. (buffer-string))))
  748. (should
  749. (equal "- item\n- "
  750. (org-test-with-temp-text "- it<point>em"
  751. (let ((org-M-RET-may-split-line '((default . nil))))
  752. (org-insert-item))
  753. (buffer-string))))
  754. ;; Preserve list visibility when inserting an item.
  755. (should
  756. (equal
  757. '(outline outline)
  758. (org-test-with-temp-text "- A\n - B\n- C\n - D"
  759. (let ((org-cycle-include-plain-lists t))
  760. (org-cycle)
  761. (forward-line 2)
  762. (org-cycle)
  763. (org-insert-item)
  764. (list (get-char-property (line-beginning-position 0) 'invisible)
  765. (get-char-property (line-end-position 2) 'invisible)))))))
  766. (ert-deftest test-org-list/repair ()
  767. "Test `org-list-repair' specifications."
  768. ;; Repair indentation.
  769. (should
  770. (equal "- item\n - child"
  771. (org-test-with-temp-text "- item\n - child"
  772. (let ((org-list-indent-offset 0)) (org-list-repair))
  773. (buffer-string))))
  774. ;; Repair bullets and numbering.
  775. (should
  776. (equal "- a\n- b"
  777. (org-test-with-temp-text "- a\n+ b"
  778. (let ((org-list-indent-offset 0))
  779. (org-list-repair))
  780. (buffer-string))))
  781. (should
  782. (equal "1. a\n2. b"
  783. (org-test-with-temp-text "1. a\n1. b"
  784. (let ((org-list-indent-offset 0)
  785. (org-plain-list-ordered-item-terminator t))
  786. (org-list-repair))
  787. (buffer-string))))
  788. ;; Repair check-boxes.
  789. (should
  790. (equal "- [X] item\n - [X] child"
  791. (org-test-with-temp-text "- [ ] item\n - [X] child"
  792. (let ((org-list-indent-offset 0))
  793. (org-list-repair))
  794. (buffer-string))))
  795. ;; Special case: do not move contents of an item within its child.
  796. ;; Yet, preserve indentation differences within contents.
  797. (should
  798. (equal "- item\n - child\n within item"
  799. (org-test-with-temp-text "- item\n - child\n within item"
  800. (let ((org-list-indent-offset 0)) (org-list-repair))
  801. (buffer-string))))
  802. (should
  803. (equal
  804. "- item\n - child\n within item\n indented"
  805. (org-test-with-temp-text
  806. "- item\n - child\n within item\n indented"
  807. (let ((org-list-indent-offset 0)) (org-list-repair))
  808. (buffer-string)))))
  809. (ert-deftest test-org-list/update-checkbox-count ()
  810. "Test `org-update-checkbox-count' specifications."
  811. ;; From a headline.
  812. (should
  813. (string-match "\\[0/1\\]"
  814. (org-test-with-temp-text "* [/]\n- [ ] item"
  815. (org-update-checkbox-count)
  816. (buffer-string))))
  817. (should
  818. (string-match "\\[1/1\\]"
  819. (org-test-with-temp-text "* [/]\n- [X] item"
  820. (org-update-checkbox-count)
  821. (buffer-string))))
  822. (should
  823. (string-match "\\[100%\\]"
  824. (org-test-with-temp-text "* [%]\n- [X] item"
  825. (org-update-checkbox-count)
  826. (buffer-string))))
  827. ;; From a list or a sub-list.
  828. (should
  829. (string-match "\\[0/1\\]"
  830. (org-test-with-temp-text "- [/]\n - [ ] item"
  831. (org-update-checkbox-count)
  832. (buffer-string))))
  833. (should
  834. (string-match "\\[1/1\\]"
  835. (org-test-with-temp-text "- [/]\n - [X] item"
  836. (org-update-checkbox-count)
  837. (buffer-string))))
  838. (should
  839. (string-match "\\[100%\\]"
  840. (org-test-with-temp-text "- [%]\n - [X] item"
  841. (org-update-checkbox-count)
  842. (buffer-string))))
  843. (should
  844. (string-match
  845. "\\[1/1\\]"
  846. (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
  847. (org-update-checkbox-count)
  848. (buffer-string))))
  849. ;; Count do not apply to sub-lists unless count is not hierarchical.
  850. ;; This state can be achieved with COOKIE_DATA node property set to
  851. ;; "recursive".
  852. (should
  853. (string-match "\\[1/1\\]"
  854. (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
  855. (let ((org-checkbox-hierarchical-statistics nil))
  856. (org-update-checkbox-count))
  857. (buffer-string))))
  858. (should
  859. (string-match "\\[1/1\\]"
  860. (org-test-with-temp-text "
  861. <point>* H
  862. :PROPERTIES:
  863. :COOKIE_DATA: recursive
  864. :END:
  865. - [/]
  866. - item
  867. - [X] sub-item"
  868. (org-update-checkbox-count)
  869. (buffer-string))))
  870. (should
  871. (string-match "\\[0/0\\]"
  872. (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
  873. (org-update-checkbox-count)
  874. (buffer-string))))
  875. ;; With optional argument ALL, update all buffer.
  876. (should
  877. (= 2
  878. (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
  879. (org-update-checkbox-count t)
  880. (count-matches "\\[1/1\\]"))))
  881. ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
  882. ;; outside.
  883. (should
  884. (string-match "\\[2/2\\]"
  885. (org-test-with-temp-text "
  886. - [/]
  887. - [X] item1
  888. :DRAWER:
  889. - [X] item
  890. :END:
  891. - [X] item2"
  892. (let ((org-checkbox-hierarchical-statistics nil))
  893. (org-update-checkbox-count))
  894. (buffer-string)))))
  895. ;;; Miscellaneous
  896. (ert-deftest test-org-list/toggle-item ()
  897. "Test `org-toggle-item' specifications."
  898. ;; Convert normal lines to items.
  899. (should
  900. (equal "- line"
  901. (org-test-with-temp-text "line"
  902. (org-toggle-item nil)
  903. (buffer-string))))
  904. ;; Convert items to normal lines.
  905. (should
  906. (equal "line"
  907. (org-test-with-temp-text "- line"
  908. (org-toggle-item nil)
  909. (buffer-string))))
  910. ;; Convert headlines to items.
  911. (should
  912. (equal "- line"
  913. (org-test-with-temp-text "* line"
  914. (org-toggle-item nil)
  915. (buffer-string))))
  916. ;; When converting a headline to a list item, TODO keywords become
  917. ;; checkboxes.
  918. (should
  919. (equal "- [X] line"
  920. (org-test-with-temp-text "* DONE line"
  921. (org-toggle-item nil)
  922. (buffer-string))))
  923. (should
  924. (equal "- [ ] line"
  925. (org-test-with-temp-text "* TODO line"
  926. (org-toggle-item nil)
  927. (buffer-string))))
  928. ;; When turning headlines into items, make sure planning info line
  929. ;; and properties drawers are removed. This also includes empty
  930. ;; lines following them.
  931. (should
  932. (equal "- H\n"
  933. (org-test-with-temp-text "* H\nSCHEDULED: <2012-03-29 Thu>"
  934. (org-toggle-item nil)
  935. (buffer-string))))
  936. (should
  937. (equal "- H\n"
  938. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  939. (org-toggle-item nil)
  940. (buffer-string))))
  941. (should
  942. (equal "- H\nText"
  943. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:\n\n\nText"
  944. (org-toggle-item nil)
  945. (buffer-string))))
  946. ;; When a region is marked and first line is a headline, all
  947. ;; headlines are turned into items.
  948. (should
  949. (equal "- H1\n - H2"
  950. (org-test-with-temp-text "* H1\n** H2"
  951. (transient-mark-mode 1)
  952. (push-mark (point) t t)
  953. (goto-char (point-max))
  954. (org-toggle-item nil)
  955. (buffer-string))))
  956. (should
  957. (equal "- [ ] H1\n - [ ] H2"
  958. (org-test-with-temp-text "* TODO H1\n** TODO H2"
  959. (transient-mark-mode 1)
  960. (push-mark (point) t t)
  961. (goto-char (point-max))
  962. (org-toggle-item nil)
  963. (buffer-string))))
  964. ;; When turning headlines into items, make sure headings contents
  965. ;; are kept within items.
  966. (should
  967. (equal "- H1\n Text"
  968. (org-test-with-temp-text "* H1\nText"
  969. (transient-mark-mode 1)
  970. (push-mark (point) t t)
  971. (goto-char (point-max))
  972. (org-toggle-item nil)
  973. (buffer-string))))
  974. ;; When a region is marked and first line is an item, all items are
  975. ;; turned into normal lines.
  976. (should
  977. (equal "1\n 2"
  978. (org-test-with-temp-text "- 1\n - 2"
  979. (transient-mark-mode 1)
  980. (push-mark (point) t t)
  981. (goto-char (point-max))
  982. (org-toggle-item nil)
  983. (buffer-string))))
  984. (should
  985. (equal "1\n2"
  986. (org-test-with-temp-text "- 1\n2"
  987. (transient-mark-mode 1)
  988. (push-mark (point) t t)
  989. (goto-char (point-max))
  990. (org-toggle-item nil)
  991. (buffer-string))))
  992. ;; When a region is marked and first line is an item, all normal
  993. ;; lines are turned into items.
  994. (should
  995. (equal "- line 1\n- line 2"
  996. (org-test-with-temp-text "line 1\nline 2"
  997. (transient-mark-mode 1)
  998. (push-mark (point) t t)
  999. (goto-char (point-max))
  1000. (org-toggle-item nil)
  1001. (buffer-string))))
  1002. (should
  1003. (equal "- line 1\n- line 2"
  1004. (org-test-with-temp-text "line 1\n- line 2"
  1005. (transient-mark-mode 1)
  1006. (push-mark (point) t t)
  1007. (goto-char (point-max))
  1008. (org-toggle-item nil)
  1009. (buffer-string))))
  1010. ;; When argument ARG is non-nil, change the whole region into
  1011. ;; a single item.
  1012. (should
  1013. (equal "- line 1\n line 2"
  1014. (org-test-with-temp-text "line 1\nline 2"
  1015. (transient-mark-mode 1)
  1016. (push-mark (point) t t)
  1017. (goto-char (point-max))
  1018. (org-toggle-item t)
  1019. (buffer-string)))))
  1020. (ert-deftest test-org-list/sort ()
  1021. "Test `org-sort-list'."
  1022. ;; Sort alphabetically.
  1023. (let ((original-string-collate-lessp (symbol-function 'string-collate-lessp)))
  1024. (cl-letf (((symbol-function 'string-collate-lessp)
  1025. (lambda (s1 s2 &optional locale ignore-case)
  1026. (funcall original-string-collate-lessp
  1027. s1 s2 "C" ignore-case))))
  1028. (should
  1029. (equal "- abc\n- def\n- XYZ\n"
  1030. (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
  1031. (org-sort-list nil ?a)
  1032. (buffer-string))))
  1033. (should
  1034. (equal "- XYZ\n- def\n- abc\n"
  1035. (org-test-with-temp-text "- def\n- XYZ\n- abc\n"
  1036. (org-sort-list nil ?A)
  1037. (buffer-string))))
  1038. ;; Sort alphabetically (with case).
  1039. (should
  1040. (equal "- C\n- a\n- b\n"
  1041. (org-test-with-temp-text "- b\n- C\n- a\n"
  1042. (org-sort-list t ?a)
  1043. (buffer-string))))
  1044. (should
  1045. (equal "- b\n- a\n- C\n"
  1046. (org-test-with-temp-text "- b\n- C\n- a\n"
  1047. (org-sort-list t ?A)
  1048. (buffer-string))))))
  1049. ;; Sort numerically.
  1050. (should
  1051. (equal "- 1\n- 2\n- 10\n"
  1052. (org-test-with-temp-text "- 10\n- 1\n- 2\n"
  1053. (org-sort-list nil ?n)
  1054. (buffer-string))))
  1055. (should
  1056. (equal "- 10\n- 2\n- 1\n"
  1057. (org-test-with-temp-text "- 10\n- 1\n- 2\n"
  1058. (org-sort-list nil ?N)
  1059. (buffer-string))))
  1060. ;; Sort by checked status.
  1061. (should
  1062. (equal "- [ ] xyz\n- [ ] def\n- [X] abc\n"
  1063. (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1064. (org-sort-list nil ?x)
  1065. (buffer-string))))
  1066. (should
  1067. (equal "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1068. (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1069. (org-sort-list nil ?X)
  1070. (buffer-string))))
  1071. ;; Sort by time stamp.
  1072. (should
  1073. (equal "- <2017-05-08 Mon>\n- <2017-05-09 Tue>\n- <2018-05-09 Wed>\n"
  1074. (org-test-with-temp-text
  1075. "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1076. (org-sort-list nil ?t)
  1077. (buffer-string))))
  1078. (should
  1079. (equal "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1080. (org-test-with-temp-text
  1081. "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1082. (org-sort-list nil ?T)
  1083. (buffer-string))))
  1084. ;; Sort by custom function.
  1085. (should
  1086. (equal "- b\n- aa\n- ccc\n"
  1087. (org-test-with-temp-text "- ccc\n- b\n- aa\n"
  1088. (org-sort-list nil ?f
  1089. (lambda ()
  1090. (length (buffer-substring (point-at-bol)
  1091. (point-at-eol))))
  1092. #'<)
  1093. (buffer-string))))
  1094. (should
  1095. (equal "- ccc\n- aa\n- b\n"
  1096. (org-test-with-temp-text "- ccc\n- b\n- aa\n"
  1097. (org-sort-list nil ?F
  1098. (lambda ()
  1099. (length (buffer-substring (point-at-bol)
  1100. (point-at-eol))))
  1101. #'<)
  1102. (buffer-string)))))
  1103. ;;; List transformations
  1104. (ert-deftest test-org-list/to-generic ()
  1105. "Test `org-list-to-generic' specifications."
  1106. ;; Test `:ustart' and `:uend' parameters.
  1107. (should
  1108. (equal
  1109. "begin\na"
  1110. (org-test-with-temp-text "- a"
  1111. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1112. (should-not
  1113. (equal
  1114. "begin\na"
  1115. (org-test-with-temp-text "1. a"
  1116. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1117. (should
  1118. (equal
  1119. "a\nend"
  1120. (org-test-with-temp-text "- a"
  1121. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1122. (should-not
  1123. (equal
  1124. "a\nend"
  1125. (org-test-with-temp-text "1. a"
  1126. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1127. (should
  1128. (equal
  1129. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1130. (org-test-with-temp-text "- a\n - b"
  1131. (org-list-to-generic
  1132. (org-list-to-lisp)
  1133. (list :ustart (lambda (l) (format "begin l%d" l))
  1134. :uend (lambda (l) (format "end l%d" l)))))))
  1135. ;; Test `:ostart' and `:oend' parameters.
  1136. (should
  1137. (equal
  1138. "begin\na"
  1139. (org-test-with-temp-text "1. a"
  1140. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1141. (should-not
  1142. (equal
  1143. "begin\na"
  1144. (org-test-with-temp-text "- a"
  1145. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1146. (should
  1147. (equal
  1148. "a\nend"
  1149. (org-test-with-temp-text "1. a"
  1150. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1151. (should-not
  1152. (equal
  1153. "a\nend"
  1154. (org-test-with-temp-text "- a"
  1155. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1156. (should
  1157. (equal
  1158. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1159. (org-test-with-temp-text "1. a\n 1. b"
  1160. (org-list-to-generic
  1161. (org-list-to-lisp)
  1162. (list :ostart (lambda (l) (format "begin l%d" l))
  1163. :oend (lambda (l) (format "end l%d" l)))))))
  1164. ;; Test `:dstart' and `:dend' parameters.
  1165. (should
  1166. (equal
  1167. "begin\ntaga"
  1168. (org-test-with-temp-text "- tag :: a"
  1169. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1170. (should-not
  1171. (equal
  1172. "begin\na"
  1173. (org-test-with-temp-text "- a"
  1174. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1175. (should
  1176. (equal
  1177. "taga\nend"
  1178. (org-test-with-temp-text "- tag :: a"
  1179. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1180. (should-not
  1181. (equal
  1182. "a\nend"
  1183. (org-test-with-temp-text "- a"
  1184. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1185. (should
  1186. (equal
  1187. "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
  1188. (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
  1189. (org-list-to-generic
  1190. (org-list-to-lisp)
  1191. (list :dstart (lambda (l) (format "begin l%d" l))
  1192. :dend (lambda (l) (format "end l%d" l)))))))
  1193. ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
  1194. (should
  1195. (equal
  1196. ">tag<a"
  1197. (org-test-with-temp-text "- tag :: a"
  1198. (org-list-to-generic (org-list-to-lisp) '(:dtstart ">" :dtend "<")))))
  1199. (should
  1200. (equal
  1201. "tag>a<"
  1202. (org-test-with-temp-text "- tag :: a"
  1203. (org-list-to-generic (org-list-to-lisp) '(:ddstart ">" :ddend "<")))))
  1204. ;; Test `:istart' and `:iend' parameters.
  1205. (should
  1206. (equal
  1207. "starta"
  1208. (org-test-with-temp-text "- a"
  1209. (org-list-to-generic (org-list-to-lisp) '(:istart "start")))))
  1210. (should
  1211. (equal
  1212. "level1 a\nlevel2 b"
  1213. (org-test-with-temp-text "- a\n - b"
  1214. (org-list-to-generic (org-list-to-lisp)
  1215. '(:istart (lambda (type l) (format "level%d "l)))))))
  1216. (should
  1217. (equal
  1218. "a\nblevel2level1"
  1219. (org-test-with-temp-text "- a\n - b"
  1220. (org-list-to-generic (org-list-to-lisp)
  1221. '(:iend (lambda (type l) (format "level%d" l)))))))
  1222. ;; Test `:icount' parameter.
  1223. (should
  1224. (equal
  1225. "counta"
  1226. (org-test-with-temp-text "1. [@3] a"
  1227. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1228. (should-not
  1229. (equal
  1230. "counta"
  1231. (org-test-with-temp-text "1. a"
  1232. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1233. (should
  1234. (equal
  1235. "counta"
  1236. (org-test-with-temp-text "1. [@3] a"
  1237. (org-list-to-generic (org-list-to-lisp)
  1238. '(:icount "count" :istart "start")))))
  1239. (should
  1240. (equal
  1241. "level:1, counter:3 a"
  1242. (org-test-with-temp-text "1. [@3] a"
  1243. (org-list-to-generic
  1244. (org-list-to-lisp)
  1245. '(:icount (lambda (type l c) (format "level:%d, counter:%d " l c)))))))
  1246. ;; Test `:isep' parameter.
  1247. (should
  1248. (equal
  1249. "a\n--\nb"
  1250. (org-test-with-temp-text "- a\n- b"
  1251. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1252. (should-not
  1253. (equal
  1254. "a\n--\nb"
  1255. (org-test-with-temp-text "- a\n - b"
  1256. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1257. (should
  1258. (equal
  1259. "a\n- 1 -\nb"
  1260. (org-test-with-temp-text "- a\n- b"
  1261. (org-list-to-generic
  1262. (org-list-to-lisp)
  1263. '(:isep (lambda (type depth) (format "- %d -" depth)))))))
  1264. ;; Test `:ifmt' parameter.
  1265. (should
  1266. (equal
  1267. ">> a <<"
  1268. (org-test-with-temp-text "1. [@3] a"
  1269. (org-list-to-generic
  1270. (org-list-to-lisp)
  1271. '(:ifmt (lambda (type c) (format ">> %s <<" c)))))))
  1272. ;; Test `:cbon', `:cboff', `:cbtrans'
  1273. (should
  1274. (equal
  1275. "!a"
  1276. (org-test-with-temp-text "- [X] a"
  1277. (org-list-to-generic (org-list-to-lisp) '(:cbon "!")))))
  1278. (should-not
  1279. (equal
  1280. "!a"
  1281. (org-test-with-temp-text "- [X] a"
  1282. (org-list-to-generic (org-list-to-lisp) '(:cboff "!" :cbtrans "!")))))
  1283. (should
  1284. (equal
  1285. "!a"
  1286. (org-test-with-temp-text "- [ ] a"
  1287. (org-list-to-generic (org-list-to-lisp) '(:cboff "!")))))
  1288. (should-not
  1289. (equal
  1290. "!a"
  1291. (org-test-with-temp-text "- [ ] a"
  1292. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cbtrans "!")))))
  1293. (should
  1294. (equal
  1295. "!a"
  1296. (org-test-with-temp-text "- [-] a"
  1297. (org-list-to-generic (org-list-to-lisp) '(:cbtrans "!")))))
  1298. (should-not
  1299. (equal
  1300. "!a"
  1301. (org-test-with-temp-text "- [-] a"
  1302. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cboff "!")))))
  1303. ;; Test `:splice' parameter.
  1304. (should
  1305. (equal
  1306. "a"
  1307. (org-test-with-temp-text "- a"
  1308. (org-list-to-generic (org-list-to-lisp)
  1309. '(:ustart "begin" :uend "end" :splice t)))))
  1310. ;; No error on empty lists.
  1311. (should
  1312. (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil))))
  1313. (ert-deftest test-org-list/to-html ()
  1314. "Test `org-list-to-html' specifications."
  1315. (should
  1316. (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
  1317. (org-test-with-temp-text "- a"
  1318. (org-list-to-html (org-list-to-lisp) nil)))))
  1319. (ert-deftest test-org-list/to-latex ()
  1320. "Test `org-list-to-latex' specifications."
  1321. (should
  1322. (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
  1323. (org-test-with-temp-text "- a"
  1324. (org-list-to-latex (org-list-to-lisp) nil)))))
  1325. (ert-deftest test-org-list/to-texinfo ()
  1326. "Test `org-list-to-texinfo' specifications."
  1327. (should
  1328. (equal "@itemize\n@item\na\n@end itemize"
  1329. (org-test-with-temp-text "- a"
  1330. (org-list-to-texinfo (org-list-to-lisp) nil)))))
  1331. (ert-deftest test-org-list/to-org ()
  1332. "Test `org-list-to-org' specifications."
  1333. ;; Un-ordered list.
  1334. (should
  1335. (equal "- a"
  1336. (org-test-with-temp-text "- a"
  1337. (org-list-to-org (org-list-to-lisp) nil))))
  1338. ;; Ordered list.
  1339. (should
  1340. (equal "1. a"
  1341. (org-test-with-temp-text "1. a"
  1342. (org-list-to-org (org-list-to-lisp) nil))))
  1343. ;; Descriptive list.
  1344. (should
  1345. (equal "- a :: b"
  1346. (org-test-with-temp-text "- a :: b"
  1347. (org-list-to-org (org-list-to-lisp) nil))))
  1348. ;; Nested list.
  1349. (should
  1350. (equal "- a\n - b"
  1351. (org-test-with-temp-text "- a\n - b"
  1352. (org-list-to-org (org-list-to-lisp) nil))))
  1353. ;; Item spanning over multiple lines.
  1354. (should
  1355. (equal "- a\n b"
  1356. (org-test-with-temp-text "- a\n b"
  1357. (org-list-to-org (org-list-to-lisp) nil))))
  1358. ;; Item with continuation text after a sub-list.
  1359. (should
  1360. (equal "- a\n - b\n c"
  1361. (org-test-with-temp-text "- a\n - b\n c"
  1362. (org-list-to-org (org-list-to-lisp) nil)))))
  1363. (provide 'test-org-list)
  1364. ;;; test-org-list.el ends here