瀏覽代碼

org-clock: Add test

* testing/lisp/test-org-clock.el (test-org-clock/clocktable/link): New
  test.
Nicolas Goaziou 8 年之前
父節點
當前提交
4e5bc38040
共有 1 個文件被更改,包括 124 次插入0 次删除
  1. 124 0
      testing/lisp/test-org-clock.el

+ 124 - 0
testing/lisp/test-org-clock.el

@@ -532,6 +532,130 @@ CLOCK: [2016-12-28 Wed 13:09]--[2016-12-28 Wed 15:09] =>  2:00"
   CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
       (test-org-clock-clocktable-contents ":maxlevel 1 :lang foo")))))
 
+(ert-deftest test-org-clock/clocktable/link ()
+  "Test \":link\" parameter in Clock table."
+  ;; If there is no file attached to the document, link directly to
+  ;; the headline.
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  ;; Otherwise, link to the headline in the current file.
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[file:filename::Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text-in-file
+	"* Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (let ((file (buffer-file-name)))
+	(replace-regexp-in-string
+	 (regexp-quote file) "filename"
+	 (test-org-clock-clocktable-contents ":link t"))))))
+  ;; Ignore TODO keyword, priority cookie, COMMENT and tags in
+  ;; headline.
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* TODO Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* [#A] Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* COMMENT Foo
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo :tag:
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  ;; Remove statistics cookie from headline description.
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo [50%]
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo][Foo]]          | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo [1/2]
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  ;; Replace links with their description, or turn them into plain
+  ;; links if there is no description.
+  (should
+   (equal
+    "| Headline     | Time    |   |
+|--------------+---------+---|
+| *Total time* | *26:00* |   |
+|--------------+---------+---|
+| [[Foo%20%5B%5Bhttp://orgmode.org%5D%5BOrg%20mode%5D%5D][Foo Org mode]] | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo [[http://orgmode.org][Org mode]]
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t"))))
+  (should
+   (equal
+    "| Headline               | Time    |   |
+|------------------------+---------+---|
+| *Total time*           | *26:00* |   |
+|------------------------+---------+---|
+| [[Foo%20%5B%5Bhttp://orgmode.org%5D%5D][Foo http://orgmode.org]] | 26:00   |   |"
+    (org-test-with-temp-text
+	"* Foo [[http://orgmode.org]]
+CLOCK: [2016-12-27 Wed 13:09]--[2016-12-28 Wed 15:09] => 26:00"
+      (test-org-clock-clocktable-contents ":link t")))))
+
 (ert-deftest test-org-clock/clocktable/compact ()
   "Test \":compact\" parameter in Clock table."
   ;; With :compact, all headlines are in the same column.