test-org-list.el 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323
  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. ;; Preserve list visibility when inserting an item.
  720. (should
  721. (equal
  722. '(outline outline)
  723. (org-test-with-temp-text "- A\n - B\n- C\n - D"
  724. (let ((org-cycle-include-plain-lists t))
  725. (org-cycle)
  726. (forward-line 2)
  727. (org-cycle)
  728. (org-insert-item)
  729. (list (get-char-property (line-beginning-position 0) 'invisible)
  730. (get-char-property (line-end-position 2) 'invisible)))))))
  731. (ert-deftest test-org-list/repair ()
  732. "Test `org-list-repair' specifications."
  733. ;; Repair indentation.
  734. (should
  735. (equal "- item\n - child"
  736. (org-test-with-temp-text "- item\n - child"
  737. (let ((org-list-indent-offset 0)) (org-list-repair))
  738. (buffer-string))))
  739. ;; Repair bullets and numbering.
  740. (should
  741. (equal "- a\n- b"
  742. (org-test-with-temp-text "- a\n+ b"
  743. (let ((org-list-indent-offset 0))
  744. (org-list-repair))
  745. (buffer-string))))
  746. (should
  747. (equal "1. a\n2. b"
  748. (org-test-with-temp-text "1. a\n1. b"
  749. (let ((org-list-indent-offset 0)
  750. (org-plain-list-ordered-item-terminator t))
  751. (org-list-repair))
  752. (buffer-string))))
  753. ;; Repair check-boxes.
  754. (should
  755. (equal "- [X] item\n - [X] child"
  756. (org-test-with-temp-text "- [ ] item\n - [X] child"
  757. (let ((org-list-indent-offset 0))
  758. (org-list-repair))
  759. (buffer-string))))
  760. ;; Special case: do not move contents of an item within its child.
  761. ;; Yet, preserve indentation differences within contents.
  762. (should
  763. (equal "- item\n - child\n within item"
  764. (org-test-with-temp-text "- item\n - child\n within item"
  765. (let ((org-list-indent-offset 0)) (org-list-repair))
  766. (buffer-string))))
  767. (should
  768. (equal
  769. "- item\n - child\n within item\n indented"
  770. (org-test-with-temp-text
  771. "- item\n - child\n within item\n indented"
  772. (let ((org-list-indent-offset 0)) (org-list-repair))
  773. (buffer-string)))))
  774. (ert-deftest test-org-list/update-checkbox-count ()
  775. "Test `org-update-checkbox-count' specifications."
  776. ;; From a headline.
  777. (should
  778. (string-match "\\[0/1\\]"
  779. (org-test-with-temp-text "* [/]\n- [ ] item"
  780. (org-update-checkbox-count)
  781. (buffer-string))))
  782. (should
  783. (string-match "\\[1/1\\]"
  784. (org-test-with-temp-text "* [/]\n- [X] item"
  785. (org-update-checkbox-count)
  786. (buffer-string))))
  787. (should
  788. (string-match "\\[100%\\]"
  789. (org-test-with-temp-text "* [%]\n- [X] item"
  790. (org-update-checkbox-count)
  791. (buffer-string))))
  792. ;; From a list or a sub-list.
  793. (should
  794. (string-match "\\[0/1\\]"
  795. (org-test-with-temp-text "- [/]\n - [ ] item"
  796. (org-update-checkbox-count)
  797. (buffer-string))))
  798. (should
  799. (string-match "\\[1/1\\]"
  800. (org-test-with-temp-text "- [/]\n - [X] item"
  801. (org-update-checkbox-count)
  802. (buffer-string))))
  803. (should
  804. (string-match "\\[100%\\]"
  805. (org-test-with-temp-text "- [%]\n - [X] item"
  806. (org-update-checkbox-count)
  807. (buffer-string))))
  808. (should
  809. (string-match
  810. "\\[1/1\\]"
  811. (org-test-with-temp-text "- [ ] item 1\n- [ ] item 2 [/]\n - [X] sub 1"
  812. (org-update-checkbox-count)
  813. (buffer-string))))
  814. ;; Count do not apply to sub-lists unless count is not hierarchical.
  815. ;; This state can be achieved with COOKIE_DATA node property set to
  816. ;; "recursive".
  817. (should
  818. (string-match "\\[1/1\\]"
  819. (org-test-with-temp-text "- [/]\n - item\n - [X] sub-item"
  820. (let ((org-checkbox-hierarchical-statistics nil))
  821. (org-update-checkbox-count))
  822. (buffer-string))))
  823. (should
  824. (string-match "\\[1/1\\]"
  825. (org-test-with-temp-text "
  826. <point>* H
  827. :PROPERTIES:
  828. :COOKIE_DATA: recursive
  829. :END:
  830. - [/]
  831. - item
  832. - [X] sub-item"
  833. (org-update-checkbox-count)
  834. (buffer-string))))
  835. (should
  836. (string-match "\\[0/0\\]"
  837. (org-test-with-temp-text "- [/]\n - item\n - [ ] sub-item"
  838. (org-update-checkbox-count)
  839. (buffer-string))))
  840. ;; With optional argument ALL, update all buffer.
  841. (should
  842. (= 2
  843. (org-test-with-temp-text "* [/]\n- [X] item\n* [/]\n- [X] item"
  844. (org-update-checkbox-count t)
  845. (count-matches "\\[1/1\\]"))))
  846. ;; Ignore boxes in drawers, blocks or inlinetasks when counting from
  847. ;; outside.
  848. (should
  849. (string-match "\\[2/2\\]"
  850. (org-test-with-temp-text "
  851. - [/]
  852. - [X] item1
  853. :DRAWER:
  854. - [X] item
  855. :END:
  856. - [X] item2"
  857. (let ((org-checkbox-hierarchical-statistics nil))
  858. (org-update-checkbox-count))
  859. (buffer-string)))))
  860. ;;; Miscellaneous
  861. (ert-deftest test-org-list/toggle-item ()
  862. "Test `org-toggle-item' specifications."
  863. ;; Convert normal lines to items.
  864. (should
  865. (equal "- line"
  866. (org-test-with-temp-text "line"
  867. (org-toggle-item nil)
  868. (buffer-string))))
  869. ;; Convert items to normal lines.
  870. (should
  871. (equal "line"
  872. (org-test-with-temp-text "- line"
  873. (org-toggle-item nil)
  874. (buffer-string))))
  875. ;; Convert headlines to items.
  876. (should
  877. (equal "- line"
  878. (org-test-with-temp-text "* line"
  879. (org-toggle-item nil)
  880. (buffer-string))))
  881. ;; When converting a headline to a list item, TODO keywords become
  882. ;; checkboxes.
  883. (should
  884. (equal "- [X] line"
  885. (org-test-with-temp-text "* DONE line"
  886. (org-toggle-item nil)
  887. (buffer-string))))
  888. (should
  889. (equal "- [ ] line"
  890. (org-test-with-temp-text "* TODO line"
  891. (org-toggle-item nil)
  892. (buffer-string))))
  893. ;; When a region is marked and first line is a headline, all
  894. ;; headlines are turned into items.
  895. (should
  896. (equal "- H1\n - H2"
  897. (org-test-with-temp-text "* H1\n** H2"
  898. (transient-mark-mode 1)
  899. (push-mark (point) t t)
  900. (goto-char (point-max))
  901. (org-toggle-item nil)
  902. (buffer-string))))
  903. (should
  904. (equal "- [ ] H1\n - [ ] H2"
  905. (org-test-with-temp-text "* TODO H1\n** TODO H2"
  906. (transient-mark-mode 1)
  907. (push-mark (point) t t)
  908. (goto-char (point-max))
  909. (org-toggle-item nil)
  910. (buffer-string))))
  911. ;; When turning headlines into items, make sure headings contents
  912. ;; are kept within items.
  913. (should
  914. (equal "- H1\n Text"
  915. (org-test-with-temp-text "* H1\nText"
  916. (transient-mark-mode 1)
  917. (push-mark (point) t t)
  918. (goto-char (point-max))
  919. (org-toggle-item nil)
  920. (buffer-string))))
  921. ;; When a region is marked and first line is an item, all items are
  922. ;; turned into normal lines.
  923. (should
  924. (equal "1\n 2"
  925. (org-test-with-temp-text "- 1\n - 2"
  926. (transient-mark-mode 1)
  927. (push-mark (point) t t)
  928. (goto-char (point-max))
  929. (org-toggle-item nil)
  930. (buffer-string))))
  931. (should
  932. (equal "1\n2"
  933. (org-test-with-temp-text "- 1\n2"
  934. (transient-mark-mode 1)
  935. (push-mark (point) t t)
  936. (goto-char (point-max))
  937. (org-toggle-item nil)
  938. (buffer-string))))
  939. ;; When a region is marked and first line is an item, all normal
  940. ;; lines are turned into items.
  941. (should
  942. (equal "- line 1\n- line 2"
  943. (org-test-with-temp-text "line 1\nline 2"
  944. (transient-mark-mode 1)
  945. (push-mark (point) t t)
  946. (goto-char (point-max))
  947. (org-toggle-item nil)
  948. (buffer-string))))
  949. (should
  950. (equal "- line 1\n- line 2"
  951. (org-test-with-temp-text "line 1\n- line 2"
  952. (transient-mark-mode 1)
  953. (push-mark (point) t t)
  954. (goto-char (point-max))
  955. (org-toggle-item nil)
  956. (buffer-string))))
  957. ;; When argument ARG is non-nil, change the whole region into
  958. ;; a single item.
  959. (should
  960. (equal "- line 1\n line 2"
  961. (org-test-with-temp-text "line 1\nline 2"
  962. (transient-mark-mode 1)
  963. (push-mark (point) t t)
  964. (goto-char (point-max))
  965. (org-toggle-item t)
  966. (buffer-string)))))
  967. ;;; Radio Lists
  968. (ert-deftest test-org-list/send-list ()
  969. "Test various checks for `org-list-send-list'."
  970. ;; Error when not at a list item.
  971. (should-error
  972. (org-test-with-temp-text "Not a list item"
  973. (org-list-send-list)))
  974. ;; Error when ORGLST line is not provided.
  975. (should-error
  976. (org-test-with-temp-text "- item"
  977. (org-list-send-list)))
  978. ;; Error when transformation function is unknown.
  979. (should-error
  980. (org-test-with-temp-text "@ignore
  981. #+ORGLST: SEND list unknown-function
  982. - item
  983. @end ignore"
  984. (forward-line 2)
  985. (org-list-send-list)))
  986. ;; Error when receiving location is not defined.
  987. (should-error
  988. (org-test-with-temp-text "@ignore
  989. #+ORGLST: SEND list org-list-to-texinfo
  990. - item
  991. @end ignore"
  992. (forward-line 2)
  993. (org-list-send-list)))
  994. ;; Error when insertion region is ill-formed.
  995. (should-error
  996. (org-test-with-temp-text "@c BEGIN RECEIVE ORGLST list
  997. @ignore
  998. #+ORGLST: SEND list org-list-to-texinfo
  999. - item
  1000. @end ignore"
  1001. (forward-line 3)
  1002. (org-list-send-list)))
  1003. ;; Allow multiple receiver locations.
  1004. (should
  1005. (org-test-with-temp-text "
  1006. @c BEGIN RECEIVE ORGLST list
  1007. @c END RECEIVE ORGLST list
  1008. @ignore
  1009. #+ORGLST: SEND list org-list-to-texinfo
  1010. <point>- item contents
  1011. @end ignore
  1012. @c BEGIN RECEIVE ORGLST list
  1013. @c END RECEIVE ORGLST list"
  1014. (org-list-send-list)
  1015. (goto-char (point-min))
  1016. (search-forward "item contents" nil t 3))))
  1017. (ert-deftest test-org-list/to-generic ()
  1018. "Test `org-list-to-generic' specifications."
  1019. ;; Test `:ustart' and `:uend' parameters.
  1020. (should
  1021. (equal
  1022. "begin\na"
  1023. (org-test-with-temp-text "- a"
  1024. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1025. (should-not
  1026. (equal
  1027. "begin\na"
  1028. (org-test-with-temp-text "1. a"
  1029. (org-list-to-generic (org-list-to-lisp) '(:ustart "begin")))))
  1030. (should
  1031. (equal
  1032. "a\nend"
  1033. (org-test-with-temp-text "- a"
  1034. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1035. (should-not
  1036. (equal
  1037. "a\nend"
  1038. (org-test-with-temp-text "1. a"
  1039. (org-list-to-generic (org-list-to-lisp) '(:uend "end")))))
  1040. (should
  1041. (equal
  1042. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1043. (org-test-with-temp-text "- a\n - b"
  1044. (org-list-to-generic
  1045. (org-list-to-lisp)
  1046. (list :ustart (lambda (l) (format "begin l%d" l))
  1047. :uend (lambda (l) (format "end l%d" l)))))))
  1048. ;; Test `:ostart' and `:oend' parameters.
  1049. (should
  1050. (equal
  1051. "begin\na"
  1052. (org-test-with-temp-text "1. a"
  1053. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1054. (should-not
  1055. (equal
  1056. "begin\na"
  1057. (org-test-with-temp-text "- a"
  1058. (org-list-to-generic (org-list-to-lisp) '(:ostart "begin")))))
  1059. (should
  1060. (equal
  1061. "a\nend"
  1062. (org-test-with-temp-text "1. a"
  1063. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1064. (should-not
  1065. (equal
  1066. "a\nend"
  1067. (org-test-with-temp-text "- a"
  1068. (org-list-to-generic (org-list-to-lisp) '(:oend "end")))))
  1069. (should
  1070. (equal
  1071. "begin l1\na\nbegin l2\nb\nend l2\nend l1"
  1072. (org-test-with-temp-text "1. a\n 1. b"
  1073. (org-list-to-generic
  1074. (org-list-to-lisp)
  1075. (list :ostart (lambda (l) (format "begin l%d" l))
  1076. :oend (lambda (l) (format "end l%d" l)))))))
  1077. ;; Test `:dstart' and `:dend' parameters.
  1078. (should
  1079. (equal
  1080. "begin\ntaga"
  1081. (org-test-with-temp-text "- tag :: a"
  1082. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1083. (should-not
  1084. (equal
  1085. "begin\na"
  1086. (org-test-with-temp-text "- a"
  1087. (org-list-to-generic (org-list-to-lisp) '(:dstart "begin")))))
  1088. (should
  1089. (equal
  1090. "taga\nend"
  1091. (org-test-with-temp-text "- tag :: a"
  1092. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1093. (should-not
  1094. (equal
  1095. "a\nend"
  1096. (org-test-with-temp-text "- a"
  1097. (org-list-to-generic (org-list-to-lisp) '(:dend "end")))))
  1098. (should
  1099. (equal
  1100. "begin l1\ntag1a\nbegin l2\ntag2b\nend l2\nend l1"
  1101. (org-test-with-temp-text "- tag1 :: a\n - tag2 :: b"
  1102. (org-list-to-generic
  1103. (org-list-to-lisp)
  1104. (list :dstart (lambda (l) (format "begin l%d" l))
  1105. :dend (lambda (l) (format "end l%d" l)))))))
  1106. ;; Test `:dtstart', `:dtend', `:ddstart' and `:ddend' parameters.
  1107. (should
  1108. (equal
  1109. ">tag<a"
  1110. (org-test-with-temp-text "- tag :: a"
  1111. (org-list-to-generic (org-list-to-lisp) '(:dtstart ">" :dtend "<")))))
  1112. (should
  1113. (equal
  1114. "tag>a<"
  1115. (org-test-with-temp-text "- tag :: a"
  1116. (org-list-to-generic (org-list-to-lisp) '(:ddstart ">" :ddend "<")))))
  1117. ;; Test `:istart' and `:iend' parameters.
  1118. (should
  1119. (equal
  1120. "starta"
  1121. (org-test-with-temp-text "- a"
  1122. (org-list-to-generic (org-list-to-lisp) '(:istart "start")))))
  1123. (should
  1124. (equal
  1125. "level1 a\nlevel2 b"
  1126. (org-test-with-temp-text "- a\n - b"
  1127. (org-list-to-generic (org-list-to-lisp)
  1128. '(:istart (lambda (l) (format "level%d "l)))))))
  1129. (should
  1130. (equal
  1131. "a\nblevel2level1"
  1132. (org-test-with-temp-text "- a\n - b"
  1133. (org-list-to-generic (org-list-to-lisp)
  1134. '(:iend (lambda (l) (format "level%d" l)))))))
  1135. ;; Test `:icount' parameter.
  1136. (should
  1137. (equal
  1138. "counta"
  1139. (org-test-with-temp-text "1. [@3] a"
  1140. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1141. (should-not
  1142. (equal
  1143. "counta"
  1144. (org-test-with-temp-text "1. a"
  1145. (org-list-to-generic (org-list-to-lisp) '(:icount "count")))))
  1146. (should
  1147. (equal
  1148. "counta"
  1149. (org-test-with-temp-text "1. [@3] a"
  1150. (org-list-to-generic (org-list-to-lisp)
  1151. '(:icount "count" :istart "start")))))
  1152. (should
  1153. (equal
  1154. "level:1, counter:3 a"
  1155. (org-test-with-temp-text "1. [@3] a"
  1156. (org-list-to-generic
  1157. (org-list-to-lisp)
  1158. '(:icount (lambda (l c) (format "level:%d, counter:%d " l c)))))))
  1159. ;; Test `:isep' parameter.
  1160. (should
  1161. (equal
  1162. "a\n--\nb"
  1163. (org-test-with-temp-text "- a\n- b"
  1164. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1165. (should-not
  1166. (equal
  1167. "a\n--\nb"
  1168. (org-test-with-temp-text "- a\n - b"
  1169. (org-list-to-generic (org-list-to-lisp) '(:isep "--")))))
  1170. (should
  1171. (equal
  1172. "a\n- 1 -\nb"
  1173. (org-test-with-temp-text "- a\n- b"
  1174. (org-list-to-generic (org-list-to-lisp)
  1175. '(:isep (lambda (l) (format "- %d -" l)))))))
  1176. ;; Test `:cbon', `:cboff', `:cbtrans'
  1177. (should
  1178. (equal
  1179. "!a"
  1180. (org-test-with-temp-text "- [X] a"
  1181. (org-list-to-generic (org-list-to-lisp) '(:cbon "!")))))
  1182. (should-not
  1183. (equal
  1184. "!a"
  1185. (org-test-with-temp-text "- [X] a"
  1186. (org-list-to-generic (org-list-to-lisp) '(:cboff "!" :cbtrans "!")))))
  1187. (should
  1188. (equal
  1189. "!a"
  1190. (org-test-with-temp-text "- [ ] a"
  1191. (org-list-to-generic (org-list-to-lisp) '(:cboff "!")))))
  1192. (should-not
  1193. (equal
  1194. "!a"
  1195. (org-test-with-temp-text "- [ ] a"
  1196. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cbtrans "!")))))
  1197. (should
  1198. (equal
  1199. "!a"
  1200. (org-test-with-temp-text "- [-] a"
  1201. (org-list-to-generic (org-list-to-lisp) '(:cbtrans "!")))))
  1202. (should-not
  1203. (equal
  1204. "!a"
  1205. (org-test-with-temp-text "- [-] a"
  1206. (org-list-to-generic (org-list-to-lisp) '(:cbon "!" :cboff "!")))))
  1207. ;; Test `:splice' parameter.
  1208. (should
  1209. (equal
  1210. "a"
  1211. (org-test-with-temp-text "- a"
  1212. (org-list-to-generic (org-list-to-lisp)
  1213. '(:ustart "begin" :uend "end" :splice t)))))
  1214. ;; No error on empty lists.
  1215. (should
  1216. (org-test-with-temp-text "-" (org-list-to-generic (org-list-to-lisp) nil))))
  1217. (ert-deftest test-org-list/to-html ()
  1218. "Test `org-list-to-html' specifications."
  1219. (should
  1220. (equal "<ul class=\"org-ul\">\n<li>a</li>\n</ul>"
  1221. (let (org-html-indent)
  1222. (with-temp-buffer
  1223. (insert "<!-- BEGIN RECEIVE ORGLST name -->
  1224. <!-- END RECEIVE ORGLST name -->
  1225. <!--
  1226. #+ORGLST: SEND name org-list-to-html
  1227. - a
  1228. -->")
  1229. (goto-char (point-min))
  1230. (re-search-forward "^- a" nil t)
  1231. (beginning-of-line)
  1232. (org-list-send-list)
  1233. (goto-line 2)
  1234. (buffer-substring-no-properties
  1235. (point)
  1236. (progn (re-search-forward "^<!-- END" nil t)
  1237. (beginning-of-line)
  1238. (skip-chars-backward " \r\t\n")
  1239. (point))))))))
  1240. (ert-deftest test-org-list/to-latex ()
  1241. "Test `org-list-to-latex' specifications."
  1242. (should
  1243. (equal "\\begin{itemize}\n\\item a\n\\end{itemize}"
  1244. (with-temp-buffer
  1245. (insert "% BEGIN RECEIVE ORGLST name
  1246. % END RECEIVE ORGLST name
  1247. \\begin{comment}
  1248. #+ORGLST: SEND name org-list-to-latex
  1249. - a
  1250. \\end{comment}")
  1251. (goto-char (point-min))
  1252. (re-search-forward "^- a" nil t)
  1253. (beginning-of-line)
  1254. (org-list-send-list)
  1255. (goto-line 2)
  1256. (buffer-substring-no-properties
  1257. (point)
  1258. (progn (re-search-forward "^% END" nil t)
  1259. (beginning-of-line)
  1260. (skip-chars-backward " \r\t\n")
  1261. (point)))))))
  1262. (ert-deftest test-org-list/to-texinfo ()
  1263. "Test `org-list-to-texinfo' specifications."
  1264. (should
  1265. (equal "@itemize\n@item\na\n@end itemize"
  1266. (with-temp-buffer
  1267. (insert "@c BEGIN RECEIVE ORGLST name
  1268. @c END RECEIVE ORGLST name
  1269. @ignore
  1270. #+ORGLST: SEND name org-list-to-texinfo
  1271. - a
  1272. @end ignore")
  1273. (goto-char (point-min))
  1274. (re-search-forward "^- a" nil t)
  1275. (beginning-of-line)
  1276. (org-list-send-list)
  1277. (goto-line 2)
  1278. (buffer-substring-no-properties
  1279. (point)
  1280. (progn (re-search-forward "^@c END" nil t)
  1281. (beginning-of-line)
  1282. (skip-chars-backward " \r\t\n")
  1283. (point)))))))
  1284. (provide 'test-org-list)
  1285. ;;; test-org-list.el ends here