test-org-clock.el 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. ;;; test-org-clock.el --- Tests for org-clock.el
  2. ;; Copyright (C) 2012, 2014, 2015 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot com>
  4. ;; Released under the GNU General Public License version 3
  5. ;; see: http://www.gnu.org/licenses/gpl-3.0.html
  6. ;;;; Comments
  7. ;;; Code:
  8. (defun org-test-clock-create-timestamp (input &optional inactive with-time)
  9. "Create a timestamp out of a date/time prompt string.
  10. INPUT is a string as expected in a date/time prompt, i.e \"+2d\"
  11. or \"2/5\".
  12. When optional argument INACTIVE is non-nil, return an inactive
  13. timestamp. When optional argument WITH-TIME is non-nil, also
  14. insert hours and minutes.
  15. Return the timestamp as a string."
  16. (org-element-interpret-data
  17. (let ((time (decode-time
  18. (apply #'encode-time
  19. (mapcar (lambda (el) (or el 0))
  20. (org-read-date-analyze
  21. input nil (decode-time (current-time))))))))
  22. (list 'timestamp
  23. (list :type (if inactive 'inactive 'active)
  24. :minute-start (and with-time (nth 1 time))
  25. :hour-start (and with-time (nth 2 time))
  26. :day-start (nth 3 time)
  27. :month-start (nth 4 time)
  28. :year-start (nth 5 time))))))
  29. (defun org-test-clock-create-clock (input1 &optional input2)
  30. "Create a clock line out of two date/time prompts.
  31. INPUT1 and INPUT2 are strings as expected in a date/time prompt,
  32. i.e \"+2d\" or \"2/5\". They respectively refer to start and end
  33. range. INPUT2 can be omitted if clock hasn't finished yet.
  34. Return the clock line as a string."
  35. (let* ((beg (org-test-clock-create-timestamp input1 t t))
  36. (end (and input2 (org-test-clock-create-timestamp input2 t t)))
  37. (sec-diff (and input2 (floor (- (org-time-string-to-seconds end)
  38. (org-time-string-to-seconds beg))))))
  39. (concat org-clock-string " " beg
  40. (when end
  41. (concat "--" end " => "
  42. (format "%2d:%02d"
  43. (/ sec-diff 3600)
  44. (/ (mod sec-diff 3600) 60))))
  45. "\n")))
  46. (defun test-org-clock-clocktable-contents (options &optional initial)
  47. "Return contents of a Clock table for current buffer
  48. OPTIONS is a string of Clock table options. Optional argument
  49. INITIAL is a string specifying initial contents within the Clock
  50. table.
  51. Caption is ignored in contents. The clocktable doesn't appear in
  52. the buffer."
  53. (declare (indent 2))
  54. (goto-char (point-min))
  55. (save-excursion
  56. (insert "#+BEGIN: clocktable " options "\n")
  57. (when initial (insert initial))
  58. (unless (string-suffix-p "\n" initial) (insert "\n"))
  59. (insert "#+END:\n"))
  60. (unwind-protect
  61. (save-excursion
  62. (let ((org-duration-format 'h:mm)) (org-update-dblock))
  63. (forward-line)
  64. ;; Skip caption.
  65. (when (looking-at "#\\+CAPTION:") (forward-line))
  66. (buffer-substring-no-properties
  67. (point) (progn (search-forward "#+END:") (line-end-position 0))))
  68. ;; Remove clocktable.
  69. (delete-region (point) (search-forward "#+END:\n"))))
  70. ;;; Clock drawer
  71. (ert-deftest test-org-clock/into-drawer ()
  72. "Test `org-clock-into-drawer' specifications."
  73. ;; When `org-clock-into-drawer' is nil, do not use a clock drawer.
  74. (should-not
  75. (org-test-with-temp-text "* H"
  76. (let ((org-clock-into-drawer nil)
  77. (org-log-into-drawer nil))
  78. (org-clock-into-drawer))))
  79. (should-not
  80. (org-test-with-temp-text "* H"
  81. (let ((org-clock-into-drawer nil)
  82. (org-log-into-drawer t))
  83. (org-clock-into-drawer))))
  84. (should-not
  85. (org-test-with-temp-text "* H"
  86. (let ((org-clock-into-drawer nil)
  87. (org-log-into-drawer "BAR"))
  88. (org-clock-into-drawer))))
  89. ;; When `org-clock-into-drawer' is a string, use it
  90. ;; unconditionally.
  91. (should
  92. (equal "FOO"
  93. (org-test-with-temp-text "* H"
  94. (let ((org-clock-into-drawer "FOO")
  95. (org-log-into-drawer nil))
  96. (org-clock-into-drawer)))))
  97. (should
  98. (equal "FOO"
  99. (org-test-with-temp-text "* H"
  100. (let ((org-clock-into-drawer "FOO")
  101. (org-log-into-drawer t))
  102. (org-clock-into-drawer)))))
  103. (should
  104. (equal "FOO"
  105. (org-test-with-temp-text "* H"
  106. (let ((org-clock-into-drawer "FOO")
  107. (org-log-into-drawer "BAR"))
  108. (org-clock-into-drawer)))))
  109. ;; When `org-clock-into-drawer' is an integer, return it.
  110. (should
  111. (= 1
  112. (org-test-with-temp-text "* H"
  113. (let ((org-clock-into-drawer 1)
  114. (org-log-into-drawer nil))
  115. (org-clock-into-drawer)))))
  116. (should
  117. (= 1
  118. (org-test-with-temp-text "* H"
  119. (let ((org-clock-into-drawer 1)
  120. (org-log-into-drawer t))
  121. (org-clock-into-drawer)))))
  122. (should
  123. (= 1
  124. (org-test-with-temp-text "* H"
  125. (let ((org-clock-into-drawer 1)
  126. (org-log-into-drawer "BAR"))
  127. (org-clock-into-drawer)))))
  128. ;; Otherwise, any non-nil value defaults to `org-log-into-drawer' or
  129. ;; "LOGBOOK" if it is nil.
  130. (should
  131. (equal "LOGBOOK"
  132. (org-test-with-temp-text "* H"
  133. (let ((org-clock-into-drawer t)
  134. (org-log-into-drawer nil))
  135. (org-clock-into-drawer)))))
  136. (should
  137. (equal "LOGBOOK"
  138. (org-test-with-temp-text "* H"
  139. (let ((org-clock-into-drawer t)
  140. (org-log-into-drawer t))
  141. (org-clock-into-drawer)))))
  142. (should
  143. (equal "FOO"
  144. (org-test-with-temp-text "* H"
  145. (let ((org-clock-into-drawer t)
  146. (org-log-into-drawer "FOO"))
  147. (org-clock-into-drawer)))))
  148. ;; A non-nil "CLOCK_INTO_DRAWER" property overrides
  149. ;; `org-clock-into-drawer' value.
  150. (should
  151. (equal "LOGBOOK"
  152. (org-test-with-temp-text
  153. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:"
  154. (let ((org-clock-into-drawer nil)
  155. (org-log-into-drawer nil))
  156. (org-clock-into-drawer)))))
  157. (should
  158. (equal "FOO"
  159. (org-test-with-temp-text
  160. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:"
  161. (let ((org-clock-into-drawer nil)
  162. (org-log-into-drawer nil))
  163. (org-clock-into-drawer)))))
  164. (should-not
  165. (org-test-with-temp-text
  166. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:"
  167. (let ((org-clock-into-drawer t)
  168. (org-log-into-drawer nil))
  169. (org-clock-into-drawer))))
  170. ;; "CLOCK_INTO_DRAWER" can be inherited.
  171. (should
  172. (equal "LOGBOOK"
  173. (org-test-with-temp-text
  174. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: t\n:END:\n** H2<point>"
  175. (let ((org-clock-into-drawer nil)
  176. (org-log-into-drawer nil))
  177. (org-clock-into-drawer)))))
  178. (should
  179. (equal "FOO"
  180. (org-test-with-temp-text
  181. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: FOO\n:END:\n** H2<point>"
  182. (let ((org-clock-into-drawer nil)
  183. (org-log-into-drawer nil))
  184. (org-clock-into-drawer)))))
  185. (should-not
  186. (org-test-with-temp-text
  187. "* H\n:PROPERTIES:\n:CLOCK_INTO_DRAWER: nil\n:END:\n** H2<point>"
  188. (let ((org-clock-into-drawer t)
  189. (org-log-into-drawer nil))
  190. (org-clock-into-drawer)))))
  191. (ert-deftest test-org-clock/drawer-name ()
  192. "Test `org-clock-drawer-name' specifications."
  193. ;; A nil value for `org-clock-into-drawer' means no drawer is
  194. ;; expected whatsoever.
  195. (should-not
  196. (org-test-with-temp-text "* H"
  197. (let ((org-clock-into-drawer nil)
  198. (org-log-into-drawer nil))
  199. (org-clock-drawer-name))))
  200. (should-not
  201. (org-test-with-temp-text "* H"
  202. (let ((org-clock-into-drawer nil)
  203. (org-log-into-drawer t))
  204. (org-clock-drawer-name))))
  205. (should-not
  206. (org-test-with-temp-text "* H"
  207. (let ((org-clock-into-drawer nil)
  208. (org-log-into-drawer "FOO"))
  209. (org-clock-drawer-name))))
  210. ;; A string value for `org-clock-into-drawer' means to use it
  211. ;; unconditionally.
  212. (should
  213. (equal "FOO"
  214. (org-test-with-temp-text "* H"
  215. (let ((org-clock-into-drawer "FOO")
  216. (org-log-into-drawer nil))
  217. (org-clock-drawer-name)))))
  218. (should
  219. (equal "FOO"
  220. (org-test-with-temp-text "* H"
  221. (let ((org-clock-into-drawer "FOO")
  222. (org-log-into-drawer t))
  223. (org-clock-drawer-name)))))
  224. (should
  225. (equal "FOO"
  226. (org-test-with-temp-text "* H"
  227. (let ((org-clock-into-drawer "FOO")
  228. (org-log-into-drawer "BAR"))
  229. (org-clock-drawer-name)))))
  230. ;; When the value in `org-clock-into-drawer' is a number, re-use
  231. ;; `org-log-into-drawer' or use default "LOGBOOK" value.
  232. (should
  233. (equal "FOO"
  234. (org-test-with-temp-text "* H"
  235. (let ((org-clock-into-drawer 1)
  236. (org-log-into-drawer "FOO"))
  237. (org-clock-drawer-name)))))
  238. (should
  239. (equal "LOGBOOK"
  240. (org-test-with-temp-text "* H"
  241. (let ((org-clock-into-drawer 1)
  242. (org-log-into-drawer t))
  243. (org-clock-drawer-name)))))
  244. (should
  245. (equal "LOGBOOK"
  246. (org-test-with-temp-text "* H"
  247. (let ((org-clock-into-drawer 1)
  248. (org-log-into-drawer nil))
  249. (org-clock-drawer-name))))))
  250. ;;; Clocktable
  251. (ert-deftest test-org-clock/clocktable/ranges ()
  252. "Test ranges in Clock table."
  253. ;; Relative time: Previous two days.
  254. (should
  255. (equal
  256. "| Headline | Time | |
  257. |------------------------------+--------+------|
  258. | *Total time* | *8:00* | |
  259. |------------------------------+--------+------|
  260. | Relative times in clocktable | 8:00 | |
  261. | Foo | | 8:00 |"
  262. (org-test-with-temp-text
  263. "* Relative times in clocktable\n** Foo\n<point>"
  264. (insert (org-test-clock-create-clock "-3d 8:00" "-3d 12:00"))
  265. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  266. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  267. (test-org-clock-clocktable-contents
  268. ":tstart \"<-2d>\" :tend \"<today>\" :indent nil"))))
  269. ;; Relative time: Yesterday until now.
  270. (should
  271. (equal
  272. "| Headline | Time | |
  273. |------------------------------+--------+------|
  274. | *Total time* | *6:00* | |
  275. |------------------------------+--------+------|
  276. | Relative times in clocktable | 6:00 | |
  277. | Foo | | 6:00 |"
  278. (org-test-with-temp-text
  279. "* Relative times in clocktable\n** Foo\n<point>"
  280. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  281. (insert (org-test-clock-create-clock "-1d 8:00" "-1d 13:00"))
  282. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  283. (test-org-clock-clocktable-contents
  284. ":tstart \"<yesterday>\" :tend \"<tomorrow>\" :indent nil"))))
  285. ;; Test `untilnow' block.
  286. (should
  287. (equal
  288. "| Headline | Time | |
  289. |------------------------------+--------+------|
  290. | *Total time* | *6:00* | |
  291. |------------------------------+--------+------|
  292. | Relative times in clocktable | 6:00 | |
  293. | Foo | | 6:00 |"
  294. (org-test-with-temp-text
  295. "* Relative times in clocktable\n** Foo\n<point>"
  296. (insert (org-test-clock-create-clock "-10y 15:00" "-10y 18:00"))
  297. (insert (org-test-clock-create-clock "-2d 15:00" "-2d 18:00"))
  298. (test-org-clock-clocktable-contents ":block untilnow :indent nil")))))
  299. (ert-deftest test-org-clock/clocktable/tags ()
  300. "Test \":tags\" parameter in Clock table."
  301. ;; Test tag filtering.
  302. (should
  303. (equal
  304. "| Headline | Time | |
  305. |--------------+--------+------|
  306. | *Total time* | *2:00* | |
  307. |--------------+--------+------|
  308. | H1 | | 2:00 |"
  309. (org-test-with-temp-text "** H1\n\n*** H2 :tag:\n\n*** H3\n<point>"
  310. (insert (org-test-clock-create-clock ". 1:00" ". 2:00"))
  311. (goto-line 4)
  312. (insert (org-test-clock-create-clock ". 2:00" ". 4:00"))
  313. (test-org-clock-clocktable-contents ":tags \"tag\" :indent nil")))))
  314. (ert-deftest test-org-clock/clocktable/scope ()
  315. "Test \":scope\" parameter in Clock table."
  316. ;; Test `file-with-archives' scope. In particular, preserve "TBLFM"
  317. ;; line, and ignore "file" column.
  318. (should
  319. (equal
  320. "| Headline | Time | |
  321. |--------------+------------+-----|
  322. | *Total time* | *16905:01* | foo |
  323. |--------------+------------+-----|
  324. | Test | 16905:01 | foo |
  325. #+TBLFM: $3=string(\"foo\")"
  326. (org-test-with-temp-text-in-file
  327. "* Test
  328. CLOCK: [2012-03-29 Thu 16:40]--[2014-03-04 Thu 01:41] => 16905:01"
  329. (test-org-clock-clocktable-contents ":scope file-with-archives"
  330. "#+TBLFM: $3=string(\"foo\")"))))
  331. ;; Test "function" scope.
  332. (should
  333. (string-match-p
  334. (regexp-quote "| ALL *Total time* | *1:00* |")
  335. (org-test-with-temp-text-in-file
  336. "* Test
  337. CLOCK: [2012-03-29 Thu 16:00]--[2012-03-29 Thu 17:00] => 1:00"
  338. (let ((the-file (buffer-file-name)))
  339. (org-test-with-temp-text-in-file ""
  340. (test-org-clock-clocktable-contents
  341. (format ":scope (lambda () (list %S))" the-file))))))))
  342. (ert-deftest test-org-clock/clocktable/maxlevel ()
  343. "Test \":maxlevel\" parameter in Clock table."
  344. (should
  345. (equal "| Headline | Time | | |
  346. |--------------+--------+------+---|
  347. | *Total time* | *6:00* | | |
  348. |--------------+--------+------+---|
  349. | Foo | 6:00 | | |
  350. | \\_ Bar | | 2:00 | |"
  351. (org-test-with-temp-text
  352. "* Foo
  353. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  354. ** Bar
  355. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  356. (test-org-clock-clocktable-contents ":maxlevel 3"))))
  357. (should
  358. (equal "| Headline | Time | |
  359. |--------------+--------+------|
  360. | *Total time* | *6:00* | |
  361. |--------------+--------+------|
  362. | Foo | 6:00 | |
  363. | \\_ Bar | | 2:00 |"
  364. (org-test-with-temp-text
  365. "* Foo
  366. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  367. ** Bar
  368. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  369. (test-org-clock-clocktable-contents ":maxlevel 2"))))
  370. (should
  371. (equal "| Headline | Time |
  372. |--------------+--------|
  373. | *Total time* | *6:00* |
  374. |--------------+--------|
  375. | Foo | 6:00 |"
  376. (org-test-with-temp-text
  377. "* Foo
  378. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  379. ** Bar
  380. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  381. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  382. ;; Special ":maxlevel 0" case: only report total file time.
  383. (should
  384. (equal "| Headline | Time |
  385. |--------------+--------|
  386. | *Total time* | *6:00* |
  387. |--------------+--------|"
  388. (org-test-with-temp-text
  389. "* Foo
  390. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  391. ** Bar
  392. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  393. (test-org-clock-clocktable-contents ":maxlevel 0")))))
  394. (ert-deftest test-org-clock/clocktable/formula ()
  395. "Test \":formula\" parameter in Clock table."
  396. ;; Test ":formula %". Handle various duration formats.
  397. (should
  398. (equal
  399. "| Headline | Time | % |
  400. |--------------+--------+-------|
  401. | *Total time* | *6:00* | 100.0 |
  402. |--------------+--------+-------|
  403. | Foo | 4:00 | 66.7 |
  404. | Bar | 2:00 | 33.3 |"
  405. (org-test-with-temp-text
  406. "* Foo
  407. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  408. * Bar
  409. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  410. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  411. (should
  412. (equal
  413. "| Headline | Time | % |
  414. |--------------+---------+-------|
  415. | *Total time* | *28:00* | 100.0 |
  416. |--------------+---------+-------|
  417. | Foo | 26:00 | 92.9 |
  418. | Bar | 2:00 | 7.1 |"
  419. (org-test-with-temp-text
  420. "* Foo
  421. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  422. * Bar
  423. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  424. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %")))))
  425. (ert-deftest test-org-clock/clocktable/lang ()
  426. "Test \":lang\" parameter in Clock table."
  427. ;; Test foreign translation
  428. (should
  429. (equal
  430. "| Headline | Time |
  431. |--------------+---------|
  432. | *Total time* | *26:00* |
  433. |--------------+---------|
  434. | Foo | 26:00 |"
  435. (org-test-with-temp-text
  436. "* Foo
  437. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  438. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
  439. (should
  440. (equal
  441. "| En-tête | Durée |
  442. |----------------+---------|
  443. | *Durée totale* | *26:00* |
  444. |----------------+---------|
  445. | Foo | 26:00 |"
  446. (org-test-with-temp-text
  447. "* Foo
  448. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  449. (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr"))))
  450. ;; No :lang parameter is equivalent to "en".
  451. (should
  452. (equal
  453. (org-test-with-temp-text
  454. "* Foo
  455. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  456. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
  457. (org-test-with-temp-text
  458. "* Foo
  459. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  460. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  461. ;; Unknown translation fall backs to "en".
  462. (should
  463. (equal
  464. "| Headline | Time |
  465. |--------------+---------|
  466. | *Total time* | *26:00* |
  467. |--------------+---------|
  468. | Foo | 26:00 |"
  469. (org-test-with-temp-text
  470. "* Foo
  471. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  472. (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
  473. (ert-deftest test-org-clock/clocktable/compact ()
  474. "Test \":compact\" parameter in Clock table."
  475. ;; With :compact, all headlines are in the same column.
  476. (should
  477. (equal
  478. "| Headline | Time |
  479. |--------------+---------|
  480. | *Total time* | *26:00* |
  481. |--------------+---------|
  482. | Foo | 26:00 |"
  483. (org-test-with-temp-text
  484. "* Foo
  485. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  486. (test-org-clock-clocktable-contents ":compact t"))))
  487. (should
  488. (equal
  489. "| Headline | Time |
  490. |--------------+---------|
  491. | *Total time* | *52:00* |
  492. |--------------+---------|
  493. | Foo | 52:00 |
  494. | \\_ Bar | 26:00 |"
  495. (org-test-with-temp-text
  496. "* Foo
  497. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  498. ** Bar
  499. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  500. (test-org-clock-clocktable-contents ":compact t"))))
  501. ;; :maxlevel does not affect :compact parameter.
  502. (should
  503. (equal
  504. "| Headline | Time |
  505. |--------------+---------|
  506. | *Total time* | *52:00* |
  507. |--------------+---------|
  508. | Foo | 52:00 |
  509. | \\_ Bar | 26:00 |"
  510. (org-test-with-temp-text
  511. "* Foo
  512. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  513. ** Bar
  514. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  515. (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
  516. ;; :compact implies a non-nil :indent parameter.
  517. (should
  518. (equal
  519. "| Headline | Time |
  520. |--------------+---------|
  521. | *Total time* | *52:00* |
  522. |--------------+---------|
  523. | Foo | 52:00 |
  524. | \\_ Bar | 26:00 |"
  525. (org-test-with-temp-text
  526. "* Foo
  527. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  528. ** Bar
  529. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  530. (test-org-clock-clocktable-contents ":compact t :indent nil"))))
  531. ;; :compact implies a nil :level parameter.
  532. (should
  533. (equal
  534. "| Headline | Time |
  535. |--------------+---------|
  536. | *Total time* | *52:00* |
  537. |--------------+---------|
  538. | Foo | 52:00 |
  539. | \\_ Bar | 26:00 |"
  540. (org-test-with-temp-text
  541. "* Foo
  542. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  543. ** Bar
  544. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  545. (test-org-clock-clocktable-contents ":compact t :level t")))))
  546. (ert-deftest test-org-clock/clocktable/properties ()
  547. "Test \":properties\" parameter in Clock table."
  548. ;; Include a new column with list properties.
  549. (should
  550. (equal
  551. "| A | Headline | Time | |
  552. |---+--------------+---------+---|
  553. | | *Total time* | *26:00* | |
  554. |---+--------------+---------+---|
  555. | 1 | Foo | 26:00 | |"
  556. (org-test-with-temp-text
  557. "* Foo
  558. :PROPERTIES:
  559. :A: 1
  560. :END:
  561. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  562. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  563. (should
  564. (equal
  565. "| A | Headline | Time | |
  566. |---+--------------+---------+-------|
  567. | | *Total time* | *52:00* | |
  568. |---+--------------+---------+-------|
  569. | | Foo | 52:00 | |
  570. | 1 | \\_ Bar | | 26:00 |"
  571. (org-test-with-temp-text
  572. "* Foo
  573. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  574. ** Bar
  575. :PROPERTIES:
  576. :A: 1
  577. :END:
  578. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  579. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  580. ;; Handle missing properties.
  581. (should
  582. (equal
  583. "| A | Headline | Time | |
  584. |---+--------------+---------+---|
  585. | | *Total time* | *26:00* | |
  586. |---+--------------+---------+---|
  587. | 1 | Foo | 26:00 | |"
  588. (org-test-with-temp-text
  589. "* Foo
  590. :PROPERTIES:
  591. :A: 1
  592. :END:
  593. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  594. (test-org-clock-clocktable-contents ":properties (\"A\")")))))
  595. (provide 'test-org-clock)
  596. ;;; test-org-clock.el end here