test-org-colview.el 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  1. ;;; test-org-colview.el --- Tests for org-colview.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2016 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
  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. ;;; Column view
  16. (require 'cl-lib)
  17. (ert-deftest test-org-colview/get-format ()
  18. "Test `org-columns-get-format' specifications."
  19. ;; Without any clue, use `org-columns-default-format'.
  20. (should
  21. (equal "%A"
  22. (org-test-with-temp-text "* H"
  23. (let ((org-columns-default-format "%A"))
  24. (org-columns-get-format)))))
  25. ;; If COLUMNS keyword is set, use it.
  26. (should
  27. (equal "%B"
  28. (org-test-with-temp-text "#+COLUMNS: %B\n* H"
  29. (let ((org-columns-default-format "%A"))
  30. (org-columns-get-format)))))
  31. (should
  32. (equal "%B"
  33. (org-test-with-temp-text "#+columns: %B\n* H"
  34. (let ((org-columns-default-format "%A"))
  35. (org-columns-get-format)))))
  36. (should
  37. (equal "%B"
  38. (org-test-with-temp-text "* H\n#+COLUMNS: %B"
  39. (let ((org-columns-default-format "%A"))
  40. (org-columns-get-format)))))
  41. ;; When :COLUMNS: property is set somewhere in the tree, use it over
  42. ;; the previous ways.
  43. (should
  44. (equal
  45. "%C"
  46. (org-test-with-temp-text
  47. "#+COLUMNS: %B\n* H\n:PROPERTIES:\n:COLUMNS: %C\n:END:\n** S\n<point>"
  48. (let ((org-columns-default-format "%A"))
  49. (org-columns-get-format)))))
  50. ;; When optional argument is provided, prefer it.
  51. (should
  52. (equal
  53. "%D"
  54. (org-test-with-temp-text
  55. "#+COLUMNS: %B\n* H\n:PROPERTIES:\n:COLUMNS: %C\n:END:\n** S\n<point>"
  56. (let ((org-columns-default-format "%A"))
  57. (org-columns-get-format "%D"))))))
  58. (ert-deftest test-org-colview/columns-scope ()
  59. "Test `org-columns' scope."
  60. ;; Before the first headline, view all document.
  61. (should
  62. (equal
  63. '("H1" "H2" "H3")
  64. (org-test-with-temp-text "Top\n* H1\n** H2\n* H3"
  65. (let ((org-columns-default-format "%ITEM")) (org-columns))
  66. (org-map-entries
  67. (lambda () (get-char-property (point) 'org-columns-value))))))
  68. ;; When :COLUMNS: is set up in the hierarchy, view tree starting
  69. ;; there.
  70. (should
  71. (equal
  72. '(nil "H2" "H3" nil)
  73. (org-test-with-temp-text
  74. "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
  75. (let ((org-columns-default-format "%ITEM")) (org-columns))
  76. (org-map-entries
  77. (lambda () (get-char-property (point) 'org-columns-value))))))
  78. ;; Otherwise, view tree starting at the current headline.
  79. (should
  80. (equal
  81. '(nil "H2" "H3" nil)
  82. (org-test-with-temp-text "Top\n* H1\n** <point>H2\n*** H3\n* H4"
  83. (let ((org-columns-default-format "%ITEM")) (org-columns))
  84. (org-map-entries
  85. (lambda () (get-char-property (point) 'org-columns-value))))))
  86. ;; With a non-nil prefix argument, always view all document.
  87. (should
  88. (equal
  89. '("H1" "H2" "H3" "H4")
  90. (org-test-with-temp-text
  91. "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
  92. (let ((org-columns-default-format "%ITEM")) (org-columns t))
  93. (org-map-entries
  94. (lambda () (get-char-property (point) 'org-columns-value))))))
  95. (should
  96. (equal
  97. '("1" "1")
  98. (org-test-with-temp-text
  99. "Top\n* H1\n** <point>H2\n:PROPERTIES:\n:A: 1\n:END:"
  100. (let ((org-columns-default-format "%A{+}")) (org-columns t))
  101. (org-map-entries
  102. (lambda () (get-char-property (point) 'org-columns-value)))))))
  103. (ert-deftest test-org-colview/columns-width ()
  104. "Test `org-columns' column widths."
  105. ;; When a width is specified in the format, use it.
  106. (should
  107. (= 9
  108. (org-test-with-temp-text "* H"
  109. (let ((org-columns-default-format "%9ITEM")) (org-columns))
  110. (aref org-columns-current-maxwidths 0))))
  111. ;; Otherwise, use the width of the largest value in the column.
  112. (should
  113. (= 2
  114. (org-test-with-temp-text
  115. "* H\n:PROPERTIES:\n:P: X\n:END:\n** H2\n:PROPERTIES:\n:P: XX\n:END:"
  116. (let ((org-columns-default-format "%P")) (org-columns))
  117. (aref org-columns-current-maxwidths 0))))
  118. ;; If the title is wider than the widest value, use title width
  119. ;; instead.
  120. (should
  121. (= 4
  122. (org-test-with-temp-text "* H"
  123. (let ((org-columns-default-format "%ITEM")) (org-columns))
  124. (aref org-columns-current-maxwidths 0))))
  125. ;; Special case: stars do count for ITEM.
  126. (should
  127. (= 6
  128. (org-test-with-temp-text "* Head"
  129. (let ((org-columns-default-format "%ITEM")) (org-columns))
  130. (aref org-columns-current-maxwidths 0))))
  131. ;; Special case: width takes into account link narrowing in ITEM.
  132. (should
  133. (equal
  134. '("* [123]" . 7)
  135. (org-test-with-temp-text "* [[https://orgmode.org][123]]"
  136. (let ((org-columns-default-format "%ITEM")) (org-columns))
  137. (cons (get-char-property (point) 'org-columns-value-modified)
  138. (aref org-columns-current-maxwidths 0)))))
  139. ;; When a value is too wide for the current column, add ellipses.
  140. ;; Take into consideration length of `org-columns-ellipses'.
  141. (should
  142. (equal "123.. |"
  143. (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
  144. (let ((org-columns-default-format "%5P")
  145. (org-columns-ellipses ".."))
  146. (org-columns))
  147. (org-trim (get-char-property (point) 'display)))))
  148. (should
  149. (equal "1234… |"
  150. (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
  151. (let ((org-columns-default-format "%5P")
  152. (org-columns-ellipses "…"))
  153. (org-columns))
  154. (org-trim (get-char-property (point) 'display))))))
  155. (ert-deftest test-org-colview/columns-summary ()
  156. "Test `org-columns' summary types."
  157. ;; {+} and {+;format} add numbers.
  158. (should
  159. (equal
  160. "3"
  161. (org-test-with-temp-text
  162. "* H
  163. ** S1
  164. :PROPERTIES:
  165. :A: 1
  166. :END:
  167. ** S1
  168. :PROPERTIES:
  169. :A: 2
  170. :END:"
  171. (let ((org-columns-default-format "%A{+}")) (org-columns))
  172. (get-char-property (point) 'org-columns-value-modified))))
  173. (should
  174. (equal
  175. "3.0"
  176. (org-test-with-temp-text
  177. "* H
  178. ** S1
  179. :PROPERTIES:
  180. :A: 1
  181. :END:
  182. ** S1
  183. :PROPERTIES:
  184. :A: 2
  185. :END:"
  186. (let ((org-columns-default-format "%A{+;%.1f}")) (org-columns))
  187. (get-char-property (point) 'org-columns-value-modified))))
  188. ;; {$} is a shortcut for {+;%.2f}.
  189. (should
  190. (equal
  191. "3.60"
  192. (org-test-with-temp-text
  193. "* H
  194. ** S1
  195. :PROPERTIES:
  196. :A: 1.50
  197. :END:
  198. ** S1
  199. :PROPERTIES:
  200. :A: 2.10
  201. :END:"
  202. (let ((org-columns-default-format "%A{$}")) (org-columns))
  203. (get-char-property (point) 'org-columns-value-modified))))
  204. ;; Obey to format string even in leaf values.
  205. (should
  206. (equal
  207. "1.0"
  208. (org-test-with-temp-text
  209. "* H
  210. :PROPERTIES:
  211. :A: 1
  212. :END:"
  213. (let ((org-columns-default-format "%A{+;%.1f}")) (org-columns))
  214. (get-char-property (point) 'org-columns-value-modified))))
  215. ;; {:} sums times. Plain numbers are hours.
  216. (should
  217. (equal
  218. "4:10"
  219. (org-test-with-temp-text
  220. "* H
  221. ** S1
  222. :PROPERTIES:
  223. :A: 1:30
  224. :END:
  225. ** S1
  226. :PROPERTIES:
  227. :A: 2:40
  228. :END:"
  229. (let ((org-columns-default-format "%A{:}")) (org-columns))
  230. (get-char-property (point) 'org-columns-value-modified))))
  231. (should
  232. (equal
  233. "3:30"
  234. (org-test-with-temp-text
  235. "* H
  236. ** S1
  237. :PROPERTIES:
  238. :A: 1:30
  239. :END:
  240. ** S1
  241. :PROPERTIES:
  242. :A: 2
  243. :END:"
  244. (let ((org-columns-default-format "%A{:}")) (org-columns))
  245. (get-char-property (point) 'org-columns-value-modified))))
  246. ;; {X}, {X/} and {X%} indicate checkbox status.
  247. (should
  248. (equal
  249. "[ ]"
  250. (org-test-with-temp-text
  251. "* H
  252. ** S1
  253. :PROPERTIES:
  254. :A: [ ]
  255. :END:
  256. ** S1
  257. :PROPERTIES:
  258. :A: [ ]
  259. :END:"
  260. (let ((org-columns-default-format "%A{X}")) (org-columns))
  261. (get-char-property (point) 'org-columns-value-modified))))
  262. (should
  263. (equal
  264. "[-]"
  265. (org-test-with-temp-text
  266. "* H
  267. ** S1
  268. :PROPERTIES:
  269. :A: [ ]
  270. :END:
  271. ** S1
  272. :PROPERTIES:
  273. :A: [X]
  274. :END:"
  275. (let ((org-columns-default-format "%A{X}")) (org-columns))
  276. (get-char-property (point) 'org-columns-value-modified))))
  277. (should
  278. (equal
  279. "[X]"
  280. (org-test-with-temp-text
  281. "* H
  282. ** S1
  283. :PROPERTIES:
  284. :A: [X]
  285. :END:
  286. ** S1
  287. :PROPERTIES:
  288. :A: [X]
  289. :END:"
  290. (let ((org-columns-default-format "%A{X}")) (org-columns))
  291. (get-char-property (point) 'org-columns-value-modified))))
  292. (should
  293. (equal
  294. "[1/2]"
  295. (org-test-with-temp-text
  296. "* H
  297. ** S1
  298. :PROPERTIES:
  299. :A: [ ]
  300. :END:
  301. ** S1
  302. :PROPERTIES:
  303. :A: [X]
  304. :END:"
  305. (let ((org-columns-default-format "%A{X/}")) (org-columns))
  306. (get-char-property (point) 'org-columns-value-modified))))
  307. (should
  308. (equal
  309. "[50%]"
  310. (org-test-with-temp-text
  311. "* H
  312. ** S1
  313. :PROPERTIES:
  314. :A: [ ]
  315. :END:
  316. ** S1
  317. :PROPERTIES:
  318. :A: [X]
  319. :END:"
  320. (let ((org-columns-default-format "%A{X%}")) (org-columns))
  321. (get-char-property (point) 'org-columns-value-modified))))
  322. ;; {X/} handles recursive summaries.
  323. (should
  324. (equal
  325. "[1/2]"
  326. (org-test-with-temp-text
  327. "* H
  328. ** S1
  329. :PROPERTIES:
  330. :A: [ ]
  331. :END:
  332. ** S2
  333. *** S21
  334. :PROPERTIES:
  335. :A: [X]
  336. :END:
  337. *** S22
  338. :PROPERTIES:
  339. :A: [X]
  340. :END:"
  341. (let ((org-columns-default-format "%A{X/}")) (org-columns))
  342. (get-char-property (point) 'org-columns-value-modified))))
  343. (should
  344. (equal
  345. "[1/2]"
  346. (org-test-with-temp-text
  347. "* H
  348. ** S1
  349. :PROPERTIES:
  350. :A: [X]
  351. :END:
  352. ** S2
  353. *** S21
  354. :PROPERTIES:
  355. :A: [ ]
  356. :END:
  357. *** S22
  358. :PROPERTIES:
  359. :A: [ ]
  360. :END:"
  361. (let ((org-columns-default-format "%A{X/}")) (org-columns))
  362. (get-char-property (point) 'org-columns-value-modified))))
  363. ;; {X%} handles recursive summaries.
  364. (should
  365. (equal
  366. "[50%]"
  367. (org-test-with-temp-text
  368. "* H
  369. ** S1
  370. :PROPERTIES:
  371. :A: [ ]
  372. :END:
  373. ** S2
  374. *** S21
  375. :PROPERTIES:
  376. :A: [X]
  377. :END:
  378. *** S22
  379. :PROPERTIES:
  380. :A: [X]
  381. :END:"
  382. (let ((org-columns-default-format "%A{X%}")) (org-columns))
  383. (get-char-property (point) 'org-columns-value-modified))))
  384. (should
  385. (equal
  386. "[50%]"
  387. (org-test-with-temp-text
  388. "* H
  389. ** S1
  390. :PROPERTIES:
  391. :A: [X]
  392. :END:
  393. ** S2
  394. *** S21
  395. :PROPERTIES:
  396. :A: [ ]
  397. :END:
  398. *** S22
  399. :PROPERTIES:
  400. :A: [ ]
  401. :END:"
  402. (let ((org-columns-default-format "%A{X%}")) (org-columns))
  403. (get-char-property (point) 'org-columns-value-modified))))
  404. ;; {min} is the smallest number in column, {max} the largest one.
  405. ;; {mean} is the arithmetic mean of numbers in column.
  406. (should
  407. (equal
  408. "42"
  409. (org-test-with-temp-text
  410. "* H
  411. ** S1
  412. :PROPERTIES:
  413. :A: 99
  414. :END:
  415. ** S1
  416. :PROPERTIES:
  417. :A: 42
  418. :END:"
  419. (let ((org-columns-default-format "%A{min}")) (org-columns))
  420. (get-char-property (point) 'org-columns-value-modified))))
  421. (should
  422. (equal
  423. "99"
  424. (org-test-with-temp-text
  425. "* H
  426. ** S1
  427. :PROPERTIES:
  428. :A: 99
  429. :END:
  430. ** S1
  431. :PROPERTIES:
  432. :A: 42
  433. :END:"
  434. (let ((org-columns-default-format "%A{max}")) (org-columns))
  435. (get-char-property (point) 'org-columns-value-modified))))
  436. (should
  437. (equal
  438. "51.0"
  439. (org-test-with-temp-text
  440. "* H
  441. ** S1
  442. :PROPERTIES:
  443. :A: 60
  444. :END:
  445. ** S1
  446. :PROPERTIES:
  447. :A: 42
  448. :END:"
  449. (let ((org-columns-default-format "%A{mean}")) (org-columns))
  450. (get-char-property (point) 'org-columns-value-modified))))
  451. ;; {:min}, {:max} and {:mean} apply to time values.
  452. (should
  453. (equal
  454. "1:20"
  455. (org-test-with-temp-text
  456. "* H
  457. ** S1
  458. :PROPERTIES:
  459. :A: 4:40
  460. :END:
  461. ** S1
  462. :PROPERTIES:
  463. :A: 1:20
  464. :END:"
  465. (let ((org-columns-default-format "%A{:min}")) (org-columns))
  466. (get-char-property (point) 'org-columns-value-modified))))
  467. (should
  468. (equal
  469. "4:40"
  470. (org-test-with-temp-text
  471. "* H
  472. ** S1
  473. :PROPERTIES:
  474. :A: 4:40
  475. :END:
  476. ** S1
  477. :PROPERTIES:
  478. :A: 1:20
  479. :END:"
  480. (let ((org-columns-default-format "%A{:max}")) (org-columns))
  481. (get-char-property (point) 'org-columns-value-modified))))
  482. (should
  483. (equal
  484. "3:00"
  485. (org-test-with-temp-text
  486. "* H
  487. ** S1
  488. :PROPERTIES:
  489. :A: 4:40
  490. :END:
  491. ** S1
  492. :PROPERTIES:
  493. :A: 1:20
  494. :END:"
  495. (let ((org-columns-default-format "%A{:mean}")) (org-columns))
  496. (get-char-property (point) 'org-columns-value-modified))))
  497. ;; {@min}, {@max} and {@mean} apply to ages.
  498. (should
  499. (equal
  500. "0min"
  501. (cl-letf (((symbol-function 'current-time)
  502. (lambda ()
  503. (apply #'encode-time
  504. (org-parse-time-string "<2014-03-04 Tue>")))))
  505. (org-test-with-temp-text
  506. "* H
  507. ** S1
  508. :PROPERTIES:
  509. :A: <2012-03-29 Thu>
  510. :END:
  511. ** S1
  512. :PROPERTIES:
  513. :A: <2014-03-04 Tue>
  514. :END:"
  515. (let ((org-columns-default-format "%A{@min}")) (org-columns))
  516. (get-char-property (point) 'org-columns-value-modified)))))
  517. (should
  518. (equal
  519. "2d"
  520. (cl-letf (((symbol-function 'current-time)
  521. (lambda ()
  522. (apply #'encode-time
  523. (org-parse-time-string "<2014-03-04 Tue>")))))
  524. (org-test-with-temp-text
  525. "* H
  526. ** S1
  527. :PROPERTIES:
  528. :A: <2014-03-03 Mon>
  529. :END:
  530. ** S1
  531. :PROPERTIES:
  532. :A: <2014-03-02 Sun>
  533. :END:"
  534. (let ((org-columns-default-format "%A{@max}")) (org-columns))
  535. (get-char-property (point) 'org-columns-value-modified)))))
  536. (should
  537. (equal
  538. "1d 12h"
  539. (cl-letf (((symbol-function 'current-time)
  540. (lambda ()
  541. (apply #'encode-time
  542. (org-parse-time-string "<2014-03-04 Tue>")))))
  543. (org-test-with-temp-text
  544. "* H
  545. ** S1
  546. :PROPERTIES:
  547. :A: <2014-03-03 Mon>
  548. :END:
  549. ** S1
  550. :PROPERTIES:
  551. :A: <2014-03-02 Sun>
  552. :END:"
  553. (let ((org-columns-default-format "%A{@mean}")) (org-columns))
  554. (get-char-property (point) 'org-columns-value-modified)))))
  555. ;; If a time value is expressed as a duration, return a duration.
  556. ;; If any of them follows H:MM:SS pattern, use it too. Also handle
  557. ;; combinations of duration and H:MM:SS patterns.
  558. (should
  559. (equal
  560. "3d 4:20"
  561. (org-test-with-temp-text
  562. "* H
  563. ** S1
  564. :PROPERTIES:
  565. :A: 3d 3h
  566. :END:
  567. ** S1
  568. :PROPERTIES:
  569. :A: 1:20
  570. :END:"
  571. (let ((org-columns-default-format "%A{:}")
  572. (org-duration-units '(("d" . 1440) ("h" . 60)))
  573. (org-duration-format '(("d" . nil) (special . h:mm))))
  574. (org-columns))
  575. (get-char-property (point) 'org-columns-value-modified))))
  576. (should
  577. (equal
  578. "6:00:10"
  579. (org-test-with-temp-text
  580. "* H
  581. ** S1
  582. :PROPERTIES:
  583. :A: 4:40:10
  584. :END:
  585. ** S1
  586. :PROPERTIES:
  587. :A: 1:20
  588. :END:"
  589. (let ((org-columns-default-format "%A{:}")) (org-columns))
  590. (get-char-property (point) 'org-columns-value-modified))))
  591. (should
  592. (equal
  593. "3d 4:20"
  594. (org-test-with-temp-text
  595. "* H
  596. ** S1
  597. :PROPERTIES:
  598. :A: 3d 3h
  599. :END:
  600. ** S1
  601. :PROPERTIES:
  602. :A: 0d 1:20
  603. :END:"
  604. (let ((org-columns-default-format "%A{:}")
  605. (org-duration-units '(("d" . 1440) ("h" . 60)))
  606. (org-duration-format '(("d" . nil) (special . h:mm))))
  607. (org-columns))
  608. (get-char-property (point) 'org-columns-value-modified))))
  609. ;; @min, @max and @mean also accept regular duration.
  610. (should
  611. (equal
  612. "1d 10h"
  613. (org-test-with-temp-text
  614. "* H
  615. ** S1
  616. :PROPERTIES:
  617. :A: 1d 10h 0min
  618. :END:
  619. ** S1
  620. :PROPERTIES:
  621. :A: 5d 3h
  622. :END:"
  623. (let ((org-columns-default-format "%A{@min}")) (org-columns))
  624. (get-char-property (point) 'org-columns-value-modified))))
  625. ;; {est+} gives a low-high estimate using mean and standard
  626. ;; deviation.
  627. (should
  628. (equal
  629. "3-17"
  630. (org-test-with-temp-text
  631. "* H
  632. ** S1
  633. :PROPERTIES:
  634. :A: 0-10
  635. :END:
  636. ** S1
  637. :PROPERTIES:
  638. :A: 0-10
  639. :END:"
  640. (let ((org-columns-default-format "%A{est+}")) (org-columns))
  641. (get-char-property (point) 'org-columns-value-modified))))
  642. ;; When using {est+} summary, a single number is understood as
  643. ;; a degenerate range.
  644. (should
  645. (equal
  646. "4-4"
  647. (org-test-with-temp-text
  648. "* H
  649. ** S1
  650. :PROPERTIES:
  651. :A: 4
  652. :END:
  653. "
  654. (let ((org-columns-default-format "%A{est+}")) (org-columns))
  655. (get-char-property (point) 'org-columns-value-modified))))
  656. ;; Allow custom summary types.
  657. (should
  658. (equal
  659. "1|2"
  660. (org-test-with-temp-text
  661. "* H
  662. ** S1
  663. :PROPERTIES:
  664. :A: 1
  665. :END:
  666. ** S1
  667. :PROPERTIES:
  668. :A: 2
  669. :END:"
  670. (let ((org-columns-summary-types
  671. '(("custom" . (lambda (s _) (mapconcat #'identity s "|")))))
  672. (org-columns-default-format "%A{custom}")) (org-columns))
  673. (get-char-property (point) 'org-columns-value-modified))))
  674. ;; Allow custom _collect_ for summary types.
  675. (should
  676. (equal
  677. "2"
  678. (org-test-with-temp-text
  679. "* H
  680. ** S1
  681. :PROPERTIES:
  682. :A: 1
  683. :END:
  684. ** S1
  685. :PROPERTIES:
  686. :A: 2
  687. :A-OK: 1
  688. :END:"
  689. (let ((org-columns-summary-types
  690. '(("custom" org-columns--summary-sum
  691. (lambda (p)
  692. (if (equal "1" (org-entry-get nil (format "%s-OK" p)))
  693. (org-entry-get nil p)
  694. "")))))
  695. (org-columns-default-format "%A{custom}")) (org-columns))
  696. (get-char-property (point) 'org-columns-value-modified))))
  697. ;; Allow custom collect function to be used for different columns
  698. (should
  699. (equal
  700. '("2" "1")
  701. (org-test-with-temp-text
  702. "* H
  703. ** S1
  704. :PROPERTIES:
  705. :A: 1
  706. :B: 1
  707. :B-OK: 1
  708. :END:
  709. ** S1
  710. :PROPERTIES:
  711. :A: 2
  712. :B: 2
  713. :A-OK: 1
  714. :END:"
  715. (let ((org-columns-summary-types
  716. '(("custom" org-columns--summary-sum
  717. (lambda (p)
  718. (if (equal "1" (org-entry-get nil (format "%s-OK" p)))
  719. (org-entry-get nil p)
  720. "")))))
  721. (org-columns-default-format "%A{custom} %B{custom}")) (org-columns))
  722. (list (get-char-property (point) 'org-columns-value-modified)
  723. (get-char-property (1+ (point)) 'org-columns-value-modified)))))
  724. ;; Allow multiple summary types applied to the same property.
  725. (should
  726. (equal
  727. '("42" "99")
  728. (org-test-with-temp-text
  729. "* H
  730. ** S1
  731. :PROPERTIES:
  732. :A: 99
  733. :END:
  734. ** S1
  735. :PROPERTIES:
  736. :A: 42
  737. :END:"
  738. (let ((org-columns-default-format "%A{min} %A{max}")) (org-columns))
  739. (list (get-char-property (point) 'org-columns-value-modified)
  740. (get-char-property (1+ (point)) 'org-columns-value-modified)))))
  741. ;; Allow mixing both summarized and non-summarized columns for
  742. ;; a property. However, the first column takes precedence and
  743. ;; updates the value.
  744. (should
  745. (equal
  746. '("1000" "42")
  747. (org-test-with-temp-text
  748. "* H
  749. :PROPERTIES:
  750. :A: 1000
  751. :END:
  752. ** S1
  753. :PROPERTIES:
  754. :A: 99
  755. :END:
  756. ** S1
  757. :PROPERTIES:
  758. :A: 42
  759. :END:"
  760. (let ((org-columns-default-format "%A %A{min}")) (org-columns))
  761. (list (get-char-property (point) 'org-columns-value-modified)
  762. (get-char-property (1+ (point)) 'org-columns-value-modified)))))
  763. (should
  764. (equal
  765. '("42" "42")
  766. (org-test-with-temp-text
  767. "* H
  768. :PROPERTIES:
  769. :A: 1000
  770. :END:
  771. ** S1
  772. :PROPERTIES:
  773. :A: 99
  774. :END:
  775. ** S1
  776. :PROPERTIES:
  777. :A: 42
  778. :END:"
  779. (let ((org-columns-default-format "%A{min} %A")) (org-columns))
  780. (list (get-char-property (point) 'org-columns-value-modified)
  781. (get-char-property (1+ (point)) 'org-columns-value-modified))))))
  782. (ert-deftest test-org-colview/columns-new ()
  783. "Test `org-columns-new' specifications."
  784. ;; Insert new column at the left of the current one.
  785. (should
  786. (equal '("FOO" "ITEM")
  787. (org-test-with-temp-text "* H"
  788. (let ((org-columns-default-format "%ITEM")) (org-columns))
  789. (org-columns-new nil "FOO" "FOO" nil nil nil)
  790. (list (get-char-property (point) 'org-columns-key)
  791. (get-char-property (1+ (point)) 'org-columns-key)))))
  792. (should
  793. (equal '("ITEM" "FOO" "BAR")
  794. (org-test-with-temp-text "* H"
  795. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  796. (forward-char)
  797. (org-columns-new nil "FOO" "FOO" nil nil nil)
  798. (list (get-char-property (1- (point)) 'org-columns-key)
  799. (get-char-property (point) 'org-columns-key)
  800. (get-char-property (1+ (point)) 'org-columns-key)))))
  801. ;; Update #+COLUMNS keyword if needed.
  802. (should
  803. (equal "#+COLUMNS: %FOO %ITEM"
  804. (org-test-with-temp-text "#+COLUMNS: %ITEM\n<point>* H"
  805. (let ((org-columns-default-format "%ITEM")) (org-columns))
  806. (org-columns-new nil "FOO" "FOO" nil nil nil)
  807. (goto-char (point-min))
  808. (buffer-substring-no-properties (point) (line-end-position)))))
  809. (should
  810. (equal "#+COLUMNS: %ITEM %FOO %BAR"
  811. (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
  812. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  813. (forward-char)
  814. (org-columns-new nil "FOO" "FOO" nil nil nil)
  815. (goto-char (point-min))
  816. (buffer-substring-no-properties (point) (line-end-position)))))
  817. ;; Mind case when updating #+COLUMNS.
  818. (should
  819. (equal "#+COLUMNS: %ITEM %Foo %BAR"
  820. (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
  821. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  822. (forward-char)
  823. (org-columns-new nil "Foo" "Foo" nil nil nil)
  824. (goto-char (point-min))
  825. (buffer-substring-no-properties (point) (line-end-position)))))
  826. (should
  827. (equal "#+columns: %ITEM %Foo %BAR"
  828. (org-test-with-temp-text "#+columns: %ITEM %BAR\n<point>* H"
  829. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  830. (forward-char)
  831. (org-columns-new nil "Foo" "Foo" nil nil nil)
  832. (goto-char (point-min))
  833. (buffer-substring-no-properties (point) (line-end-position)))))
  834. ;; Also update :COLUMNS: properties.
  835. (should
  836. (equal "%FOO %ITEM"
  837. (org-test-with-temp-text "* H\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:"
  838. (let ((org-columns-default-format "%ITEM")) (org-columns))
  839. (org-columns-new nil "FOO" "FOO" nil nil nil)
  840. (org-entry-get nil "COLUMNS"))))
  841. ;; If no keyword nor any property is available, insert one.
  842. (should
  843. (string-match-p (regexp-quote "#+COLUMNS: %FOO %ITEM")
  844. (org-test-with-temp-text "* H"
  845. (let ((org-columns-default-format "%ITEM")) (org-columns))
  846. (org-columns-new nil "FOO" "FOO" nil nil nil)
  847. (buffer-string)))))
  848. (ert-deftest test-org-colview/columns-update ()
  849. "Test `org-columns-update' specifications."
  850. ;; Update display.
  851. (should
  852. (equal
  853. "12 |"
  854. (org-test-with-temp-text
  855. "* H
  856. :PROPERTIES:
  857. :A: 1
  858. :END:
  859. "
  860. (let ((org-columns-default-format "%5A")) (org-columns))
  861. (search-forward "1")
  862. (insert "2")
  863. (org-columns-update "A")
  864. (get-char-property (point-min) 'display))))
  865. ;; Update is case-insensitive.
  866. (should
  867. (equal
  868. "12 |"
  869. (org-test-with-temp-text
  870. "* H
  871. :PROPERTIES:
  872. :A: 1
  873. :END:
  874. "
  875. (let ((org-columns-default-format "%5A")) (org-columns))
  876. (search-forward "1")
  877. (insert "2")
  878. (org-columns-update "a")
  879. (get-char-property (point-min) 'display))))
  880. ;; Update stored values.
  881. (should
  882. (equal
  883. '("12" "12")
  884. (org-test-with-temp-text
  885. "* H
  886. :PROPERTIES:
  887. :A: 1
  888. :END:
  889. "
  890. (let ((org-columns-default-format "%5A")) (org-columns))
  891. (search-forward "1")
  892. (insert "2")
  893. (org-columns-update "A")
  894. (list (get-char-property (point-min) 'org-columns-value)
  895. (get-char-property (point-min) 'org-columns-value-modified)))))
  896. ;; When multiple columns are using the same property, value is
  897. ;; updated according to the specifications of the first one.
  898. (should
  899. (equal
  900. "2"
  901. (org-test-with-temp-text
  902. "* H
  903. :PROPERTIES:
  904. :A: 1
  905. :END:
  906. ** S
  907. :PROPERTIES:
  908. :A: 2
  909. :END:"
  910. (let ((org-columns-default-format "%A{min} %A")) (org-columns))
  911. (org-columns-update "A")
  912. (org-entry-get nil "A"))))
  913. (should
  914. (equal
  915. "1"
  916. (org-test-with-temp-text
  917. "* H
  918. :PROPERTIES:
  919. :A: 1
  920. :END:
  921. ** S
  922. :PROPERTIES:
  923. :A: 2
  924. :END:"
  925. (let ((org-columns-default-format "%A %A{min}")) (org-columns))
  926. (org-columns-update "A")
  927. (org-entry-get nil "A"))))
  928. ;; Ensure modifications propagate in upper levels even when multiple
  929. ;; summary types apply to the same property.
  930. (should
  931. (equal
  932. '("1" "22")
  933. (org-test-with-temp-text
  934. "* H
  935. ** S1
  936. :PROPERTIES:
  937. :A: 1
  938. :END:
  939. ** S2
  940. :PROPERTIES:
  941. :A: <point>2
  942. :END:"
  943. (save-excursion
  944. (goto-char (point-min))
  945. (let ((org-columns-default-format "%A{min} %A{max}")) (org-columns)))
  946. (insert "2")
  947. (org-columns-update "A")
  948. (list (get-char-property 1 'org-columns-value)
  949. (get-char-property 2 'org-columns-value-modified)))))
  950. ;; Ensure additional processing is done (e.g., ellipses, special
  951. ;; keywords fontification...).
  952. (should
  953. (equal
  954. "ve.. |"
  955. (org-test-with-temp-text
  956. "* H
  957. :PROPERTIES:
  958. :A: text
  959. :END:
  960. "
  961. (let ((org-columns-default-format "%4A")
  962. (org-columns-ellipses ".."))
  963. (org-columns))
  964. (search-forward ":A: ")
  965. (insert "very long ")
  966. (org-columns-update "A")
  967. (get-char-property (point-min) 'display))))
  968. ;; Values obtained from inline tasks are at the same level as those
  969. ;; obtained from children of the current node.
  970. (when (featurep 'org-inlinetask)
  971. (should
  972. (equal
  973. "2"
  974. (org-test-with-temp-text
  975. "* H
  976. *************** Inline task
  977. :PROPERTIES:
  978. :A: 2
  979. :END:
  980. *************** END
  981. ** Children
  982. :PROPERTIES:
  983. :A: 3
  984. :END:
  985. "
  986. (let ((org-columns-default-format "%A{min}")
  987. (org-columns-ellipses "..")
  988. (org-inlinetask-min-level 15))
  989. (org-columns))
  990. (get-char-property (point-min) 'org-columns-value)))))
  991. ;; Handle `org-columns-modify-value-for-display-function', even with
  992. ;; multiple titles for the same property.
  993. (should
  994. (equal '("foo" "bar")
  995. (org-test-with-temp-text "* H"
  996. (let ((org-columns-default-format "%ITEM %ITEM(Name)")
  997. (org-columns-modify-value-for-display-function
  998. (lambda (title value)
  999. (pcase title ("ITEM" "foo") ("Name" "bar") (_ "baz")))))
  1000. (org-columns))
  1001. (list (get-char-property 1 'org-columns-value-modified)
  1002. (get-char-property 2 'org-columns-value-modified))))))
  1003. (ert-deftest test-org-colview/columns-move-left ()
  1004. "Test `org-columns-move-left' specifications."
  1005. ;; Error when trying to move the left-most column.
  1006. (should-error
  1007. (org-test-with-temp-text "* H"
  1008. (let ((org-columns-default-format "%ITEM")) (org-columns))
  1009. (org-columns-move-left)))
  1010. ;; Otherwise, move column to left and update display.
  1011. (should
  1012. (equal '("2" "1")
  1013. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  1014. (let ((org-columns-default-format "%A %B")) (org-columns))
  1015. (forward-char)
  1016. (org-columns-move-left)
  1017. (list (get-char-property (point) 'org-columns-value)
  1018. (get-char-property (1+ (point)) 'org-columns-value)))))
  1019. ;; Handle multiple columns with the same property.
  1020. (should
  1021. (equal '("2" "1")
  1022. (org-test-with-temp-text
  1023. "* H
  1024. ** S1
  1025. :PROPERTIES:
  1026. :A: 1
  1027. :END:
  1028. ** S1
  1029. :PROPERTIES:
  1030. :A: 2
  1031. :END:"
  1032. (let ((org-columns-default-format "%ITEM %A{min} %A{max}"))
  1033. (org-columns))
  1034. (forward-char 2)
  1035. (org-columns-move-left)
  1036. (list (get-char-property (point) 'org-columns-value)
  1037. (get-char-property (1+ (point)) 'org-columns-value)))))
  1038. ;; Special case: do not update values even if move entails changing
  1039. ;; them.
  1040. (should
  1041. (equal "1"
  1042. (org-test-with-temp-text
  1043. "* H
  1044. :PROPERTIES:
  1045. :A: 1
  1046. :END:
  1047. ** S1
  1048. :PROPERTIES:
  1049. :A: 99
  1050. :END:"
  1051. (let ((org-columns-default-format "%A %A{max}"))
  1052. (org-columns))
  1053. (forward-char)
  1054. (org-columns-move-left)
  1055. ;; Since the first column matching a given property
  1056. ;; determines how a value is computed, the following
  1057. ;; should return "99" instead. However, this behavior is
  1058. ;; in practice surprising so we just ignore the value
  1059. ;; change. It can be computed later.
  1060. (org-entry-get (point) "A")))))
  1061. (ert-deftest test-org-colview/columns-move-right ()
  1062. "Test `org-columns-move-right' specifications."
  1063. ;; Error when trying to move the right-most column.
  1064. (should-error
  1065. (org-test-with-temp-text "* H"
  1066. (let ((org-columns-default-format "%ITEM")) (org-columns))
  1067. (org-columns-move-right)))
  1068. ;; Otherwise, move column to left and update display.
  1069. (should
  1070. (equal '("2" "1")
  1071. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:B: 2\n:END:"
  1072. (let ((org-columns-default-format "%A %B")) (org-columns))
  1073. (org-columns-move-right)
  1074. (list (get-char-property (1- (point)) 'org-columns-value)
  1075. (get-char-property (point) 'org-columns-value)))))
  1076. ;; Handle multiple columns with the same property.
  1077. (should
  1078. (equal '("2" "1")
  1079. (org-test-with-temp-text
  1080. "* H
  1081. ** S1
  1082. :PROPERTIES:
  1083. :A: 1
  1084. :END:
  1085. ** S1
  1086. :PROPERTIES:
  1087. :A: 2
  1088. :END:"
  1089. (let ((org-columns-default-format "%ITEM %A{min} %A{max}"))
  1090. (org-columns))
  1091. (forward-char)
  1092. (org-columns-move-right)
  1093. (list (get-char-property (1- (point)) 'org-columns-value)
  1094. (get-char-property (point) 'org-columns-value)))))
  1095. ;; Special case: do not update values even if move entails changing
  1096. ;; them.
  1097. (should
  1098. (equal "1"
  1099. (org-test-with-temp-text
  1100. "* H
  1101. :PROPERTIES:
  1102. :A: 1
  1103. :END:
  1104. ** S1
  1105. :PROPERTIES:
  1106. :A: 99
  1107. :END:"
  1108. (let ((org-columns-default-format "%A %A{max}"))
  1109. (org-columns))
  1110. (org-columns-move-right)
  1111. ;; See `test-org-colview/columns-move-left' for an
  1112. ;; explanation.
  1113. (org-entry-get (point) "A")))))
  1114. (ert-deftest test-org-colview/columns-next-allowed-value ()
  1115. "Test `org-columns-next-allowed-value' specifications."
  1116. ;; Cannot shift "ITEM" property.
  1117. (should-error
  1118. (org-test-with-temp-text "* H"
  1119. (let ((org-columns-default-format "%ITEM")) (org-columns))
  1120. (org-columns-next-allowed-value)))
  1121. ;; Throw an error when allowed values are not defined.
  1122. (should-error
  1123. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:END:"
  1124. (let ((org-columns-default-format "%A")) (org-columns))
  1125. (org-columns-next-allowed-value)))
  1126. ;; Throw an error when there's only one value to select.
  1127. (should-error
  1128. (org-test-with-temp-text "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1\n:END:"
  1129. (let ((org-columns-default-format "%A")) (org-columns))
  1130. (org-columns-next-allowed-value)))
  1131. ;; By default select the next allowed value. Where there is no more
  1132. ;; value, start again from first possible one.
  1133. (should
  1134. (equal "2"
  1135. (org-test-with-temp-text
  1136. "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1 2 3\n:END:"
  1137. (let ((org-columns-default-format "%A")) (org-columns))
  1138. (org-columns-next-allowed-value)
  1139. (org-entry-get (point) "A"))))
  1140. (should
  1141. (equal "3"
  1142. (org-test-with-temp-text
  1143. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1144. (let ((org-columns-default-format "%A")) (org-columns))
  1145. (org-columns-next-allowed-value)
  1146. (org-entry-get (point) "A"))))
  1147. (should
  1148. (equal "1"
  1149. (org-test-with-temp-text
  1150. "* H\n:PROPERTIES:\n:A: 3\n:A_ALL: 1 2 3\n:END:"
  1151. (let ((org-columns-default-format "%A")) (org-columns))
  1152. (org-columns-next-allowed-value)
  1153. (org-entry-get (point) "A"))))
  1154. ;; PREVIOUS argument moves backward.
  1155. (should
  1156. (equal "1"
  1157. (org-test-with-temp-text
  1158. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1159. (let ((org-columns-default-format "%A")) (org-columns))
  1160. (org-columns-next-allowed-value 'previous)
  1161. (org-entry-get (point) "A"))))
  1162. (should
  1163. (equal "2"
  1164. (org-test-with-temp-text
  1165. "* H\n:PROPERTIES:\n:A: 3\n:A_ALL: 1 2 3\n:END:"
  1166. (let ((org-columns-default-format "%A")) (org-columns))
  1167. (org-columns-next-allowed-value 'previous)
  1168. (org-entry-get (point) "A"))))
  1169. (should
  1170. (equal "3"
  1171. (org-test-with-temp-text
  1172. "* H\n:PROPERTIES:\n:A: 1\n:A_ALL: 1 2 3\n:END:"
  1173. (let ((org-columns-default-format "%A")) (org-columns))
  1174. (org-columns-next-allowed-value 'previous)
  1175. (org-entry-get (point) "A"))))
  1176. ;; Select Nth element with optional argument NTH.
  1177. (should
  1178. (equal "1"
  1179. (org-test-with-temp-text
  1180. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1181. (let ((org-columns-default-format "%A")) (org-columns))
  1182. (org-columns-next-allowed-value nil 1)
  1183. (org-entry-get (point) "A"))))
  1184. ;; If NTH is negative, go backwards, 0 being the last one and -1 the
  1185. ;; penultimate.
  1186. (should
  1187. (equal "3"
  1188. (org-test-with-temp-text
  1189. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1190. (let ((org-columns-default-format "%A")) (org-columns))
  1191. (org-columns-next-allowed-value nil 0)
  1192. (org-entry-get (point) "A"))))
  1193. (should
  1194. (equal "2"
  1195. (org-test-with-temp-text
  1196. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1197. (let ((org-columns-default-format "%A")) (org-columns))
  1198. (org-columns-next-allowed-value nil -1)
  1199. (org-entry-get (point) "A"))))
  1200. ;; Throw an error if NTH is greater than the number of allowed
  1201. ;; values.
  1202. (should-error
  1203. (org-test-with-temp-text
  1204. "* H\n:PROPERTIES:\n:A: 2\n:A_ALL: 1 2 3\n:END:"
  1205. (let ((org-columns-default-format "%A")) (org-columns))
  1206. (org-columns-next-allowed-value nil 4)
  1207. (org-entry-get (point) "A")))
  1208. ;; Pathological case: when shifting the value alters the current
  1209. ;; heading, make sure all columns are still at their correct
  1210. ;; location.
  1211. (should
  1212. (equal '("H" "" "" "" "TODO")
  1213. (let ((org-todo-keywords '((sequence "TODO" "DONE"))))
  1214. (org-test-with-temp-text "* H"
  1215. (let ((org-columns-default-format "%ITEM %A %B %C %TODO"))
  1216. (org-columns)
  1217. (forward-char 4)
  1218. (org-columns-next-allowed-value)
  1219. (list (get-char-property (- (point) 4) 'org-columns-value)
  1220. (get-char-property (- (point) 3) 'org-columns-value)
  1221. (get-char-property (- (point) 2) 'org-columns-value)
  1222. (get-char-property (- (point) 1) 'org-columns-value)
  1223. (get-char-property (point) 'org-columns-value)))))))
  1224. (should
  1225. (equal '("H" "VERYLONGTODO")
  1226. (let ((org-todo-keywords '((sequence "TODO" "VERYLONGTODO"))))
  1227. (org-test-with-temp-text "* TODO H"
  1228. (let ((org-columns-default-format "%ITEM %TODO"))
  1229. (org-columns)
  1230. (forward-char)
  1231. (org-columns-next-allowed-value)
  1232. (list (get-char-property (- (point) 1) 'org-columns-value)
  1233. (get-char-property (point) 'org-columns-value))))))))
  1234. ;;; Dynamic block
  1235. (ert-deftest test-org-colview/dblock ()
  1236. "Test the column view table."
  1237. (should
  1238. (equal
  1239. "#+BEGIN: columnview
  1240. | ITEM |
  1241. |------|
  1242. | H |
  1243. #+END:"
  1244. (org-test-with-temp-text
  1245. "* H\n<point>#+BEGIN: columnview\n#+END:"
  1246. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1247. (buffer-substring-no-properties (point) (point-max)))))
  1248. (should
  1249. (equal
  1250. "#+BEGIN: columnview
  1251. | ITEM | A |
  1252. |------+---|
  1253. | H | 1 |
  1254. #+END:"
  1255. (org-test-with-temp-text
  1256. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  1257. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  1258. (buffer-substring-no-properties (point) (point-max)))))
  1259. ;; Properties are case insensitive.
  1260. (should
  1261. (equal
  1262. "#+BEGIN: columnview
  1263. | a |
  1264. |---|
  1265. | 1 |
  1266. #+END:"
  1267. (org-test-with-temp-text
  1268. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  1269. (let ((org-columns-default-format "%a")) (org-update-dblock))
  1270. (buffer-substring-no-properties (point) (point-max)))))
  1271. ;; Test titles given to columns.
  1272. (should
  1273. (equal
  1274. "#+BEGIN: columnview
  1275. | Name | Prop |
  1276. |------+------|
  1277. | H | 1 |
  1278. #+END:"
  1279. (org-test-with-temp-text
  1280. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  1281. (let ((org-columns-default-format "%ITEM(Name) %A(Prop)"))
  1282. (org-update-dblock))
  1283. (buffer-substring-no-properties (point) (point-max)))))
  1284. ;; Test `:id' parameter
  1285. (should
  1286. (equal
  1287. "#+BEGIN: columnview :id local
  1288. | ITEM |
  1289. |------|
  1290. | H1 |
  1291. | H1.1 |
  1292. #+END:
  1293. "
  1294. (org-test-with-temp-text
  1295. "* H1\n<point>#+BEGIN: columnview :id local\n#+END:\n** H1.1\n* H2"
  1296. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1297. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1298. (should
  1299. (equal
  1300. "#+BEGIN: columnview :id global
  1301. | ITEM |
  1302. |------|
  1303. | H1 |
  1304. | H1.1 |
  1305. | H2 |
  1306. #+END:
  1307. "
  1308. (org-test-with-temp-text
  1309. "\n* H1\n<point>#+BEGIN: columnview :id global\n#+END:\n** H1.1\n* H2"
  1310. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1311. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1312. ;; Test `:hlines' parameter.
  1313. (should
  1314. (equal
  1315. "#+BEGIN: columnview :hlines t :id global
  1316. | ITEM |
  1317. |------|
  1318. | H |
  1319. |------|
  1320. | H2 |
  1321. |------|
  1322. | H2.1 |
  1323. #+END:\n"
  1324. (org-test-with-temp-text
  1325. "
  1326. * H
  1327. <point>#+BEGIN: columnview :hlines t :id global
  1328. #+END:
  1329. * H2
  1330. ** H2.1"
  1331. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1332. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1333. (should
  1334. (equal
  1335. "#+BEGIN: columnview :hlines 1 :id global
  1336. | ITEM |
  1337. |------|
  1338. | H |
  1339. |------|
  1340. | H2 |
  1341. | H2.1 |
  1342. #+END:\n"
  1343. (org-test-with-temp-text
  1344. "
  1345. * H
  1346. <point>#+BEGIN: columnview :hlines 1 :id global
  1347. #+END:
  1348. * H2
  1349. ** H2.1"
  1350. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1351. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1352. (should
  1353. (equal
  1354. "#+BEGIN: columnview :hlines 1 :id \"id\"
  1355. | ITEM |
  1356. |------|
  1357. | H2 |
  1358. | H2.1 |
  1359. #+END:
  1360. "
  1361. (org-test-with-temp-text
  1362. "
  1363. * H
  1364. <point>#+BEGIN: columnview :hlines 1 :id \"id\"
  1365. #+END:
  1366. * H2
  1367. :PROPERTIES:
  1368. :ID: id
  1369. :END:
  1370. ** H2.1"
  1371. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1372. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1373. (should
  1374. (equal
  1375. "#+BEGIN: columnview :hlines 1 :id id
  1376. | ITEM |
  1377. |------|
  1378. | H2 |
  1379. | H2.1 |
  1380. #+END:
  1381. "
  1382. (org-test-with-temp-text
  1383. "
  1384. * H
  1385. <point>#+BEGIN: columnview :hlines 1 :id id
  1386. #+END:
  1387. * H2
  1388. :PROPERTIES:
  1389. :ID: id
  1390. :END:
  1391. ** H2.1"
  1392. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1393. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1394. ;; Test `:indent' parameter.
  1395. (should
  1396. (equal
  1397. "#+BEGIN: columnview :indent t
  1398. | ITEM |
  1399. |----------|
  1400. | H1 |
  1401. | \\_ H1.1 |
  1402. #+END:
  1403. "
  1404. (org-test-with-temp-text
  1405. "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
  1406. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1407. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1408. (should
  1409. (equal
  1410. "#+BEGIN: columnview :indent t
  1411. | Prop | Name |
  1412. |------+----------|
  1413. | | H1 |
  1414. | | \\_ H1.1 |
  1415. #+END:
  1416. "
  1417. (org-test-with-temp-text
  1418. "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
  1419. (let ((org-columns-default-format "%A(Prop) %ITEM(Name)"))
  1420. (org-update-dblock))
  1421. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1422. ;; Test `:vlines' parameter.
  1423. (should
  1424. (equal
  1425. "#+BEGIN: columnview :vlines t
  1426. | | ITEM | A |
  1427. |---+------+----|
  1428. | | H | 1 |
  1429. | / | <> | <> |
  1430. #+END:"
  1431. (org-test-with-temp-text
  1432. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview :vlines t\n#+END:"
  1433. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  1434. (buffer-substring-no-properties (point) (point-max)))))
  1435. ;; Test `:skip-empty-rows' parameter.
  1436. (should
  1437. (equal
  1438. "#+BEGIN: columnview :skip-empty-rows t
  1439. | ITEM | A |
  1440. |------+---|
  1441. | H1.1 | 1 |
  1442. #+END:
  1443. "
  1444. (org-test-with-temp-text
  1445. "
  1446. * H1
  1447. <point>#+BEGIN: columnview :skip-empty-rows t
  1448. #+END:
  1449. ** H1.1
  1450. :PROPERTIES:
  1451. :A: 1
  1452. :END:"
  1453. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  1454. (buffer-substring-no-properties (point) (outline-next-heading)))))
  1455. ;; Test `:format' parameter.
  1456. (should
  1457. (equal
  1458. "#+BEGIN: columnview :format \"%ITEM(Name)\"
  1459. | Name |
  1460. |------|
  1461. | H |
  1462. #+END:"
  1463. (org-test-with-temp-text
  1464. "* H\n<point>#+BEGIN: columnview :format \"%ITEM(Name)\"\n#+END:"
  1465. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1466. (buffer-substring-no-properties (point) (point-max)))))
  1467. ;; When inserting ITEM values, make sure to clean sensitive
  1468. ;; contents, like unique targets or forbidden inline src-blocks.
  1469. (should
  1470. (equal
  1471. "#+BEGIN: columnview
  1472. | ITEM |
  1473. |------|
  1474. | H 1 |
  1475. #+END:"
  1476. (org-test-with-temp-text
  1477. "* H <<target>> 1\n<point>#+BEGIN: columnview\n#+END:"
  1478. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1479. (buffer-substring-no-properties (point) (point-max)))))
  1480. (should
  1481. (equal
  1482. "#+BEGIN: columnview
  1483. | ITEM |
  1484. |------|
  1485. | H 1 |
  1486. #+END:"
  1487. (org-test-with-temp-text
  1488. "* H src_emacs-lisp{(+ 1 1)} 1\n<point>#+BEGIN: columnview\n#+END:"
  1489. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  1490. (buffer-substring-no-properties (point) (point-max))))))
  1491. (provide 'test-org-colview)
  1492. ;;; test-org-colview.el ends here