test-org-list.el 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310
  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. ;; Preserve contents visibility.
  515. (org-test-with-temp-text "
  516. - item 1
  517. #+BEGIN_CENTER
  518. Text1
  519. #+END_CENTER
  520. - item 2
  521. #+BEGIN_CENTER
  522. Text2
  523. #+END_CENTER"
  524. (org-hide-block-all)
  525. (search-forward "- item 1")
  526. (org-move-item-down)
  527. (search-forward "Text1")
  528. (should (org-invisible-p2))
  529. (search-backward "Text2")
  530. (should (org-invisible-p2))))
  531. (ert-deftest test-org-list/move-item-up ()
  532. "Test `org-move-item-up' specifications."
  533. ;; Standard test.
  534. (org-test-with-temp-text "- item 1\n- item 2"
  535. (forward-line)
  536. (org-move-item-up)
  537. (should (equal (buffer-string)
  538. "- item 2\n- item 1")))
  539. ;; Keep same column in item.
  540. (org-test-with-temp-text "- item 1\n- item 2"
  541. (forward-line)
  542. (forward-char 4)
  543. (org-move-item-up)
  544. (should (looking-at "em 2")))
  545. ;; Move sub-items.
  546. (org-test-with-temp-text "- item 1\n- item 2\n - sub-item 2"
  547. (forward-line)
  548. (org-move-item-up)
  549. (should (equal (buffer-string)
  550. "- item 2\n - sub-item 2\n- item 1")))
  551. ;; Preserve blank lines.
  552. (should
  553. (equal
  554. "- item 2\n\n- item 1"
  555. (org-test-with-temp-text "- item 1\n\n- item 2"
  556. (search-forward "- item 2")
  557. (org-move-item-up)
  558. (buffer-string))))
  559. ;; Error when trying to move the first item...
  560. (org-test-with-temp-text "- item 1\n- item 2"
  561. (should-error (org-move-item-up)))
  562. ;; ... unless `org-list-use-circular-motion' is non-nil. In this
  563. ;; case, move to the first item.
  564. (org-test-with-temp-text "- item 1\n- item 2\n- item 3"
  565. (let ((org-list-use-circular-motion t)) (org-move-item-up))
  566. (should (equal (buffer-string) "- item 2\n- item 3\n- item 1")))
  567. ;; Preserve item visibility.
  568. (org-test-with-temp-text "* Headline\n- item 1\n body 1\n- item 2\n body 2"
  569. (let ((org-cycle-include-plain-lists t))
  570. (search-forward "- item 1")
  571. (org-cycle)
  572. (search-forward "- item 2")
  573. (org-cycle))
  574. (org-move-item-up)
  575. (forward-line)
  576. (should (org-invisible-p2))
  577. (search-forward " body 1")
  578. (should (org-invisible-p2)))
  579. ;; Preserve children visibility.
  580. (org-test-with-temp-text "* Headline
  581. - item 1
  582. - sub-item 1
  583. sub-body 1
  584. - item 2
  585. - sub-item 2
  586. sub-body 2"
  587. (let ((org-cycle-include-plain-lists t))
  588. (search-forward "- sub-item 1")
  589. (org-cycle)
  590. (search-forward "- sub-item 2")
  591. (org-cycle))
  592. (search-backward "- item 2")
  593. (org-move-item-up)
  594. (search-forward "sub-body 2")
  595. (should (org-invisible-p2))
  596. (search-forward "sub-body 1")
  597. (should (org-invisible-p2)))
  598. ;; Preserve contents visibility.
  599. (org-test-with-temp-text "
  600. - item 1
  601. #+BEGIN_CENTER
  602. Text1
  603. #+END_CENTER
  604. - item 2
  605. #+BEGIN_CENTER
  606. Text2
  607. #+END_CENTER"
  608. (org-hide-block-all)
  609. (search-forward "- item 2")
  610. (org-move-item-up)
  611. (search-forward "Text2")
  612. (should (org-invisible-p2))
  613. (search-forward "Text1")
  614. (should (org-invisible-p2))))
  615. (ert-deftest test-org-list/insert-item ()
  616. "Test item insertion."
  617. ;; Blank lines specifications.
  618. ;;
  619. ;; Non-nil `org-blank-before-new-entry': insert a blank line.
  620. (should
  621. (org-test-with-temp-text "- a"
  622. (let ((org-blank-before-new-entry '((plain-list-item . t))))
  623. (end-of-line)
  624. (org-insert-item)
  625. (forward-line -1)
  626. (looking-at "$"))))
  627. ;; Nil `org-blank-before-new-entry': do not insert a blank line.
  628. (should-not
  629. (org-test-with-temp-text "- a"
  630. (let ((org-blank-before-new-entry '((plain-list-item . nil))))
  631. (end-of-line)
  632. (org-insert-item)
  633. (forward-line -1)
  634. (looking-at "$"))))
  635. ;; `org-blank-before-new-entry' set to auto: if there's no blank
  636. ;; line already in the sole item, do not insert one.
  637. (should-not
  638. (org-test-with-temp-text "- a"
  639. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  640. (end-of-line)
  641. (org-insert-item)
  642. (forward-line -1)
  643. (looking-at "$"))))
  644. ;; `org-blank-before-new-entry' set to `auto': if there's a blank
  645. ;; line in the sole item, insert another one.
  646. (should
  647. (org-test-with-temp-text "- a\n\n b<point>"
  648. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  649. (org-insert-item)
  650. (forward-line -1)
  651. (looking-at "$"))))
  652. ;; `org-blank-before-new-entry' set to `auto': if the user specified
  653. ;; a blank line, preserve it.
  654. (should
  655. (org-test-with-temp-text "- a\n\n<point>"
  656. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  657. (org-insert-item)
  658. (forward-line -1)
  659. (looking-at "$"))))
  660. ;; `org-blank-before-new-entry' set to `auto': if some items in list
  661. ;; are already separated by blank lines, insert one.
  662. (should
  663. (org-test-with-temp-text "- a\n\n- b<point>"
  664. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  665. (org-insert-item)
  666. (forward-line -1)
  667. (looking-at "$"))))
  668. (should
  669. (org-test-with-temp-text "- a\n\n- b"
  670. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  671. (org-insert-item)
  672. (forward-line)
  673. (looking-at "$"))))
  674. (should
  675. (org-test-with-temp-text
  676. "- a\n #+BEGIN_EXAMPLE\n\n x\n #+END_EXAMPLE<point>"
  677. (let ((org-blank-before-new-entry '((plain-list-item . auto))))
  678. (org-insert-item)
  679. (forward-line -1)
  680. (looking-at "$"))))
  681. ;; When called before or on the bullet, insert new item before
  682. ;; current one.
  683. (should
  684. (equal "- \n- item"
  685. (org-test-with-temp-text "- item"
  686. (org-insert-item)
  687. (buffer-string))))
  688. (should
  689. (equal "- \n- item"
  690. (org-test-with-temp-text "- <point>item"
  691. (org-insert-item)
  692. (buffer-string))))
  693. ;; When called on tag in a descriptive list, insert new item before
  694. ;; current one too.
  695. (should
  696. (equal "- :: \n- tag :: item"
  697. (org-test-with-temp-text "- tag <point>:: item"
  698. (org-insert-item)
  699. (buffer-string))))
  700. (should
  701. (equal "- :: \n- tag :: item"
  702. (org-test-with-temp-text "- ta<point>g :: item"
  703. (org-insert-item)
  704. (buffer-string))))
  705. ;; Further, it splits the line or add a blank new item after it,
  706. ;; according to `org-M-RET-may-split-line'.
  707. (should
  708. (equal "- it\n- em"
  709. (org-test-with-temp-text "- it<point>em"
  710. (let ((org-M-RET-may-split-line '((default . t))))
  711. (org-insert-item))
  712. (buffer-string))))
  713. (should
  714. (equal "- item\n- "
  715. (org-test-with-temp-text "- it<point>em"
  716. (let ((org-M-RET-may-split-line '((default . nil))))
  717. (org-insert-item))
  718. (buffer-string)))))
  719. (ert-deftest test-org-list/repair ()
  720. "Test `org-list-repair' specifications."
  721. ;; Repair indentation.
  722. (should
  723. (equal "- item\n - child"
  724. (org-test-with-temp-text "- item\n - child"
  725. (let ((org-list-indent-offset 0)) (org-list-repair))
  726. (buffer-string))))
  727. ;; Repair bullets and numbering.
  728. (should
  729. (equal "- a\n- b"
  730. (org-test-with-temp-text "- a\n+ b"
  731. (let ((org-list-indent-offset 0))
  732. (org-list-repair))
  733. (buffer-string))))
  734. (should
  735. (equal "1. a\n2. b"
  736. (org-test-with-temp-text "1. a\n1. b"
  737. (let ((org-list-indent-offset 0)
  738. (org-plain-list-ordered-item-terminator t))
  739. (org-list-repair))
  740. (buffer-string))))
  741. ;; Repair check-boxes.
  742. (should
  743. (equal "- [X] item\n - [X] child"
  744. (org-test-with-temp-text "- [ ] item\n - [X] child"
  745. (let ((org-list-indent-offset 0))
  746. (org-list-repair))
  747. (buffer-string))))
  748. ;; Special case: do not move contents of an item within its child.
  749. ;; Yet, preserve indentation differences within contents.
  750. (should
  751. (equal "- item\n - child\n within item"
  752. (org-test-with-temp-text "- item\n - child\n within item"
  753. (let ((org-list-indent-offset 0)) (org-list-repair))
  754. (buffer-string))))
  755. (should
  756. (equal
  757. "- item\n - child\n within item\n indented"
  758. (org-test-with-temp-text
  759. "- item\n - child\n within item\n indented"
  760. (let ((org-list-indent-offset 0)) (org-list-repair))
  761. (buffer-string)))))
  762. (ert-deftest test-org-list/update-checkbox-count ()
  763. "Test `org-update-checkbox-count' specifications."
  764. ;; From a headline.
  765. (should
  766. (string-match "\\[0/1\\]"
  767. (org-test-with-temp-text "* [/]\n- [ ] item"
  768. (org-update-checkbox-count)
  769. (buffer-string))))
  770. (should
  771. (string-match "\\[1/1\\]"
  772. (org-test-with-temp-text "* [/]\n- [X] item"
  773. (org-update-checkbox-count)
  774. (buffer-string))))
  775. (should
  776. (string-match "\\[100%\\]"
  777. (org-test-with-temp-text "* [%]\n- [X] item"
  778. (org-update-checkbox-count)
  779. (buffer-string))))
  780. ;; From a list or a sub-list.
  781. (should
  782. (string-match "\\[0/1\\]"
  783. (org-test-with-temp-text "- [/]\n - [ ] item"
  784. (org-update-checkbox-count)
  785. (buffer-string))))
  786. (should
  787. (string-match "\\[1/1\\]"
  788. (org-test-with-temp-text "- [/]\n - [X] item"
  789. (org-update-checkbox-count)
  790. (buffer-string))))
  791. (should
  792. (string-match "\\[100%\\]"
  793. (org-test-with-temp-text "- [%]\n - [X] item"
  794. (org-update-checkbox-count)
  795. (buffer-string))))
  796. (should
  797. (string-match
  798. "\\[1/1\\]"
  799. (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
  800. (org-update-checkbox-count)
  801. (buffer-string))))
  802. ;; Count do not apply to sub-lists unless count is not hierarchical.
  803. ;; This state can be achieved with COOKIE_DATA node property set to
  804. ;; "recursive".
  805. (should
  806. (string-match "\\[1/1\\]"
  807. (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
  808. (let ((org-checkbox-hierarchical-statistics nil))
  809. (org-update-checkbox-count))
  810. (buffer-string))))
  811. (should
  812. (string-match "\\[1/1\\]"
  813. (org-test-with-temp-text "
  814. <point>* H
  815. :PROPERTIES:
  816. :COOKIE_DATA: recursive
  817. :END:
  818. - [/]
  819. - item
  820. - [X] sub-item"
  821. (org-update-checkbox-count)
  822. (buffer-string))))
  823. (should
  824. (string-match "\\[0/0\\]"
  825. (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
  826. (org-update-checkbox-count)
  827. (buffer-string))))
  828. ;; With optional argument ALL, update all buffer.
  829. (should
  830. (= 2
  831. (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
  832. (org-update-checkbox-count t)
  833. (count-matches "\\[1/1\\]"))))
  834. ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
  835. ;; outside.
  836. (should
  837. (string-match "\\[2/2\\]"
  838. (org-test-with-temp-text "
  839. - [/]
  840. - [X] item1
  841. :DRAWER:
  842. - [X] item
  843. :END:
  844. - [X] item2"
  845. (let ((org-checkbox-hierarchical-statistics nil))
  846. (org-update-checkbox-count))
  847. (buffer-string)))))
  848. ;;; Miscellaneous
  849. (ert-deftest test-org-list/toggle-item ()
  850. "Test `org-toggle-item' specifications."
  851. ;; Convert normal lines to items.
  852. (should
  853. (equal "- line"
  854. (org-test-with-temp-text "line"
  855. (org-toggle-item nil)
  856. (buffer-string))))
  857. ;; Convert items to normal lines.
  858. (should
  859. (equal "line"
  860. (org-test-with-temp-text "- line"
  861. (org-toggle-item nil)
  862. (buffer-string))))
  863. ;; Convert headlines to items.
  864. (should
  865. (equal "- line"
  866. (org-test-with-temp-text "* line"
  867. (org-toggle-item nil)
  868. (buffer-string))))
  869. ;; When converting a headline to a list item, TODO keywords become
  870. ;; checkboxes.
  871. (should
  872. (equal "- [X] line"
  873. (org-test-with-temp-text "* DONE line"
  874. (org-toggle-item nil)
  875. (buffer-string))))
  876. (should
  877. (equal "- [ ] line"
  878. (org-test-with-temp-text "* TODO line"
  879. (org-toggle-item nil)
  880. (buffer-string))))
  881. ;; When a region is marked and first line is a headline, all
  882. ;; headlines are turned into items.
  883. (should
  884. (equal "- H1\n - H2"
  885. (org-test-with-temp-text "* H1\n** H2"
  886. (transient-mark-mode 1)
  887. (push-mark (point) t t)
  888. (goto-char (point-max))
  889. (org-toggle-item nil)
  890. (buffer-string))))
  891. (should
  892. (equal "- [ ] H1\n - [ ] H2"
  893. (org-test-with-temp-text "* TODO H1\n** TODO H2"
  894. (transient-mark-mode 1)
  895. (push-mark (point) t t)
  896. (goto-char (point-max))
  897. (org-toggle-item nil)
  898. (buffer-string))))
  899. ;; When turning headlines into items, make sure headings contents
  900. ;; are kept within items.
  901. (should
  902. (equal "- H1\n Text"
  903. (org-test-with-temp-text "* H1\nText"
  904. (transient-mark-mode 1)
  905. (push-mark (point) t t)
  906. (goto-char (point-max))
  907. (org-toggle-item nil)
  908. (buffer-string))))
  909. ;; When a region is marked and first line is an item, all items are
  910. ;; turned into normal lines.
  911. (should
  912. (equal "1\n 2"
  913. (org-test-with-temp-text "- 1\n - 2"
  914. (transient-mark-mode 1)
  915. (push-mark (point) t t)
  916. (goto-char (point-max))
  917. (org-toggle-item nil)
  918. (buffer-string))))
  919. (should
  920. (equal "1\n2"
  921. (org-test-with-temp-text "- 1\n2"
  922. (transient-mark-mode 1)
  923. (push-mark (point) t t)
  924. (goto-char (point-max))
  925. (org-toggle-item nil)
  926. (buffer-string))))
  927. ;; When a region is marked and first line is an item, all normal
  928. ;; lines are turned into items.
  929. (should
  930. (equal "- line 1\n- line 2"
  931. (org-test-with-temp-text "line 1\nline 2"
  932. (transient-mark-mode 1)
  933. (push-mark (point) t t)
  934. (goto-char (point-max))
  935. (org-toggle-item nil)
  936. (buffer-string))))
  937. (should
  938. (equal "- line 1\n- line 2"
  939. (org-test-with-temp-text "line 1\n- line 2"
  940. (transient-mark-mode 1)
  941. (push-mark (point) t t)
  942. (goto-char (point-max))
  943. (org-toggle-item nil)
  944. (buffer-string))))
  945. ;; When argument ARG is non-nil, change the whole region into
  946. ;; a single item.
  947. (should
  948. (equal "- line 1\n line 2"
  949. (org-test-with-temp-text "line 1\nline 2"
  950. (transient-mark-mode 1)
  951. (push-mark (point) t t)
  952. (goto-char (point-max))
  953. (org-toggle-item t)
  954. (buffer-string)))))
  955. ;;; Radio Lists
  956. (ert-deftest test-org-list/send-list ()
  957. "Test various checks for `org-list-send-list'."
  958. ;; Error when not at a list item.
  959. (should-error
  960. (org-test-with-temp-text "Not a list item"
  961. (org-list-send-list)))
  962. ;; Error when ORGLST line is not provided.
  963. (should-error
  964. (org-test-with-temp-text "- item"
  965. (org-list-send-list)))
  966. ;; Error when transformation function is unknown.
  967. (should-error
  968. (org-test-with-temp-text "@ignore
  969. #+ORGLST: SEND list unknown-function
  970. - item
  971. @end ignore"
  972. (forward-line 2)
  973. (org-list-send-list)))
  974. ;; Error when receiving location is not defined.
  975. (should-error
  976. (org-test-with-temp-text "@ignore
  977. #+ORGLST: SEND list org-list-to-texinfo
  978. - item
  979. @end ignore"
  980. (forward-line 2)
  981. (org-list-send-list)))
  982. ;; Error when insertion region is ill-formed.
  983. (should-error
  984. (org-test-with-temp-text "@c BEGIN RECEIVE ORGLST list
  985. @ignore
  986. #+ORGLST: SEND list org-list-to-texinfo
  987. - item
  988. @end ignore"
  989. (forward-line 3)
  990. (org-list-send-list)))
  991. ;; Allow multiple receiver locations.
  992. (should
  993. (org-test-with-temp-text "
  994. @c BEGIN RECEIVE ORGLST list
  995. @c END RECEIVE ORGLST list
  996. @ignore
  997. #+ORGLST: SEND list org-list-to-texinfo
  998. <point>- item contents
  999. @end ignore
  1000. @c BEGIN RECEIVE ORGLST list
  1001. @c END RECEIVE ORGLST list"
  1002. (org-list-send-list)
  1003. (goto-char (point-min))
  1004. (search-forward "item contents" nil t 3))))
  1005. (ert-deftest test-org-list/to-generic ()
  1006. "Test `org-list-to-generic' specifications."
  1007. ;; Test `:ustart' and `:uend' parameters.
  1008. (should
  1009. (equal
  1010. "begin\na"
  1011. (org-test-with-temp-text "- a"
  1012. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1013. (should-not
  1014. (equal
  1015. "begin\na"
  1016. (org-test-with-temp-text "1. a"
  1017. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1018. (should
  1019. (equal
  1020. "a\nend"
  1021. (org-test-with-temp-text "- a"
  1022. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1023. (should-not
  1024. (equal
  1025. "a\nend"
  1026. (org-test-with-temp-text "1. a"
  1027. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1028. (should
  1029. (equal
  1030. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1031. (org-test-with-temp-text "- a\n - b"
  1032. (org-list-to-generic
  1033. (org-list-to-lisp)
  1034. (list :ustart (lambda (l) (format "begin l%d" l))
  1035. :uend (lambda (l) (format "end l%d" l)))))))
  1036. ;; Test `:ostart' and `:oend' parameters.
  1037. (should
  1038. (equal
  1039. "begin\na"
  1040. (org-test-with-temp-text "1. a"
  1041. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1042. (should-not
  1043. (equal
  1044. "begin\na"
  1045. (org-test-with-temp-text "- a"
  1046. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1047. (should
  1048. (equal
  1049. "a\nend"
  1050. (org-test-with-temp-text "1. a"
  1051. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1052. (should-not
  1053. (equal
  1054. "a\nend"
  1055. (org-test-with-temp-text "- a"
  1056. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1057. (should
  1058. (equal
  1059. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1060. (org-test-with-temp-text "1. a\n 1. b"
  1061. (org-list-to-generic
  1062. (org-list-to-lisp)
  1063. (list :ostart (lambda (l) (format "begin l%d" l))
  1064. :oend (lambda (l) (format "end l%d" l)))))))
  1065. ;; Test `:dstart' and `:dend' parameters.
  1066. (should
  1067. (equal
  1068. "begin\ntaga"
  1069. (org-test-with-temp-text "- tag :: a"
  1070. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1071. (should-not
  1072. (equal
  1073. "begin\na"
  1074. (org-test-with-temp-text "- a"
  1075. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1076. (should
  1077. (equal
  1078. "taga\nend"
  1079. (org-test-with-temp-text "- tag :: a"
  1080. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1081. (should-not
  1082. (equal
  1083. "a\nend"
  1084. (org-test-with-temp-text "- a"
  1085. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1086. (should
  1087. (equal
  1088. "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
  1089. (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
  1090. (org-list-to-generic
  1091. (org-list-to-lisp)
  1092. (list :dstart (lambda (l) (format "begin l%d" l))
  1093. :dend (lambda (l) (format "end l%d" l)))))))
  1094. ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
  1095. (should
  1096. (equal
  1097. ">tag<a"
  1098. (org-test-with-temp-text "- tag :: a"
  1099. (org-list-to-generic (org-list-to-lisp) '(:dtstart ">" :dtend "<")))))
  1100. (should
  1101. (equal
  1102. "tag>a<"
  1103. (org-test-with-temp-text "- tag :: a"
  1104. (org-list-to-generic (org-list-to-lisp) '(:ddstart ">" :ddend "<")))))
  1105. ;; Test `:istart' and `:iend' parameters.
  1106. (should
  1107. (equal
  1108. "starta"
  1109. (org-test-with-temp-text "- a"
  1110. (org-list-to-generic (org-list-to-lisp) '(:istart "start")))))
  1111. (should
  1112. (equal
  1113. "level1 a\nlevel2 b"
  1114. (org-test-with-temp-text "- a\n - b"
  1115. (org-list-to-generic (org-list-to-lisp)
  1116. '(:istart (lambda (l) (format "level%d "l)))))))
  1117. (should
  1118. (equal
  1119. "a\nblevel2level1"
  1120. (org-test-with-temp-text "- a\n - b"
  1121. (org-list-to-generic (org-list-to-lisp)
  1122. '(:iend (lambda (l) (format "level%d" l)))))))
  1123. ;; Test `:icount' parameter.
  1124. (should
  1125. (equal
  1126. "counta"
  1127. (org-test-with-temp-text "1. [@3] a"
  1128. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1129. (should-not
  1130. (equal
  1131. "counta"
  1132. (org-test-with-temp-text "1. a"
  1133. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1134. (should
  1135. (equal
  1136. "counta"
  1137. (org-test-with-temp-text "1. [@3] a"
  1138. (org-list-to-generic (org-list-to-lisp)
  1139. '(:icount "count" :istart "start")))))
  1140. (should
  1141. (equal
  1142. "level:1, counter:3 a"
  1143. (org-test-with-temp-text "1. [@3] a"
  1144. (org-list-to-generic
  1145. (org-list-to-lisp)
  1146. '(:icount (lambda (l c) (format "level:%d, counter:%d " l c)))))))
  1147. ;; Test `:isep' parameter.
  1148. (should
  1149. (equal
  1150. "a\n--\nb"
  1151. (org-test-with-temp-text "- a\n- b"
  1152. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1153. (should-not
  1154. (equal
  1155. "a\n--\nb"
  1156. (org-test-with-temp-text "- a\n - b"
  1157. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1158. (should
  1159. (equal
  1160. "a\n- 1 -\nb"
  1161. (org-test-with-temp-text "- a\n- b"
  1162. (org-list-to-generic (org-list-to-lisp)
  1163. '(:isep (lambda (l) (format "- %d -" l)))))))
  1164. ;; Test `:cbon', `:cboff', `:cbtrans'
  1165. (should
  1166. (equal
  1167. "!a"
  1168. (org-test-with-temp-text "- [X] a"
  1169. (org-list-to-generic (org-list-to-lisp) '(:cbon "!")))))
  1170. (should-not
  1171. (equal
  1172. "!a"
  1173. (org-test-with-temp-text "- [X] a"
  1174. (org-list-to-generic (org-list-to-lisp) '(:cboff "!" :cbtrans "!")))))
  1175. (should
  1176. (equal
  1177. "!a"
  1178. (org-test-with-temp-text "- [ ] a"
  1179. (org-list-to-generic (org-list-to-lisp) '(:cboff "!")))))
  1180. (should-not
  1181. (equal
  1182. "!a"
  1183. (org-test-with-temp-text "- [ ] a"
  1184. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cbtrans "!")))))
  1185. (should
  1186. (equal
  1187. "!a"
  1188. (org-test-with-temp-text "- [-] a"
  1189. (org-list-to-generic (org-list-to-lisp) '(:cbtrans "!")))))
  1190. (should-not
  1191. (equal
  1192. "!a"
  1193. (org-test-with-temp-text "- [-] a"
  1194. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cboff "!")))))
  1195. ;; Test `:splice' parameter.
  1196. (should
  1197. (equal
  1198. "a"
  1199. (org-test-with-temp-text "- a"
  1200. (org-list-to-generic (org-list-to-lisp)
  1201. '(:ustart "begin" :uend "end" :splice t)))))
  1202. ;; No error on empty lists.
  1203. (should
  1204. (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil))))
  1205. (ert-deftest test-org-list/to-html ()
  1206. "Test `org-list-to-html' specifications."
  1207. (should
  1208. (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
  1209. (let (org-html-indent)
  1210. (with-temp-buffer
  1211. (insert "<!-- BEGIN RECEIVE ORGLST name -->
  1212. <!-- END RECEIVE ORGLST name -->
  1213. <!--
  1214. #+ORGLST: SEND name org-list-to-html
  1215. - a
  1216. -->")
  1217. (goto-char (point-min))
  1218. (re-search-forward "^- a" nil t)
  1219. (beginning-of-line)
  1220. (org-list-send-list)
  1221. (goto-line 2)
  1222. (buffer-substring-no-properties
  1223. (point)
  1224. (progn (re-search-forward "^<!-- END" nil t)
  1225. (beginning-of-line)
  1226. (skip-chars-backward " \r\t\n")
  1227. (point))))))))
  1228. (ert-deftest test-org-list/to-latex ()
  1229. "Test `org-list-to-latex' specifications."
  1230. (should
  1231. (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
  1232. (with-temp-buffer
  1233. (insert "% BEGIN RECEIVE ORGLST name
  1234. % END RECEIVE ORGLST name
  1235. \\begin{comment}
  1236. #+ORGLST: SEND name org-list-to-latex
  1237. - a
  1238. \\end{comment}")
  1239. (goto-char (point-min))
  1240. (re-search-forward "^- a" nil t)
  1241. (beginning-of-line)
  1242. (org-list-send-list)
  1243. (goto-line 2)
  1244. (buffer-substring-no-properties
  1245. (point)
  1246. (progn (re-search-forward "^% END" nil t)
  1247. (beginning-of-line)
  1248. (skip-chars-backward " \r\t\n")
  1249. (point)))))))
  1250. (ert-deftest test-org-list/to-texinfo ()
  1251. "Test `org-list-to-texinfo' specifications."
  1252. (should
  1253. (equal "@itemize\n@item\na\n@end itemize"
  1254. (with-temp-buffer
  1255. (insert "@c BEGIN RECEIVE ORGLST name
  1256. @c END RECEIVE ORGLST name
  1257. @ignore
  1258. #+ORGLST: SEND name org-list-to-texinfo
  1259. - a
  1260. @end ignore")
  1261. (goto-char (point-min))
  1262. (re-search-forward "^- a" nil t)
  1263. (beginning-of-line)
  1264. (org-list-send-list)
  1265. (goto-line 2)
  1266. (buffer-substring-no-properties
  1267. (point)
  1268. (progn (re-search-forward "^@c END" nil t)
  1269. (beginning-of-line)
  1270. (skip-chars-backward " \r\t\n")
  1271. (point)))))))
  1272. (provide 'test-org-list)
  1273. ;;; test-org-list.el ends here