test-org-agenda.el 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. ;;; test-org-agenda.el --- Tests for org-agenda.el -*- lexical-binding: t ; -*-
  2. ;; Copyright (C) 2017 Marco Wahl
  3. ;; Author: Marco Wahl <marcowahlsoft@gmail.com>
  4. ;; This program is free software; you can redistribute it and/or modify
  5. ;; it under the terms of the GNU General Public License as published by
  6. ;; the Free Software Foundation, either version 3 of the License, or
  7. ;; (at your option) any later version.
  8. ;; This program is distributed in the hope that it will be useful,
  9. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;; GNU General Public License for more details.
  12. ;; You should have received a copy of the GNU General Public License
  13. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. ;;; Commentary:
  15. ;; Unit tests for Org Agenda.
  16. ;;; Code:
  17. (require 'org-test)
  18. (require 'org-agenda)
  19. ;; General auxilliaries
  20. ;; (possibly better move to some location in the source.)
  21. ;; Prefixing with '---' on this page.
  22. ;; Evaluate the following function for no brainer function naming.
  23. (defun ---sha1-as-defun-name-39e8857766df959d8b52f9c38739f5a77c392ec0 ()
  24. "Insert the sha1 of the function text in front of arglist.
  25. The function text starts at the argument list and ends at the
  26. last paren (exclusive).
  27. Use this function if you are too lazy to invent a function name."
  28. (interactive)
  29. (let* ((start (progn
  30. (beginning-of-defun)
  31. (search-forward-regexp "\(" nil nil 2)
  32. (backward-char)
  33. (point)))
  34. (end (progn
  35. (end-of-defun)
  36. (backward-char)
  37. (point)))
  38. (sha1 (sha1 (current-buffer) start end)))
  39. (goto-char start)
  40. (insert sha1 " ")
  41. (backward-word)))
  42. (defun ---kill-all-agendas ()
  43. "Kill all agenda buffers."
  44. (mapc #'kill-buffer
  45. (cl-remove-if-not
  46. (lambda (x)
  47. (set-buffer x)
  48. (eq major-mode 'org-agenda-mode))
  49. (buffer-list))))
  50. (defun ---agenda-buffers ()
  51. "Return agenda buffers in a list."
  52. (cl-remove-if-not
  53. (lambda (x)
  54. (set-buffer x)
  55. (eq major-mode 'org-agenda-mode))
  56. (buffer-list)))
  57. ;; Test the Agenda
  58. (ert-deftest org-agenda-90c5dce0435b74ba7e9682a4a9a393aeea741739 ()
  59. "Empty agenda."
  60. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  61. (cl-assert (not (---agenda-buffers)) nil "precondition violation")
  62. (let ((org-agenda-span 'day)
  63. org-agenda-files)
  64. (org-agenda-list)
  65. (set-buffer org-agenda-buffer-name)
  66. (should (= 2 (count-lines (point-min) (point-max)))))
  67. (---kill-all-agendas))
  68. (ert-deftest org-agenda-668f0e69003051b79eb421146f7626ac9438c105 ()
  69. "One informative line in the agenda."
  70. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  71. (cl-assert (not (---agenda-buffers)) nil "precondition violation")
  72. (let ((org-agenda-span 'day)
  73. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org" org-test-dir))))
  74. (org-agenda-list nil "<2017-03-10 Fri>")
  75. (set-buffer org-agenda-buffer-name)
  76. (should (= 3 (count-lines (point-min) (point-max)))))
  77. (---kill-all-agendas))
  78. (ert-deftest org-agenda-8e6c85e9ff1ea9fed0ae0fa04ff9a3dace6c9d17 ()
  79. "Agenda buffer name after having created one sticky agenda buffer."
  80. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  81. (cl-assert (not (---agenda-buffers)) nil "precondition violation")
  82. (let ((org-agenda-span 'day)
  83. (buf (get-buffer org-agenda-buffer-name))
  84. org-agenda-files)
  85. (when buf (kill-buffer buf))
  86. (org-test-with-temp-text "<2017-03-17 Fri>"
  87. (org-follow-timestamp-link) ; creates a sticky agenda.
  88. )
  89. (---kill-all-agendas)
  90. (org-agenda-list)
  91. (should (= 1 (length (---agenda-buffers))))
  92. (should (string= "*Org Agenda*"
  93. (buffer-name (car (---agenda-buffers))))))
  94. (---kill-all-agendas))
  95. (ert-deftest org-agenda-9fa27658bf61d8fe2c5b6f9177e9e8ce07f11f7b ()
  96. "Agenda buffer name of sticky agenda after reload."
  97. (cl-assert (not org-agenda-sticky) nil "precondition violation")
  98. (cl-assert (not (---agenda-buffers)) nil "precondition violation")
  99. (org-toggle-sticky-agenda)
  100. (let (org-agenda-files)
  101. (org-agenda-list)
  102. (let* ((agenda-buffer-name
  103. (progn
  104. (assert (= 1 (length (---agenda-buffers))))
  105. (buffer-name (car (---agenda-buffers))))))
  106. (set-buffer agenda-buffer-name)
  107. (org-agenda-redo)
  108. (should (= 1 (length (---agenda-buffers))))
  109. (should (string= agenda-buffer-name
  110. (buffer-name (car (---agenda-buffers)))))))
  111. (org-toggle-sticky-agenda)
  112. (---kill-all-agendas))
  113. (provide 'test-org-agenda)
  114. ;;; test-org-agenda.el ends here