test-org-colview.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894
  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/columns-scope ()
  18. "Test `org-columns' scope."
  19. ;; Before the first headline, view all document.
  20. (should
  21. (equal
  22. '("H1" "H2" "H3")
  23. (org-test-with-temp-text "Top\n* H1\n** H2\n* H3"
  24. (let ((org-columns-default-format "%ITEM")) (org-columns))
  25. (org-map-entries
  26. (lambda () (get-char-property (point) 'org-columns-value))))))
  27. ;; When :COLUMNS: is set up in the hierarchy, view tree starting
  28. ;; there.
  29. (should
  30. (equal
  31. '(nil "H2" "H3" nil)
  32. (org-test-with-temp-text
  33. "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
  34. (let ((org-columns-default-format "%ITEM")) (org-columns))
  35. (org-map-entries
  36. (lambda () (get-char-property (point) 'org-columns-value))))))
  37. ;; Otherwise, view tree starting at the current headline.
  38. (should
  39. (equal
  40. '(nil "H2" "H3" nil)
  41. (org-test-with-temp-text "Top\n* H1\n** <point>H2\n*** H3\n* H4"
  42. (let ((org-columns-default-format "%ITEM")) (org-columns))
  43. (org-map-entries
  44. (lambda () (get-char-property (point) 'org-columns-value))))))
  45. ;; With a non-nil prefix argument, always view all document.
  46. (should
  47. (equal
  48. '("H1" "H2" "H3" "H4")
  49. (org-test-with-temp-text
  50. "* H1\n** H2\n:PROPERTIES:\n:COLUMNS: %ITEM\n:END:\n*** <point>H3\n* H4"
  51. (let ((org-columns-default-format "%ITEM")) (org-columns t))
  52. (org-map-entries
  53. (lambda () (get-char-property (point) 'org-columns-value))))))
  54. (should
  55. (equal
  56. '("H1" "H2" "H3" "H4")
  57. (org-test-with-temp-text "Top\n* H1\n** <point>H2\n*** H3\n* H4"
  58. (let ((org-columns-default-format "%ITEM")) (org-columns t))
  59. (org-map-entries
  60. (lambda () (get-char-property (point) 'org-columns-value)))))))
  61. (ert-deftest test-org-colview/columns-width ()
  62. "Test `org-columns' column widths."
  63. ;; When a width is specified in the format, use it.
  64. (should
  65. (= 9
  66. (org-test-with-temp-text "* H"
  67. (let ((org-columns-default-format "%9ITEM")) (org-columns))
  68. (cdar org-columns-current-maxwidths))))
  69. ;; Otherwise, use the width of the largest value in the column.
  70. (should
  71. (= 2
  72. (org-test-with-temp-text
  73. "* H\n:PROPERTIES:\n:P: X\n:END:\n** H2\n:PROPERTIES:\n:P: XX\n:END:"
  74. (let ((org-columns-default-format "%P")) (org-columns))
  75. (cdar org-columns-current-maxwidths))))
  76. ;; If the title is wider than the widest value, use title width
  77. ;; instead.
  78. (should
  79. (= 4
  80. (org-test-with-temp-text "* H"
  81. (let ((org-columns-default-format "%ITEM")) (org-columns))
  82. (cdar org-columns-current-maxwidths))))
  83. ;; Special case: stars do count for ITEM.
  84. (should
  85. (= 6
  86. (org-test-with-temp-text "* Head"
  87. (let ((org-columns-default-format "%ITEM")) (org-columns))
  88. (cdar org-columns-current-maxwidths))))
  89. ;; Special case: width takes into account link narrowing in ITEM.
  90. (should
  91. (equal
  92. '("* [123]" . 7)
  93. (org-test-with-temp-text "* [[http://orgmode.org][123]]"
  94. (let ((org-columns-default-format "%ITEM")) (org-columns))
  95. (cons (get-char-property (point) 'org-columns-value-modified)
  96. (cdar org-columns-current-maxwidths)))))
  97. ;; When a value is too wide for the current column, add ellipses.
  98. ;; Take into consideration length of `org-columns-ellipses'.
  99. (should
  100. (equal "123.. |"
  101. (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
  102. (let ((org-columns-default-format "%5P")
  103. (org-columns-ellipses ".."))
  104. (org-columns))
  105. (org-trim (get-char-property (point) 'display)))))
  106. (should
  107. (equal "1234… |"
  108. (org-test-with-temp-text "* H\n:PROPERTIES:\n:P: 123456\n:END:"
  109. (let ((org-columns-default-format "%5P")
  110. (org-columns-ellipses "…"))
  111. (org-columns))
  112. (org-trim (get-char-property (point) 'display))))))
  113. (ert-deftest test-org-colview/columns-summary ()
  114. "Test `org-columns' summary types."
  115. ;; {+} and {+;format} add numbers.
  116. (should
  117. (equal
  118. "3"
  119. (org-test-with-temp-text
  120. "* H
  121. ** S1
  122. :PROPERTIES:
  123. :A: 1
  124. :END:
  125. ** S1
  126. :PROPERTIES:
  127. :A: 2
  128. :END:"
  129. (let ((org-columns-default-format "%A{+}")) (org-columns))
  130. (get-char-property (point) 'org-columns-value-modified))))
  131. (should
  132. (equal
  133. "3.0"
  134. (org-test-with-temp-text
  135. "* H
  136. ** S1
  137. :PROPERTIES:
  138. :A: 1
  139. :END:
  140. ** S1
  141. :PROPERTIES:
  142. :A: 2
  143. :END:"
  144. (let ((org-columns-default-format "%A{+;%.1f}")) (org-columns))
  145. (get-char-property (point) 'org-columns-value-modified))))
  146. ;; {$} is a shortcut for {+;%.2f}.
  147. (should
  148. (equal
  149. "3.60"
  150. (org-test-with-temp-text
  151. "* H
  152. ** S1
  153. :PROPERTIES:
  154. :A: 1.50
  155. :END:
  156. ** S1
  157. :PROPERTIES:
  158. :A: 2.10
  159. :END:"
  160. (let ((org-columns-default-format "%A{$}")) (org-columns))
  161. (get-char-property (point) 'org-columns-value-modified))))
  162. ;; {:} sums times. Plain numbers are hours.
  163. (should
  164. (equal
  165. "4:10"
  166. (org-test-with-temp-text
  167. "* H
  168. ** S1
  169. :PROPERTIES:
  170. :A: 1:30
  171. :END:
  172. ** S1
  173. :PROPERTIES:
  174. :A: 2:40
  175. :END:"
  176. (let ((org-columns-default-format "%A{:}")) (org-columns))
  177. (get-char-property (point) 'org-columns-value-modified))))
  178. (should
  179. (equal
  180. "3:30"
  181. (org-test-with-temp-text
  182. "* H
  183. ** S1
  184. :PROPERTIES:
  185. :A: 1:30
  186. :END:
  187. ** S1
  188. :PROPERTIES:
  189. :A: 2
  190. :END:"
  191. (let ((org-columns-default-format "%A{:}")) (org-columns))
  192. (get-char-property (point) 'org-columns-value-modified))))
  193. ;; {X}, {X/} and {X%} indicate checkbox status.
  194. (should
  195. (equal
  196. "[ ]"
  197. (org-test-with-temp-text
  198. "* H
  199. ** S1
  200. :PROPERTIES:
  201. :A: [ ]
  202. :END:
  203. ** S1
  204. :PROPERTIES:
  205. :A: [ ]
  206. :END:"
  207. (let ((org-columns-default-format "%A{X}")) (org-columns))
  208. (get-char-property (point) 'org-columns-value-modified))))
  209. (should
  210. (equal
  211. "[-]"
  212. (org-test-with-temp-text
  213. "* H
  214. ** S1
  215. :PROPERTIES:
  216. :A: [ ]
  217. :END:
  218. ** S1
  219. :PROPERTIES:
  220. :A: [X]
  221. :END:"
  222. (let ((org-columns-default-format "%A{X}")) (org-columns))
  223. (get-char-property (point) 'org-columns-value-modified))))
  224. (should
  225. (equal
  226. "[X]"
  227. (org-test-with-temp-text
  228. "* H
  229. ** S1
  230. :PROPERTIES:
  231. :A: [X]
  232. :END:
  233. ** S1
  234. :PROPERTIES:
  235. :A: [X]
  236. :END:"
  237. (let ((org-columns-default-format "%A{X}")) (org-columns))
  238. (get-char-property (point) 'org-columns-value-modified))))
  239. (should
  240. (equal
  241. "[1/2]"
  242. (org-test-with-temp-text
  243. "* H
  244. ** S1
  245. :PROPERTIES:
  246. :A: [ ]
  247. :END:
  248. ** S1
  249. :PROPERTIES:
  250. :A: [X]
  251. :END:"
  252. (let ((org-columns-default-format "%A{X/}")) (org-columns))
  253. (get-char-property (point) 'org-columns-value-modified))))
  254. (should
  255. (equal
  256. "[50%]"
  257. (org-test-with-temp-text
  258. "* H
  259. ** S1
  260. :PROPERTIES:
  261. :A: [ ]
  262. :END:
  263. ** S1
  264. :PROPERTIES:
  265. :A: [X]
  266. :END:"
  267. (let ((org-columns-default-format "%A{X%}")) (org-columns))
  268. (get-char-property (point) 'org-columns-value-modified))))
  269. ;; {min} is the smallest number in column, {max} the largest one.
  270. ;; {mean} is the arithmetic mean of numbers in column.
  271. (should
  272. (equal
  273. "42"
  274. (org-test-with-temp-text
  275. "* H
  276. ** S1
  277. :PROPERTIES:
  278. :A: 99
  279. :END:
  280. ** S1
  281. :PROPERTIES:
  282. :A: 42
  283. :END:"
  284. (let ((org-columns-default-format "%A{min}")) (org-columns))
  285. (get-char-property (point) 'org-columns-value-modified))))
  286. (should
  287. (equal
  288. "99"
  289. (org-test-with-temp-text
  290. "* H
  291. ** S1
  292. :PROPERTIES:
  293. :A: 99
  294. :END:
  295. ** S1
  296. :PROPERTIES:
  297. :A: 42
  298. :END:"
  299. (let ((org-columns-default-format "%A{max}")) (org-columns))
  300. (get-char-property (point) 'org-columns-value-modified))))
  301. (should
  302. (equal
  303. "51.0"
  304. (org-test-with-temp-text
  305. "* H
  306. ** S1
  307. :PROPERTIES:
  308. :A: 60
  309. :END:
  310. ** S1
  311. :PROPERTIES:
  312. :A: 42
  313. :END:"
  314. (let ((org-columns-default-format "%A{mean}")) (org-columns))
  315. (get-char-property (point) 'org-columns-value-modified))))
  316. ;; {:min}, {:max} and {:mean} apply to time values.
  317. (should
  318. (equal
  319. "1:20"
  320. (org-test-with-temp-text
  321. "* H
  322. ** S1
  323. :PROPERTIES:
  324. :A: 4:40
  325. :END:
  326. ** S1
  327. :PROPERTIES:
  328. :A: 1:20
  329. :END:"
  330. (let ((org-columns-default-format "%A{:min}")) (org-columns))
  331. (get-char-property (point) 'org-columns-value-modified))))
  332. (should
  333. (equal
  334. "4:40"
  335. (org-test-with-temp-text
  336. "* H
  337. ** S1
  338. :PROPERTIES:
  339. :A: 4:40
  340. :END:
  341. ** S1
  342. :PROPERTIES:
  343. :A: 1:20
  344. :END:"
  345. (let ((org-columns-default-format "%A{:max}")) (org-columns))
  346. (get-char-property (point) 'org-columns-value-modified))))
  347. (should
  348. (equal
  349. "3:00"
  350. (org-test-with-temp-text
  351. "* H
  352. ** S1
  353. :PROPERTIES:
  354. :A: 4:40
  355. :END:
  356. ** S1
  357. :PROPERTIES:
  358. :A: 1:20
  359. :END:"
  360. (let ((org-columns-default-format "%A{:mean}")) (org-columns))
  361. (get-char-property (point) 'org-columns-value-modified))))
  362. ;; {@min}, {@max} and {@mean} apply to ages.
  363. (should
  364. (equal
  365. (let ((org-columns--time (float-time (current-time))))
  366. (org-columns--summary-min-age (list "<2014-03-04 Tue>") nil))
  367. (org-test-with-temp-text
  368. "* H
  369. ** S1
  370. :PROPERTIES:
  371. :A: <2012-03-29 Thu>
  372. :END:
  373. ** S1
  374. :PROPERTIES:
  375. :A: <2014-03-04 Tue>
  376. :END:"
  377. (let ((org-columns-default-format "%A{@min}")) (org-columns))
  378. (get-char-property (point) 'org-columns-value-modified))))
  379. (should
  380. (equal
  381. (let ((org-columns--time (float-time (current-time))))
  382. (org-columns--summary-max-age (list "<2012-03-29 Thu>") nil))
  383. (org-test-with-temp-text
  384. "* H
  385. ** S1
  386. :PROPERTIES:
  387. :A: <2012-03-29 Thu>
  388. :END:
  389. ** S1
  390. :PROPERTIES:
  391. :A: <2014-03-04 Tue>
  392. :END:"
  393. (let ((org-columns-default-format "%A{@max}")) (org-columns))
  394. (get-char-property (point) 'org-columns-value-modified))))
  395. (should
  396. (equal
  397. (let ((org-columns--time (float-time (current-time))))
  398. (org-columns--summary-mean-age
  399. (list "<2012-03-29 Thu>" "<2014-03-04 Tue>") nil))
  400. (org-test-with-temp-text
  401. "* H
  402. ** S1
  403. :PROPERTIES:
  404. :A: <2012-03-29 Thu>
  405. :END:
  406. ** S1
  407. :PROPERTIES:
  408. :A: <2014-03-04 Tue>
  409. :END:"
  410. (let ((org-columns-default-format "%A{@mean}")) (org-columns))
  411. (get-char-property (point) 'org-columns-value-modified))))
  412. ;; If a time value is expressed as a duration, return a duration.
  413. ;; If any of them follows H:MM:SS pattern, use it too.
  414. (should
  415. (equal
  416. "1d 4:20"
  417. (org-test-with-temp-text
  418. "* H
  419. ** S1
  420. :PROPERTIES:
  421. :A: 3d 3h
  422. :END:
  423. ** S1
  424. :PROPERTIES:
  425. :A: 1:20
  426. :END:"
  427. (let ((org-columns-default-format "%A{:}")
  428. (org-time-clocksum-use-fractional nil)
  429. (org-time-clocksum-format
  430. '(:days "%dd " :hours "%d" :minutes ":%02d")))
  431. (org-columns))
  432. (get-char-property (point) 'org-columns-value-modified))))
  433. (should
  434. (equal
  435. "6:00:10"
  436. (org-test-with-temp-text
  437. "* H
  438. ** S1
  439. :PROPERTIES:
  440. :A: 4:40:10
  441. :END:
  442. ** S1
  443. :PROPERTIES:
  444. :A: 1:20
  445. :END:"
  446. (let ((org-columns-default-format "%A{:}")) (org-columns))
  447. (get-char-property (point) 'org-columns-value-modified))))
  448. ;; @min, @max and @mean also accept regular duration in
  449. ;; a "?d ?h ?m ?s" format.
  450. (should
  451. (equal
  452. "1d 10h 0m 0s"
  453. (org-test-with-temp-text
  454. "* H
  455. ** S1
  456. :PROPERTIES:
  457. :A: 1d 10h 0m 0s
  458. :END:
  459. ** S1
  460. :PROPERTIES:
  461. :A: 5d 3h 0m 0s
  462. :END:"
  463. (let ((org-columns-default-format "%A{@min}")) (org-columns))
  464. (get-char-property (point) 'org-columns-value-modified))))
  465. ;; {est+} gives a low-high estimate using mean and standard
  466. ;; deviation.
  467. (should
  468. (equal
  469. "3-17"
  470. (org-test-with-temp-text
  471. "* H
  472. ** S1
  473. :PROPERTIES:
  474. :A: 0-10
  475. :END:
  476. ** S1
  477. :PROPERTIES:
  478. :A: 0-10
  479. :END:"
  480. (let ((org-columns-default-format "%A{est+}")) (org-columns))
  481. (get-char-property (point) 'org-columns-value-modified))))
  482. ;; When using {est+} summary, a single number is understood as
  483. ;; a degenerate range.
  484. (should
  485. (equal
  486. "4-4"
  487. (org-test-with-temp-text
  488. "* H
  489. ** S1
  490. :PROPERTIES:
  491. :A: 4
  492. :END:
  493. "
  494. (let ((org-columns-default-format "%A{est+}")) (org-columns))
  495. (get-char-property (point) 'org-columns-value-modified))))
  496. ;; Test custom summary types.
  497. (should
  498. (equal
  499. "1|2"
  500. (org-test-with-temp-text
  501. "* H
  502. ** S1
  503. :PROPERTIES:
  504. :A: 1
  505. :END:
  506. ** S1
  507. :PROPERTIES:
  508. :A: 2
  509. :END:"
  510. (let ((org-columns-summary-types
  511. '(("custom" . (lambda (s _) (mapconcat #'identity s "|")))))
  512. (org-columns-default-format "%A{custom}")) (org-columns))
  513. (get-char-property (point) 'org-columns-value-modified)))))
  514. (ert-deftest test-org-colview/columns-new ()
  515. "Test `org-columns-new' specifications."
  516. ;; Insert new column at the left of the current one.
  517. (should
  518. (equal '("FOO" "ITEM")
  519. (org-test-with-temp-text "* H"
  520. (let ((org-columns-default-format "%ITEM")) (org-columns))
  521. (org-columns-new "FOO")
  522. (list (get-char-property (point) 'org-columns-key)
  523. (get-char-property (1+ (point)) 'org-columns-key)))))
  524. (should
  525. (equal '("ITEM" "FOO" "BAR")
  526. (org-test-with-temp-text "* H"
  527. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  528. (forward-char)
  529. (org-columns-new "FOO")
  530. (list (get-char-property (1- (point)) 'org-columns-key)
  531. (get-char-property (point) 'org-columns-key)
  532. (get-char-property (1+ (point)) 'org-columns-key)))))
  533. ;; Update #+COLUMNS keyword if needed.
  534. (should
  535. (equal "#+COLUMNS: %FOO %ITEM"
  536. (org-test-with-temp-text "#+COLUMNS: %ITEM\n<point>* H"
  537. (let ((org-columns-default-format "%ITEM")) (org-columns))
  538. (org-columns-new "FOO")
  539. (goto-char (point-min))
  540. (buffer-substring-no-properties (point) (line-end-position)))))
  541. (should
  542. (equal "#+COLUMNS: %ITEM %FOO %BAR"
  543. (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
  544. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  545. (forward-char)
  546. (org-columns-new "FOO")
  547. (goto-char (point-min))
  548. (buffer-substring-no-properties (point) (line-end-position)))))
  549. ;; Mind case when updating #+COLUMNS.
  550. (should
  551. (equal "#+COLUMNS: %ITEM %Foo %BAR"
  552. (org-test-with-temp-text "#+COLUMNS: %ITEM %BAR\n<point>* H"
  553. (let ((org-columns-default-format "%ITEM %BAR")) (org-columns))
  554. (forward-char)
  555. (org-columns-new "Foo")
  556. (goto-char (point-min))
  557. (buffer-substring-no-properties (point) (line-end-position))))))
  558. (ert-deftest test-org-colview/columns-update ()
  559. "Test `org-columns-update' specifications."
  560. ;; Update display.
  561. (should
  562. (equal
  563. "12 |"
  564. (org-test-with-temp-text
  565. "* H
  566. :PROPERTIES:
  567. :A: 1
  568. :END:
  569. "
  570. (let ((org-columns-default-format "%5A")) (org-columns))
  571. (search-forward "1")
  572. (insert "2")
  573. (org-columns-update "A")
  574. (get-char-property (point-min) 'display))))
  575. ;; Update is case-insensitive.
  576. (should
  577. (equal
  578. "12 |"
  579. (org-test-with-temp-text
  580. "* H
  581. :PROPERTIES:
  582. :A: 1
  583. :END:
  584. "
  585. (let ((org-columns-default-format "%5A")) (org-columns))
  586. (search-forward "1")
  587. (insert "2")
  588. (org-columns-update "a")
  589. (get-char-property (point-min) 'display))))
  590. ;; Update stored values.
  591. (should
  592. (equal
  593. '("12" "12")
  594. (org-test-with-temp-text
  595. "* H
  596. :PROPERTIES:
  597. :A: 1
  598. :END:
  599. "
  600. (let ((org-columns-default-format "%5A")) (org-columns))
  601. (search-forward "1")
  602. (insert "2")
  603. (org-columns-update "A")
  604. (list (get-char-property (point-min) 'org-columns-value)
  605. (get-char-property (point-min) 'org-columns-value-modified)))))
  606. ;; Ensure additional processing is done (e.g., ellipses, special
  607. ;; keywords fontification...).
  608. (should
  609. (equal
  610. "ve.. |"
  611. (org-test-with-temp-text
  612. "* H
  613. :PROPERTIES:
  614. :A: text
  615. :END:
  616. "
  617. (let ((org-columns-default-format "%4A")
  618. (org-columns-ellipses ".."))
  619. (org-columns))
  620. (search-forward ":A: ")
  621. (insert "very long ")
  622. (org-columns-update "A")
  623. (get-char-property (point-min) 'display))))
  624. ;; Values obtained from inline tasks are at the same level as those
  625. ;; obtained from children of the current node.
  626. (when (featurep 'org-inlinetask)
  627. (should
  628. (equal
  629. "2"
  630. (org-test-with-temp-text
  631. "* H
  632. *************** Inline task
  633. :PROPERTIES:
  634. :A: 2
  635. :END:
  636. *************** END
  637. ** Children
  638. :PROPERTIES:
  639. :A: 3
  640. :END:
  641. "
  642. (let ((org-columns-default-format "%A{min}")
  643. (org-columns-ellipses "..")
  644. (org-inlinetask-min-level 15))
  645. (org-columns))
  646. (get-char-property (point-min) 'org-columns-value))))))
  647. ;;; Dynamic block
  648. (ert-deftest test-org-colview/dblock ()
  649. "Test the column view table."
  650. (should
  651. (equal
  652. "#+BEGIN: columnview
  653. | ITEM |
  654. |------|
  655. | H |
  656. #+END:"
  657. (org-test-with-temp-text
  658. "* H\n<point>#+BEGIN: columnview\n#+END:"
  659. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  660. (buffer-substring-no-properties (point) (point-max)))))
  661. (should
  662. (equal
  663. "#+BEGIN: columnview
  664. | ITEM | A |
  665. |------+---|
  666. | H | 1 |
  667. #+END:"
  668. (org-test-with-temp-text
  669. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  670. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  671. (buffer-substring-no-properties (point) (point-max)))))
  672. ;; Properties are case insensitive.
  673. (should
  674. (equal
  675. "#+BEGIN: columnview
  676. | a |
  677. |---|
  678. | 1 |
  679. #+END:"
  680. (org-test-with-temp-text
  681. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  682. (let ((org-columns-default-format "%a")) (org-update-dblock))
  683. (buffer-substring-no-properties (point) (point-max)))))
  684. ;; Test titles given to columns.
  685. (should
  686. (equal
  687. "#+BEGIN: columnview
  688. | Name | Prop |
  689. |------+------|
  690. | H | 1 |
  691. #+END:"
  692. (org-test-with-temp-text
  693. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview\n#+END:"
  694. (let ((org-columns-default-format "%ITEM(Name) %A(Prop)"))
  695. (org-update-dblock))
  696. (buffer-substring-no-properties (point) (point-max)))))
  697. ;; Test `:id' parameter
  698. (should
  699. (equal
  700. "#+BEGIN: columnview :id local
  701. | ITEM |
  702. |------|
  703. | H1 |
  704. | H1.1 |
  705. #+END:
  706. "
  707. (org-test-with-temp-text
  708. "* H1\n<point>#+BEGIN: columnview :id local\n#+END:\n** H1.1\n* H2"
  709. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  710. (buffer-substring-no-properties (point) (outline-next-heading)))))
  711. (should
  712. (equal
  713. "#+BEGIN: columnview :id global
  714. | ITEM |
  715. |------|
  716. | H1 |
  717. | H1.1 |
  718. | H2 |
  719. #+END:
  720. "
  721. (org-test-with-temp-text
  722. "\n* H1\n<point>#+BEGIN: columnview :id global\n#+END:\n** H1.1\n* H2"
  723. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  724. (buffer-substring-no-properties (point) (outline-next-heading)))))
  725. ;; Test `:hlines' parameter.
  726. (should
  727. (equal
  728. "#+BEGIN: columnview :hlines t :id global
  729. | ITEM |
  730. |------|
  731. | H |
  732. |------|
  733. | H2 |
  734. |------|
  735. | H2.1 |
  736. #+END:\n"
  737. (org-test-with-temp-text
  738. "
  739. * H
  740. <point>#+BEGIN: columnview :hlines t :id global
  741. #+END:
  742. * H2
  743. ** H2.1"
  744. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  745. (buffer-substring-no-properties (point) (outline-next-heading)))))
  746. (should
  747. (equal
  748. "#+BEGIN: columnview :hlines 1 :id global
  749. | ITEM |
  750. |------|
  751. | H |
  752. |------|
  753. | H2 |
  754. | H2.1 |
  755. #+END:\n"
  756. (org-test-with-temp-text
  757. "
  758. * H
  759. <point>#+BEGIN: columnview :hlines 1 :id global
  760. #+END:
  761. * H2
  762. ** H2.1"
  763. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  764. (buffer-substring-no-properties (point) (outline-next-heading)))))
  765. ;; Test `:indent' parameter.
  766. (should
  767. (equal
  768. "#+BEGIN: columnview :indent t
  769. | ITEM |
  770. |----------|
  771. | H1 |
  772. | \\_ H1.1 |
  773. #+END:
  774. "
  775. (org-test-with-temp-text
  776. "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
  777. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  778. (buffer-substring-no-properties (point) (outline-next-heading)))))
  779. (should
  780. (equal
  781. "#+BEGIN: columnview :indent t
  782. | Prop | Name |
  783. |------+----------|
  784. | | H1 |
  785. | | \\_ H1.1 |
  786. #+END:
  787. "
  788. (org-test-with-temp-text
  789. "* H1\n<point>#+BEGIN: columnview :indent t\n#+END:\n** H1.1"
  790. (let ((org-columns-default-format "%A(Prop) %ITEM(Name)"))
  791. (org-update-dblock))
  792. (buffer-substring-no-properties (point) (outline-next-heading)))))
  793. ;; Test `:vlines' parameter.
  794. (should
  795. (equal
  796. "#+BEGIN: columnview :vlines t
  797. | | ITEM | A |
  798. |---+------+----|
  799. | | H | 1 |
  800. | / | <> | <> |
  801. #+END:"
  802. (org-test-with-temp-text
  803. "* H\n:PROPERTIES:\n:A: 1\n:END:\n<point>#+BEGIN: columnview :vlines t\n#+END:"
  804. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  805. (buffer-substring-no-properties (point) (point-max)))))
  806. ;; Test `:skip-empty-rows' parameter.
  807. (should
  808. (equal
  809. "#+BEGIN: columnview :skip-empty-rows t
  810. | ITEM | A |
  811. |------+---|
  812. | H1.1 | 1 |
  813. #+END:
  814. "
  815. (org-test-with-temp-text
  816. "
  817. * H1
  818. <point>#+BEGIN: columnview :skip-empty-rows t
  819. #+END:
  820. ** H1.1
  821. :PROPERTIES:
  822. :A: 1
  823. :END:"
  824. (let ((org-columns-default-format "%ITEM %A")) (org-update-dblock))
  825. (buffer-substring-no-properties (point) (outline-next-heading)))))
  826. ;; Test `:format' parameter.
  827. (should
  828. (equal
  829. "#+BEGIN: columnview :format \"%ITEM(Name)\"
  830. | Name |
  831. |------|
  832. | H |
  833. #+END:"
  834. (org-test-with-temp-text
  835. "* H\n<point>#+BEGIN: columnview :format \"%ITEM(Name)\"\n#+END:"
  836. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  837. (buffer-substring-no-properties (point) (point-max)))))
  838. ;; Test `:width' parameter
  839. (should
  840. (equal
  841. "#+BEGIN: columnview :width t
  842. | ITEM | A |
  843. |------------+---|
  844. | H | |
  845. | <10> | |
  846. #+END:"
  847. (org-test-with-temp-text
  848. "* H\n<point>#+BEGIN: columnview :width t\n#+END:"
  849. (let ((org-columns-default-format "%10ITEM %A")) (org-update-dblock))
  850. (buffer-substring-no-properties (point) (point-max)))))
  851. ;; When inserting ITEM values, make sure to clean sensitive
  852. ;; contents, like unique targets or forbidden inline src-blocks.
  853. (should
  854. (equal
  855. "#+BEGIN: columnview
  856. | ITEM |
  857. |------|
  858. | H 1 |
  859. #+END:"
  860. (org-test-with-temp-text
  861. "* H <<target>> 1\n<point>#+BEGIN: columnview\n#+END:"
  862. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  863. (buffer-substring-no-properties (point) (point-max)))))
  864. (should
  865. (equal
  866. "#+BEGIN: columnview
  867. | ITEM |
  868. |------|
  869. | H 1 |
  870. #+END:"
  871. (org-test-with-temp-text
  872. "* H src_emacs-lisp{(+ 1 1)} 1\n<point>#+BEGIN: columnview\n#+END:"
  873. (let ((org-columns-default-format "%ITEM")) (org-update-dblock))
  874. (buffer-substring-no-properties (point) (point-max))))))
  875. (provide 'test-org-colview)
  876. ;;; test-org-colview.el ends here