test-org-list.el 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457
  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. ;; 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 a region is marked and first line is a headline, all
  917. ;; headlines are turned into items.
  918. (should
  919. (equal "- H1\n - H2"
  920. (org-test-with-temp-text "* H1\n** H2"
  921. (transient-mark-mode 1)
  922. (push-mark (point) t t)
  923. (goto-char (point-max))
  924. (org-toggle-item nil)
  925. (buffer-string))))
  926. (should
  927. (equal "- [ ] H1\n - [ ] H2"
  928. (org-test-with-temp-text "* TODO H1\n** TODO H2"
  929. (transient-mark-mode 1)
  930. (push-mark (point) t t)
  931. (goto-char (point-max))
  932. (org-toggle-item nil)
  933. (buffer-string))))
  934. ;; When turning headlines into items, make sure headings contents
  935. ;; are kept within items.
  936. (should
  937. (equal "- H1\n Text"
  938. (org-test-with-temp-text "* H1\nText"
  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. ;; When a region is marked and first line is an item, all items are
  945. ;; turned into normal lines.
  946. (should
  947. (equal "1\n 2"
  948. (org-test-with-temp-text "- 1\n - 2"
  949. (transient-mark-mode 1)
  950. (push-mark (point) t t)
  951. (goto-char (point-max))
  952. (org-toggle-item nil)
  953. (buffer-string))))
  954. (should
  955. (equal "1\n2"
  956. (org-test-with-temp-text "- 1\n2"
  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 normal
  963. ;; lines are turned into items.
  964. (should
  965. (equal "- line 1\n- line 2"
  966. (org-test-with-temp-text "line 1\nline 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 "- line 1\n- line 2"
  974. (org-test-with-temp-text "line 1\n- line 2"
  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 argument ARG is non-nil, change the whole region into
  981. ;; a single item.
  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 t)
  989. (buffer-string)))))
  990. (ert-deftest test-org-list/sort ()
  991. "Test `org-sort-list'."
  992. ;; Sort alphabetically.
  993. (should
  994. (equal "- abc\n- def\n- xyz\n"
  995. (org-test-with-temp-text "- def\n- xyz\n- abc\n"
  996. (org-sort-list nil ?a)
  997. (buffer-string))))
  998. (should
  999. (equal "- xyz\n- def\n- abc\n"
  1000. (org-test-with-temp-text "- def\n- xyz\n- abc\n"
  1001. (org-sort-list nil ?A)
  1002. (buffer-string))))
  1003. ;; Sort numerically.
  1004. (should
  1005. (equal "- 1\n- 2\n- 10\n"
  1006. (org-test-with-temp-text "- 10\n- 1\n- 2\n"
  1007. (org-sort-list nil ?n)
  1008. (buffer-string))))
  1009. (should
  1010. (equal "- 10\n- 2\n- 1\n"
  1011. (org-test-with-temp-text "- 10\n- 1\n- 2\n"
  1012. (org-sort-list nil ?N)
  1013. (buffer-string))))
  1014. ;; Sort by checked status.
  1015. (should
  1016. (equal "- [ ] xyz\n- [ ] def\n- [X] abc\n"
  1017. (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1018. (org-sort-list nil ?x)
  1019. (buffer-string))))
  1020. (should
  1021. (equal "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1022. (org-test-with-temp-text "- [X] abc\n- [ ] xyz\n- [ ] def\n"
  1023. (org-sort-list nil ?X)
  1024. (buffer-string))))
  1025. ;; Sort by time stamp.
  1026. (should
  1027. (equal "- <2017-05-08 Mon>\n- <2017-05-09 Tue>\n- <2018-05-09 Wed>\n"
  1028. (org-test-with-temp-text
  1029. "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1030. (org-sort-list nil ?t)
  1031. (buffer-string))))
  1032. (should
  1033. (equal "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1034. (org-test-with-temp-text
  1035. "- <2018-05-09 Wed>\n- <2017-05-09 Tue>\n- <2017-05-08 Mon>\n"
  1036. (org-sort-list nil ?T)
  1037. (buffer-string))))
  1038. ;; Sort by custom function.
  1039. (should
  1040. (equal "- b\n- aa\n- ccc\n"
  1041. (org-test-with-temp-text "- ccc\n- b\n- aa\n"
  1042. (org-sort-list nil ?f
  1043. (lambda ()
  1044. (length (buffer-substring (point-at-bol)
  1045. (point-at-eol))))
  1046. #'<)
  1047. (buffer-string))))
  1048. (should
  1049. (equal "- ccc\n- aa\n- b\n"
  1050. (org-test-with-temp-text "- ccc\n- b\n- aa\n"
  1051. (org-sort-list nil ?F
  1052. (lambda ()
  1053. (length (buffer-substring (point-at-bol)
  1054. (point-at-eol))))
  1055. #'<)
  1056. (buffer-string)))))
  1057. ;;; Radio Lists
  1058. (ert-deftest test-org-list/send-list ()
  1059. "Test various checks for `org-list-send-list'."
  1060. ;; Error when not at a list item.
  1061. (should-error
  1062. (org-test-with-temp-text "Not a list item"
  1063. (org-list-send-list)))
  1064. ;; Error when ORGLST line is not provided.
  1065. (should-error
  1066. (org-test-with-temp-text "- item"
  1067. (org-list-send-list)))
  1068. ;; Error when transformation function is unknown.
  1069. (should-error
  1070. (org-test-with-temp-text "@ignore
  1071. #+ORGLST: SEND list unknown-function
  1072. - item
  1073. @end ignore"
  1074. (forward-line 2)
  1075. (org-list-send-list)))
  1076. ;; Error when receiving location is not defined.
  1077. (should-error
  1078. (org-test-with-temp-text "@ignore
  1079. #+ORGLST: SEND list org-list-to-texinfo
  1080. - item
  1081. @end ignore"
  1082. (forward-line 2)
  1083. (org-list-send-list)))
  1084. ;; Error when insertion region is ill-formed.
  1085. (should-error
  1086. (org-test-with-temp-text "@c BEGIN RECEIVE ORGLST list
  1087. @ignore
  1088. #+ORGLST: SEND list org-list-to-texinfo
  1089. - item
  1090. @end ignore"
  1091. (forward-line 3)
  1092. (org-list-send-list)))
  1093. ;; Allow multiple receiver locations.
  1094. (should
  1095. (org-test-with-temp-text "
  1096. @c BEGIN RECEIVE ORGLST list
  1097. @c END RECEIVE ORGLST list
  1098. @ignore
  1099. #+ORGLST: SEND list org-list-to-texinfo
  1100. <point>- item contents
  1101. @end ignore
  1102. @c BEGIN RECEIVE ORGLST list
  1103. @c END RECEIVE ORGLST list"
  1104. (org-list-send-list)
  1105. (goto-char (point-min))
  1106. (search-forward "item contents" nil t 3))))
  1107. (ert-deftest test-org-list/to-generic ()
  1108. "Test `org-list-to-generic' specifications."
  1109. ;; Test `:ustart' and `:uend' parameters.
  1110. (should
  1111. (equal
  1112. "begin\na"
  1113. (org-test-with-temp-text "- a"
  1114. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1115. (should-not
  1116. (equal
  1117. "begin\na"
  1118. (org-test-with-temp-text "1. a"
  1119. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1120. (should
  1121. (equal
  1122. "a\nend"
  1123. (org-test-with-temp-text "- a"
  1124. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1125. (should-not
  1126. (equal
  1127. "a\nend"
  1128. (org-test-with-temp-text "1. a"
  1129. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1130. (should
  1131. (equal
  1132. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1133. (org-test-with-temp-text "- a\n - b"
  1134. (org-list-to-generic
  1135. (org-list-to-lisp)
  1136. (list :ustart (lambda (l) (format "begin l%d" l))
  1137. :uend (lambda (l) (format "end l%d" l)))))))
  1138. ;; Test `:ostart' and `:oend' parameters.
  1139. (should
  1140. (equal
  1141. "begin\na"
  1142. (org-test-with-temp-text "1. a"
  1143. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1144. (should-not
  1145. (equal
  1146. "begin\na"
  1147. (org-test-with-temp-text "- a"
  1148. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1149. (should
  1150. (equal
  1151. "a\nend"
  1152. (org-test-with-temp-text "1. a"
  1153. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1154. (should-not
  1155. (equal
  1156. "a\nend"
  1157. (org-test-with-temp-text "- a"
  1158. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1159. (should
  1160. (equal
  1161. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1162. (org-test-with-temp-text "1. a\n 1. b"
  1163. (org-list-to-generic
  1164. (org-list-to-lisp)
  1165. (list :ostart (lambda (l) (format "begin l%d" l))
  1166. :oend (lambda (l) (format "end l%d" l)))))))
  1167. ;; Test `:dstart' and `:dend' parameters.
  1168. (should
  1169. (equal
  1170. "begin\ntaga"
  1171. (org-test-with-temp-text "- tag :: a"
  1172. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1173. (should-not
  1174. (equal
  1175. "begin\na"
  1176. (org-test-with-temp-text "- a"
  1177. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1178. (should
  1179. (equal
  1180. "taga\nend"
  1181. (org-test-with-temp-text "- tag :: a"
  1182. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1183. (should-not
  1184. (equal
  1185. "a\nend"
  1186. (org-test-with-temp-text "- a"
  1187. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1188. (should
  1189. (equal
  1190. "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
  1191. (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
  1192. (org-list-to-generic
  1193. (org-list-to-lisp)
  1194. (list :dstart (lambda (l) (format "begin l%d" l))
  1195. :dend (lambda (l) (format "end l%d" l)))))))
  1196. ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
  1197. (should
  1198. (equal
  1199. ">tag<a"
  1200. (org-test-with-temp-text "- tag :: a"
  1201. (org-list-to-generic (org-list-to-lisp) '(:dtstart ">" :dtend "<")))))
  1202. (should
  1203. (equal
  1204. "tag>a<"
  1205. (org-test-with-temp-text "- tag :: a"
  1206. (org-list-to-generic (org-list-to-lisp) '(:ddstart ">" :ddend "<")))))
  1207. ;; Test `:istart' and `:iend' parameters.
  1208. (should
  1209. (equal
  1210. "starta"
  1211. (org-test-with-temp-text "- a"
  1212. (org-list-to-generic (org-list-to-lisp) '(:istart "start")))))
  1213. (should
  1214. (equal
  1215. "level1 a\nlevel2 b"
  1216. (org-test-with-temp-text "- a\n - b"
  1217. (org-list-to-generic (org-list-to-lisp)
  1218. '(:istart (lambda (type l) (format "level%d "l)))))))
  1219. (should
  1220. (equal
  1221. "a\nblevel2level1"
  1222. (org-test-with-temp-text "- a\n - b"
  1223. (org-list-to-generic (org-list-to-lisp)
  1224. '(:iend (lambda (type l) (format "level%d" l)))))))
  1225. ;; Test `:icount' parameter.
  1226. (should
  1227. (equal
  1228. "counta"
  1229. (org-test-with-temp-text "1. [@3] a"
  1230. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1231. (should-not
  1232. (equal
  1233. "counta"
  1234. (org-test-with-temp-text "1. a"
  1235. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1236. (should
  1237. (equal
  1238. "counta"
  1239. (org-test-with-temp-text "1. [@3] a"
  1240. (org-list-to-generic (org-list-to-lisp)
  1241. '(:icount "count" :istart "start")))))
  1242. (should
  1243. (equal
  1244. "level:1, counter:3 a"
  1245. (org-test-with-temp-text "1. [@3] a"
  1246. (org-list-to-generic
  1247. (org-list-to-lisp)
  1248. '(:icount (lambda (type l c) (format "level:%d, counter:%d " l c)))))))
  1249. ;; Test `:isep' parameter.
  1250. (should
  1251. (equal
  1252. "a\n--\nb"
  1253. (org-test-with-temp-text "- a\n- b"
  1254. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1255. (should-not
  1256. (equal
  1257. "a\n--\nb"
  1258. (org-test-with-temp-text "- a\n - b"
  1259. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1260. (should
  1261. (equal
  1262. "a\n- 1 -\nb"
  1263. (org-test-with-temp-text "- a\n- b"
  1264. (org-list-to-generic
  1265. (org-list-to-lisp)
  1266. '(:isep (lambda (type depth) (format "- %d -" depth)))))))
  1267. ;; Test `:ifmt' parameter.
  1268. (should
  1269. (equal
  1270. ">> a <<"
  1271. (org-test-with-temp-text "1. [@3] a"
  1272. (org-list-to-generic
  1273. (org-list-to-lisp)
  1274. '(:ifmt (lambda (type c) (format ">> %s <<" c)))))))
  1275. ;; Test `:cbon', `:cboff', `:cbtrans'
  1276. (should
  1277. (equal
  1278. "!a"
  1279. (org-test-with-temp-text "- [X] a"
  1280. (org-list-to-generic (org-list-to-lisp) '(:cbon "!")))))
  1281. (should-not
  1282. (equal
  1283. "!a"
  1284. (org-test-with-temp-text "- [X] a"
  1285. (org-list-to-generic (org-list-to-lisp) '(:cboff "!" :cbtrans "!")))))
  1286. (should
  1287. (equal
  1288. "!a"
  1289. (org-test-with-temp-text "- [ ] a"
  1290. (org-list-to-generic (org-list-to-lisp) '(:cboff "!")))))
  1291. (should-not
  1292. (equal
  1293. "!a"
  1294. (org-test-with-temp-text "- [ ] a"
  1295. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cbtrans "!")))))
  1296. (should
  1297. (equal
  1298. "!a"
  1299. (org-test-with-temp-text "- [-] a"
  1300. (org-list-to-generic (org-list-to-lisp) '(:cbtrans "!")))))
  1301. (should-not
  1302. (equal
  1303. "!a"
  1304. (org-test-with-temp-text "- [-] a"
  1305. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cboff "!")))))
  1306. ;; Test `:splice' parameter.
  1307. (should
  1308. (equal
  1309. "a"
  1310. (org-test-with-temp-text "- a"
  1311. (org-list-to-generic (org-list-to-lisp)
  1312. '(:ustart "begin" :uend "end" :splice t)))))
  1313. ;; No error on empty lists.
  1314. (should
  1315. (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil))))
  1316. (ert-deftest test-org-list/to-html ()
  1317. "Test `org-list-to-html' specifications."
  1318. (should
  1319. (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
  1320. (let (org-html-indent)
  1321. (with-temp-buffer
  1322. (insert "<!-- BEGIN RECEIVE ORGLST name -->
  1323. <!-- END RECEIVE ORGLST name -->
  1324. <!--
  1325. #+ORGLST: SEND name org-list-to-html
  1326. - a
  1327. -->")
  1328. (goto-char (point-min))
  1329. (re-search-forward "^- a" nil t)
  1330. (beginning-of-line)
  1331. (org-list-send-list)
  1332. (goto-line 2)
  1333. (buffer-substring-no-properties
  1334. (point)
  1335. (progn (re-search-forward "^<!-- END" nil t)
  1336. (beginning-of-line)
  1337. (skip-chars-backward " \r\t\n")
  1338. (point))))))))
  1339. (ert-deftest test-org-list/to-latex ()
  1340. "Test `org-list-to-latex' specifications."
  1341. (should
  1342. (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
  1343. (with-temp-buffer
  1344. (insert "% BEGIN RECEIVE ORGLST name
  1345. % END RECEIVE ORGLST name
  1346. \\begin{comment}
  1347. #+ORGLST: SEND name org-list-to-latex
  1348. - a
  1349. \\end{comment}")
  1350. (goto-char (point-min))
  1351. (re-search-forward "^- a" nil t)
  1352. (beginning-of-line)
  1353. (org-list-send-list)
  1354. (goto-line 2)
  1355. (buffer-substring-no-properties
  1356. (point)
  1357. (progn (re-search-forward "^% END" nil t)
  1358. (beginning-of-line)
  1359. (skip-chars-backward " \r\t\n")
  1360. (point)))))))
  1361. (ert-deftest test-org-list/to-texinfo ()
  1362. "Test `org-list-to-texinfo' specifications."
  1363. (should
  1364. (equal "@itemize\n@item\na\n@end itemize"
  1365. (with-temp-buffer
  1366. (insert "@c BEGIN RECEIVE ORGLST name
  1367. @c END RECEIVE ORGLST name
  1368. @ignore
  1369. #+ORGLST: SEND name org-list-to-texinfo
  1370. - a
  1371. @end ignore")
  1372. (goto-char (point-min))
  1373. (re-search-forward "^- a" nil t)
  1374. (beginning-of-line)
  1375. (org-list-send-list)
  1376. (goto-line 2)
  1377. (buffer-substring-no-properties
  1378. (point)
  1379. (progn (re-search-forward "^@c END" nil t)
  1380. (beginning-of-line)
  1381. (skip-chars-backward " \r\t\n")
  1382. (point)))))))
  1383. (ert-deftest test-org-list/to-org ()
  1384. "Test `org-list-to-org' specifications."
  1385. ;; Un-ordered list.
  1386. (should
  1387. (equal "- a"
  1388. (org-test-with-temp-text "- a"
  1389. (org-list-to-org (org-list-to-lisp) nil))))
  1390. ;; Ordered list.
  1391. (should
  1392. (equal "1. a"
  1393. (org-test-with-temp-text "1. a"
  1394. (org-list-to-org (org-list-to-lisp) nil))))
  1395. ;; Descriptive list.
  1396. (should
  1397. (equal "- a :: b"
  1398. (org-test-with-temp-text "- a :: b"
  1399. (org-list-to-org (org-list-to-lisp) nil))))
  1400. ;; Nested list.
  1401. (should
  1402. (equal "- a\n - b"
  1403. (org-test-with-temp-text "- a\n - b"
  1404. (org-list-to-org (org-list-to-lisp) nil))))
  1405. ;; Item spanning over multiple lines.
  1406. (should
  1407. (equal "- a\n b"
  1408. (org-test-with-temp-text "- a\n b"
  1409. (org-list-to-org (org-list-to-lisp) nil))))
  1410. ;; Item with continuation text after a sub-list.
  1411. (should
  1412. (equal "- a\n - b\n c"
  1413. (org-test-with-temp-text "- a\n - b\n c"
  1414. (org-list-to-org (org-list-to-lisp) nil)))))
  1415. (provide 'test-org-list)
  1416. ;;; test-org-list.el ends here