test-org-list.el 40 KB

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