test-org-element.el 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. ;;; test-org-element.el --- Tests for org-element.el
  2. ;; Copyright (C) 2012 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <n.goaziou at gmail dot 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. ;;; Code:
  16. (let ((load-path (cons (expand-file-name
  17. ".." (file-name-directory
  18. (or load-file-name buffer-file-name)))
  19. load-path)))
  20. (require 'org-test)
  21. (require 'org-test-ob-consts)
  22. (require 'org-element))
  23. ;;; Tests:
  24. ;;;; Headlines
  25. (ert-deftest test-org-element/headline-quote-keyword ()
  26. "Test QUOTE keyword recognition."
  27. ;; Reference test.
  28. (org-test-with-temp-text "* Headline"
  29. (let ((org-quote-string "QUOTE"))
  30. (should-not (org-element-property :quotedp (org-element-at-point)))))
  31. ;; Standard position.
  32. (org-test-with-temp-text "* QUOTE Headline"
  33. (let ((org-quote-string "QUOTE"))
  34. (let ((headline (org-element-at-point)))
  35. (should (org-element-property :quotedp headline))
  36. ;; Test removal from raw value.
  37. (should (equal (org-element-property :raw-value headline) "Headline"))))
  38. ;; Case sensitivity.
  39. (let ((org-quote-string "Quote"))
  40. (should-not (org-element-property :quotedp (org-element-at-point)))))
  41. ;; With another keyword.
  42. (org-test-with-temp-text "* TODO QUOTE Headline"
  43. (let ((org-quote-string "QUOTE")
  44. (org-todo-keywords '((sequence "TODO" "DONE"))))
  45. (should (org-element-property :quotedp (org-element-at-point))))))
  46. (ert-deftest test-org-element/headline-comment-keyword ()
  47. "Test COMMENT keyword recognition."
  48. ;; Reference test.
  49. (org-test-with-temp-text "* Headline"
  50. (let ((org-comment-string "COMMENT"))
  51. (should-not (org-element-property :commentedp (org-element-at-point)))))
  52. ;; Standard position.
  53. (org-test-with-temp-text "* COMMENT Headline"
  54. (let ((org-comment-string "COMMENT"))
  55. (let ((headline (org-element-at-point)))
  56. (should (org-element-property :commentedp headline))
  57. ;; Test removal from raw value.
  58. (should (equal (org-element-property :raw-value headline) "Headline"))))
  59. ;; Case sensitivity.
  60. (let ((org-comment-string "Comment"))
  61. (should-not (org-element-property :commentedp (org-element-at-point)))))
  62. ;; With another keyword.
  63. (org-test-with-temp-text "* TODO COMMENT Headline"
  64. (let ((org-comment-string "COMMENT")
  65. (org-todo-keywords '((sequence "TODO" "DONE"))))
  66. (should (org-element-property :commentedp (org-element-at-point))))))
  67. (ert-deftest test-org-element/headline-archive-tag ()
  68. "Test ARCHIVE tag recognition."
  69. ;; Reference test.
  70. (org-test-with-temp-text "* Headline"
  71. (let ((org-archive-tag "ARCHIVE"))
  72. (should-not (org-element-property :archivedp (org-element-at-point)))))
  73. ;; Single tag.
  74. (org-test-with-temp-text "* Headline :ARCHIVE:"
  75. (let ((org-archive-tag "ARCHIVE"))
  76. (let ((headline (org-element-at-point)))
  77. (should (org-element-property :archivedp headline))
  78. ;; Test tag removal.
  79. (should-not (org-element-property :tags headline))))
  80. (let ((org-archive-tag "Archive"))
  81. (should-not (org-element-property :archivedp (org-element-at-point)))))
  82. ;; Multiple tags.
  83. (org-test-with-temp-text "* Headline :test:ARCHIVE:"
  84. (let ((org-archive-tag "ARCHIVE"))
  85. (let ((headline (org-element-at-point)))
  86. (should (org-element-property :archivedp headline))
  87. ;; Test tag removal.
  88. (should (equal (org-element-property :tags headline) ":test:"))))))
  89. (provide 'test-org-element)
  90. ;;; test-org-element.el ends here