test-org-datetree.el 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; test-org-datetree.el --- Tests for Org Datetree -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
  4. ;; This file is not part of GNU Emacs.
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Code:
  16. (ert-deftest test-org-datetree/find-date-create ()
  17. "Test `org-datetree-find-date-create' specifications."
  18. ;; When date is missing, create it.
  19. (should
  20. (string-match
  21. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
  22. (org-test-with-temp-text ""
  23. (let ((org-datetree-add-timestamp nil))
  24. (org-datetree-find-date-create '(3 29 2012)))
  25. (org-trim (buffer-string)))))
  26. ;; Do not create new year node when one exists.
  27. (should
  28. (string-match
  29. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
  30. (org-test-with-temp-text "* 2012\n"
  31. (let ((org-datetree-add-timestamp nil))
  32. (org-datetree-find-date-create '(3 29 2012)))
  33. (org-trim (buffer-string)))))
  34. ;; Do not create new month node when one exists.
  35. (should
  36. (string-match
  37. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
  38. (org-test-with-temp-text "* 2012\n** 2012-03 month"
  39. (let ((org-datetree-add-timestamp nil))
  40. (org-datetree-find-date-create '(3 29 2012)))
  41. (org-trim (buffer-string)))))
  42. ;; Do not create new day node when one exists.
  43. (should
  44. (string-match
  45. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* 2012-03-29 .*\\'"
  46. (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
  47. (let ((org-datetree-add-timestamp nil))
  48. (org-datetree-find-date-create '(3 29 2012)))
  49. (org-trim (buffer-string)))))
  50. ;; When `org-datetree-add-timestamp' is non-nil, insert a timestamp
  51. ;; in entry. When set to `inactive', insert an inactive one.
  52. (should
  53. (string-match
  54. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*<\\1.*?>\\'"
  55. (org-test-with-temp-text "* 2012\n"
  56. (let ((org-datetree-add-timestamp t))
  57. (org-datetree-find-date-create '(3 29 2012)))
  58. (org-trim (buffer-string)))))
  59. (should
  60. (string-match
  61. "\\`\\* 2012\n\\*\\* 2012-03 .*\n\\*\\*\\* \\(2012-03-29\\) .*\n[ \t]*\\[\\1.*?\\]\\'"
  62. (org-test-with-temp-text "* 2012\n"
  63. (let ((org-datetree-add-timestamp 'inactive))
  64. (org-datetree-find-date-create '(3 29 2012)))
  65. (org-trim (buffer-string)))))
  66. ;; Insert at top level, unless some node has DATE_TREE property. In
  67. ;; this case, date tree becomes one of its sub-trees.
  68. (should
  69. (string-match
  70. "\\* 2012"
  71. (org-test-with-temp-text "* Top"
  72. (let ((org-datetree-add-timestamp nil))
  73. (org-datetree-find-date-create '(3 29 2012)))
  74. (org-trim (buffer-string)))))
  75. (should
  76. (string-match
  77. "\\*\\* H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n\\*\\*\\* 2012"
  78. (org-test-with-temp-text
  79. "* H1\n** H1.1\n:PROPERTIES:\n:DATE_TREE: t\n:END:\n* H2"
  80. (let ((org-datetree-add-timestamp nil))
  81. (org-datetree-find-date-create '(3 29 2012)))
  82. (org-trim (buffer-string)))))
  83. ;; Always leave point at beginning of day entry.
  84. (should
  85. (string-match
  86. "\\*\\*\\* 2012-03-29"
  87. (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
  88. (let ((org-datetree-add-timestamp nil))
  89. (org-datetree-find-date-create '(3 29 2012)))
  90. (buffer-substring (point) (line-end-position)))))
  91. (should
  92. (string-match
  93. "\\*\\*\\* 2012-03-29"
  94. (org-test-with-temp-text "* 2012\n** 2012-03 month\n*** 2012-03-29 day"
  95. (let ((org-datetree-add-timestamp t))
  96. (org-datetree-find-date-create '(3 29 2012)))
  97. (buffer-substring (point) (line-end-position))))))
  98. (provide 'test-org-datetree)
  99. ;;; test-org-datetree.el ends here