test-org-agenda.el 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. ;; Auxilliaries for set-up and tear-down and more.
  20. (defun -sha1-as-defun-name-accc70505c6664ed226e3afa45ca0ecc95a35e83 ()
  21. "Name a function with the sha1 of the function text.
  22. Use this function if you are too lazy to invent a function name.
  23. The function text starts at the argument list and ends at the
  24. last paren (exclusive)."
  25. (interactive)
  26. (save-excursion
  27. (let* ((start (progn
  28. (beginning-of-defun)
  29. (search-forward-regexp "\(" nil nil 2)
  30. (backward-char)
  31. (point)))
  32. (end (progn
  33. (end-of-defun)
  34. (backward-char)
  35. (point)))
  36. (sha1 (sha1 (current-buffer) start end)))
  37. ;; relying on (point) is within the defun
  38. (progn
  39. (beginning-of-defun)
  40. (search-forward-regexp " ")
  41. (skip-chars-forward " \t")
  42. (just-one-space))
  43. (unless (= ?\( (char-after))
  44. (delete-region (point) (progn (forward-word) (point)))
  45. (just-one-space))
  46. (insert sha1 " "))))
  47. (defun -kill-all-agendas ()
  48. "Kill all agenda buffers."
  49. (mapc #'kill-buffer
  50. (cl-remove-if-not
  51. (lambda (x)
  52. (set-buffer x)
  53. (eq major-mode 'org-agenda-mode))
  54. (buffer-list))))
  55. ;; Test the Agenda
  56. (ert-deftest org-e9d91f5add1245445ba773dd74ac534273113ca5 ()
  57. "Empty agenda."
  58. (let ((org-agenda-span 'day)
  59. org-agenda-files)
  60. (org-agenda-list)
  61. (set-buffer org-agenda-buffer-name)
  62. (should (= 2 (count-lines (point-min) (point-max))))))
  63. (ert-deftest org-a0116aeccdedc04580e42933a16c2893d76ee6bc ()
  64. "One informative line in the agenda."
  65. (let ((org-agenda-span 'day)
  66. (org-agenda-files `(,(expand-file-name "examples/agenda-file.org" org-test-dir))))
  67. (org-agenda-list nil "<2017-03-10 Fri>")
  68. (set-buffer org-agenda-buffer-name)
  69. (should (= 3 (count-lines (point-min) (point-max))))))
  70. (ert-deftest org-165802102bb2d2accf16ff0ae362ef51945ae69f ()
  71. "Agenda buffer name after having created one sticky agenda buffer."
  72. (-kill-all-agendas)
  73. ;; (setq org-agenda-buffer-name "*Org Agenda*")
  74. (let ((org-agenda-span 'day)
  75. (org-agenda-buffer-name "*Org Agenda*")
  76. (default-org-agenda-buffer-name org-agenda-buffer-name)
  77. (buf (get-buffer org-agenda-buffer-name))
  78. org-agenda-files)
  79. (when buf (kill-buffer buf))
  80. (org-test-with-temp-text "<2017-03-17 Fri>"
  81. (org-follow-timestamp-link) ; creates a sticky agenda.
  82. )
  83. (-kill-all-agendas)
  84. (org-agenda-list)
  85. (let ((agenda-buffers
  86. (cl-remove-if-not
  87. (lambda (x)
  88. (set-buffer x)
  89. (eq major-mode 'org-agenda-mode))
  90. (buffer-list))))
  91. (should (= 1 (length agenda-buffers)))
  92. (should (string= default-org-agenda-buffer-name
  93. (buffer-name (car agenda-buffers))))))
  94. (-kill-all-agendas))
  95. (provide 'test-org-agenda)
  96. ;;; test-org-agenda.el ends here