test-org-list.el 42 KB

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