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