test-org-clock.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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. ;; 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. ;; Properly align column with different depths.
  426. (should
  427. (equal "| Headline | Time | | | % |
  428. |---------------+--------+------+------+-------|
  429. | *Total time* | *1:00* | | | 100.0 |
  430. |---------------+--------+------+------+-------|
  431. | foo | 1:00 | | | 100.0 |
  432. | \\_ sub | | 0:15 | | 25.0 |
  433. | \\_ sub2 | | 0:15 | | 25.0 |
  434. | \\_ sub3 | | 0:30 | | 50.0 |
  435. | \\_ subsub1 | | | 0:15 | 25.0 |
  436. | \\_ subsub1 | | | 0:15 | 25.0 |"
  437. (org-test-with-temp-text
  438. "* foo
  439. ** sub
  440. :LOGBOOK:
  441. CLOCK: [2017-03-18 Sat 15:00]--[2017-03-18 Sat 15:15] => 0:15
  442. :END:
  443. ** sub2
  444. :LOGBOOK:
  445. CLOCK: [2017-03-18 Sat 15:15]--[2017-03-18 Sat 15:30] => 0:15
  446. :END:
  447. ** sub3
  448. *** subsub1
  449. :LOGBOOK:
  450. CLOCK: [2017-03-18 Sat 13:00]--[2017-03-18 Sat 13:15] => 0:15
  451. :END:
  452. *** subsub1
  453. :LOGBOOK:
  454. CLOCK: [2017-03-18 Sat 14:00]--[2017-03-18 Sat 14:15] => 0:15
  455. :END:"
  456. (test-org-clock-clocktable-contents ":maxlevel 3 :formula %")))))
  457. (ert-deftest test-org-clock/clocktable/lang ()
  458. "Test \":lang\" parameter in Clock table."
  459. ;; Test foreign translation
  460. (should
  461. (equal
  462. "| Headline | Time |
  463. |--------------+---------|
  464. | *Total time* | *26:00* |
  465. |--------------+---------|
  466. | Foo | 26:00 |"
  467. (org-test-with-temp-text
  468. "* Foo
  469. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  470. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))))
  471. (should
  472. (equal
  473. "| En-tête | Durée |
  474. |----------------+---------|
  475. | *Durée totale* | *26:00* |
  476. |----------------+---------|
  477. | Foo | 26:00 |"
  478. (org-test-with-temp-text
  479. "* Foo
  480. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  481. (test-org-clock-clocktable-contents ":maxlevel 1 :lang fr"))))
  482. ;; No :lang parameter is equivalent to "en".
  483. (should
  484. (equal
  485. (org-test-with-temp-text
  486. "* Foo
  487. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  488. (test-org-clock-clocktable-contents ":maxlevel 1 :lang en"))
  489. (org-test-with-temp-text
  490. "* Foo
  491. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  492. (test-org-clock-clocktable-contents ":maxlevel 1"))))
  493. ;; Unknown translation fall backs to "en".
  494. (should
  495. (equal
  496. "| Headline | Time |
  497. |--------------+---------|
  498. | *Total time* | *26:00* |
  499. |--------------+---------|
  500. | Foo | 26:00 |"
  501. (org-test-with-temp-text
  502. "* Foo
  503. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  504. (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
  505. (ert-deftest test-org-clock/clocktable/compact ()
  506. "Test \":compact\" parameter in Clock table."
  507. ;; With :compact, all headlines are in the same column.
  508. (should
  509. (equal
  510. "| Headline | Time |
  511. |--------------+---------|
  512. | *Total time* | *26:00* |
  513. |--------------+---------|
  514. | Foo | 26:00 |"
  515. (org-test-with-temp-text
  516. "* Foo
  517. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  518. (test-org-clock-clocktable-contents ":compact t"))))
  519. (should
  520. (equal
  521. "| Headline | Time |
  522. |--------------+---------|
  523. | *Total time* | *52:00* |
  524. |--------------+---------|
  525. | Foo | 52:00 |
  526. | \\_ Bar | 26:00 |"
  527. (org-test-with-temp-text
  528. "* Foo
  529. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  530. ** Bar
  531. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  532. (test-org-clock-clocktable-contents ":compact t"))))
  533. ;; :maxlevel does not affect :compact parameter.
  534. (should
  535. (equal
  536. "| Headline | Time |
  537. |--------------+---------|
  538. | *Total time* | *52:00* |
  539. |--------------+---------|
  540. | Foo | 52:00 |
  541. | \\_ Bar | 26:00 |"
  542. (org-test-with-temp-text
  543. "* Foo
  544. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  545. ** Bar
  546. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  547. (test-org-clock-clocktable-contents ":compact t :maxlevel 2"))))
  548. ;; :compact implies a non-nil :indent parameter.
  549. (should
  550. (equal
  551. "| Headline | Time |
  552. |--------------+---------|
  553. | *Total time* | *52:00* |
  554. |--------------+---------|
  555. | Foo | 52:00 |
  556. | \\_ Bar | 26:00 |"
  557. (org-test-with-temp-text
  558. "* Foo
  559. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  560. ** Bar
  561. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  562. (test-org-clock-clocktable-contents ":compact t :indent nil"))))
  563. ;; :compact implies a nil :level parameter.
  564. (should
  565. (equal
  566. "| Headline | Time |
  567. |--------------+---------|
  568. | *Total time* | *52:00* |
  569. |--------------+---------|
  570. | Foo | 52:00 |
  571. | \\_ Bar | 26:00 |"
  572. (org-test-with-temp-text
  573. "* Foo
  574. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  575. ** Bar
  576. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  577. (test-org-clock-clocktable-contents ":compact t :level t")))))
  578. (ert-deftest test-org-clock/clocktable/properties ()
  579. "Test \":properties\" parameter in Clock table."
  580. ;; Include a new column with list 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. (should
  596. (equal
  597. "| A | Headline | Time | |
  598. |---+--------------+---------+-------|
  599. | | *Total time* | *52:00* | |
  600. |---+--------------+---------+-------|
  601. | | Foo | 52:00 | |
  602. | 1 | \\_ Bar | | 26:00 |"
  603. (org-test-with-temp-text
  604. "* Foo
  605. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00
  606. ** Bar
  607. :PROPERTIES:
  608. :A: 1
  609. :END:
  610. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  611. (test-org-clock-clocktable-contents ":properties (\"A\")"))))
  612. ;; Handle missing properties.
  613. (should
  614. (equal
  615. "| A | Headline | Time | |
  616. |---+--------------+---------+---|
  617. | | *Total time* | *26:00* | |
  618. |---+--------------+---------+---|
  619. | 1 | Foo | 26:00 | |"
  620. (org-test-with-temp-text
  621. "* Foo
  622. :PROPERTIES:
  623. :A: 1
  624. :END:
  625. CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
  626. (test-org-clock-clocktable-contents ":properties (\"A\")")))))
  627. (provide 'test-org-clock)
  628. ;;; test-org-clock.el end here