test-org-clock.el 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617
  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 00:41] => 16905:01"
  329. (test-org-clock-clocktable-contents ":scope file-with-archives"
  330. "#+TBLFM: $3=string(\"foo\")")))))
  331. (ert-deftest test-org-clock/clocktable/maxlevel ()
  332. "Test \":maxlevel\" parameter in Clock table."
  333. (should
  334. (equal "| Headline | Time | | |
  335. |--------------+--------+------+---|
  336. | *Total time* | *6:00* | | |
  337. |--------------+--------+------+---|
  338. | Foo | 6:00 | | |
  339. | \\_ Bar | | 2:00 | |"
  340. (org-test-with-temp-text
  341. "* Foo
  342. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  343. ** Bar
  344. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  345. (test-org-clock-clocktable-contents ":maxlevel 3"))))
  346. (should
  347. (equal "| Headline | Time | |
  348. |--------------+--------+------|
  349. | *Total time* | *6:00* | |
  350. |--------------+--------+------|
  351. | Foo | 6:00 | |
  352. | \\_ Bar | | 2:00 |"
  353. (org-test-with-temp-text
  354. "* Foo
  355. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  356. ** Bar
  357. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  358. (test-org-clock-clocktable-contents ":maxlevel 2"))))
  359. (should
  360. (equal "| Headline | Time |
  361. |--------------+--------|
  362. | *Total time* | *6:00* |
  363. |--------------+--------|
  364. | Foo | 6:00 |"
  365. (org-test-with-temp-text
  366. "* Foo
  367. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  368. ** Bar
  369. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  370. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  371. ;; Special ":maxlevel 0" case: only report total file time.
  372. (should
  373. (equal "| Headline | Time |
  374. |--------------+--------|
  375. | *Total time* | *6:00* |
  376. |--------------+--------|"
  377. (org-test-with-temp-text
  378. "* Foo
  379. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  380. ** Bar
  381. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  382. (test-org-clock-clocktable-contents ":maxlevel 0")))))
  383. (ert-deftest test-org-clock/clocktable/formula ()
  384. "Test \":formula\" parameter in Clock table."
  385. ;; Test ":formula %". Handle various duration formats.
  386. (should
  387. (equal
  388. "| Headline | Time | % |
  389. |--------------+--------+-------|
  390. | *Total time* | *6:00* | 100.0 |
  391. |--------------+--------+-------|
  392. | Foo | 4:00 | 66.7 |
  393. | Bar | 2:00 | 33.3 |"
  394. (org-test-with-temp-text
  395. "* Foo
  396. CLOCK: [2016-12-28 Wed 11:09]--[2016-12-28 Wed 15:09] => 4:00
  397. * Bar
  398. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  399. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %"))))
  400. (should
  401. (equal
  402. "| Headline | Time | % |
  403. |--------------+---------+-------|
  404. | *Total time* | *28:00* | 100.0 |
  405. |--------------+---------+-------|
  406. | Foo | 26:00 | 92.9 |
  407. | Bar | 2:00 | 7.1 |"
  408. (org-test-with-temp-text
  409. "* Foo
  410. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  411. * Bar
  412. CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] => 2:00"
  413. (test-org-clock-clocktable-contents ":maxlevel 1 :formula %")))))
  414. (ert-deftest test-org-clock/clocktable/lang ()
  415. "Test \":lang\" parameter in Clock table."
  416. ;; Test foreign translation
  417. (should
  418. (equal
  419. "| Headline | Time |
  420. |--------------+---------|
  421. | *Total time* | *26:00* |
  422. |--------------+---------|
  423. | Foo | 26:00 |"
  424. (org-test-with-temp-text
  425. "* Foo
  426. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  427. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
  428. (should
  429. (equal
  430. "| En-tête | Durée |
  431. |----------------+---------|
  432. | *Durée totale* | *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 fr"))))
  439. ;; No :lang parameter is equivalent to "en".
  440. (should
  441. (equal
  442. (org-test-with-temp-text
  443. "* Foo
  444. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  445. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
  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"))))
  450. ;; Unknown translation fall backs to "en".
  451. (should
  452. (equal
  453. "| Headline | Time |
  454. |--------------+---------|
  455. | *Total time* | *26:00* |
  456. |--------------+---------|
  457. | Foo | 26:00 |"
  458. (org-test-with-temp-text
  459. "* Foo
  460. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  461. (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
  462. (ert-deftest test-org-clock/clocktable/compact ()
  463. "Test \":compact\" parameter in Clock table."
  464. ;; With :compact, all headlines are in the same column.
  465. (should
  466. (equal
  467. "| Headline | Time |
  468. |--------------+---------|
  469. | *Total time* | *26:00* |
  470. |--------------+---------|
  471. | Foo | 26:00 |"
  472. (org-test-with-temp-text
  473. "* Foo
  474. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  475. (test-org-clock-clocktable-contents ":compact t"))))
  476. (should
  477. (equal
  478. "| Headline | Time |
  479. |--------------+---------|
  480. | *Total time* | *52:00* |
  481. |--------------+---------|
  482. | Foo | 52:00 |
  483. | \\_ Bar | 26:00 |"
  484. (org-test-with-temp-text
  485. "* Foo
  486. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  487. ** Bar
  488. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  489. (test-org-clock-clocktable-contents ":compact t"))))
  490. ;; :maxlevel does not affect :compact parameter.
  491. (should
  492. (equal
  493. "| Headline | Time |
  494. |--------------+---------|
  495. | *Total time* | *52:00* |
  496. |--------------+---------|
  497. | Foo | 52:00 |
  498. | \\_ Bar | 26:00 |"
  499. (org-test-with-temp-text
  500. "* Foo
  501. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  502. ** Bar
  503. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  504. (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
  505. ;; :compact implies a non-nil :indent parameter.
  506. (should
  507. (equal
  508. "| Headline | Time |
  509. |--------------+---------|
  510. | *Total time* | *52:00* |
  511. |--------------+---------|
  512. | Foo | 52:00 |
  513. | \\_ Bar | 26:00 |"
  514. (org-test-with-temp-text
  515. "* Foo
  516. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  517. ** Bar
  518. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  519. (test-org-clock-clocktable-contents ":compact t :indent nil"))))
  520. ;; :compact implies a nil :level parameter.
  521. (should
  522. (equal
  523. "| Headline | Time |
  524. |--------------+---------|
  525. | *Total time* | *52:00* |
  526. |--------------+---------|
  527. | Foo | 52:00 |
  528. | \\_ Bar | 26:00 |"
  529. (org-test-with-temp-text
  530. "* Foo
  531. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  532. ** Bar
  533. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  534. (test-org-clock-clocktable-contents ":compact t :level t")))))
  535. (ert-deftest test-org-clock/clocktable/properties ()
  536. "Test \":properties\" parameter in Clock table."
  537. ;; Include a new column with list properties.
  538. (should
  539. (equal
  540. "| A | Headline | Time | |
  541. |---+--------------+---------+---|
  542. | | *Total time* | *26:00* | |
  543. |---+--------------+---------+---|
  544. | 1 | Foo | 26:00 | |"
  545. (org-test-with-temp-text
  546. "* Foo
  547. :PROPERTIES:
  548. :A: 1
  549. :END:
  550. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  551. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  552. (should
  553. (equal
  554. "| A | Headline | Time | |
  555. |---+--------------+---------+-------|
  556. | | *Total time* | *52:00* | |
  557. |---+--------------+---------+-------|
  558. | | Foo | 52:00 | |
  559. | 1 | \\_ Bar | | 26:00 |"
  560. (org-test-with-temp-text
  561. "* Foo
  562. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  563. ** Bar
  564. :PROPERTIES:
  565. :A: 1
  566. :END:
  567. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  568. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  569. ;; Handle missing properties.
  570. (should
  571. (equal
  572. "| A | Headline | Time | |
  573. |---+--------------+---------+---|
  574. | | *Total time* | *26:00* | |
  575. |---+--------------+---------+---|
  576. | 1 | Foo | 26:00 | |"
  577. (org-test-with-temp-text
  578. "* Foo
  579. :PROPERTIES:
  580. :A: 1
  581. :END:
  582. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  583. (test-org-clock-clocktable-contents ":properties (\"A\")")))))
  584. (provide 'test-org-clock)
  585. ;;; test-org-clock.el end here