test-org-capture.el 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;;; test-org-capture.el --- Tests for org-capture.el -*- lexical-binding: t; -*-
  2. ;; Copyright (C) 2015 Nicolas Goaziou
  3. ;; Author: Nicolas Goaziou <mail@nicolasgoaziou.fr>
  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 Capture library.
  16. ;;; Code:
  17. (require 'org-capture)
  18. (ert-deftest test-org-capture/fill-template ()
  19. "Test `org-capture-fill-template' specifications."
  20. ;; When working on these tests consider to also change
  21. ;; `test-org-feed/fill-template'.
  22. ;; %(sexp) placeholder.
  23. (should
  24. (equal "success!\n"
  25. (org-capture-fill-template "%(concat \"success\" \"!\")")))
  26. ;; %<...> placeholder.
  27. (should
  28. (equal (concat (format-time-string "%Y") "\n")
  29. (org-capture-fill-template "%<%Y>")))
  30. ;; %t and %T placeholders.
  31. (should
  32. (equal (concat (format-time-string (org-time-stamp-format nil nil)) "\n")
  33. (org-capture-fill-template "%t")))
  34. (should
  35. (equal (concat (format-time-string (org-time-stamp-format t nil)) "\n")
  36. (org-capture-fill-template "%T")))
  37. ;; %u and %U placeholders.
  38. (should
  39. (equal
  40. (concat (format-time-string (org-time-stamp-format nil t)) "\n")
  41. (org-capture-fill-template "%u")))
  42. (should
  43. (equal
  44. (concat (format-time-string (org-time-stamp-format t t)) "\n")
  45. (org-capture-fill-template "%U")))
  46. ;; %i placeholder. Make sure sexp placeholders are not expanded
  47. ;; when they are inserted through this one.
  48. (should
  49. (equal "success!\n"
  50. (let ((org-store-link-plist nil))
  51. (org-capture-fill-template "%i" "success!"))))
  52. (should
  53. (equal "%(concat \"no \" \"evaluation\")\n"
  54. (let ((org-store-link-plist nil))
  55. (org-capture-fill-template
  56. "%i" "%(concat \"no \" \"evaluation\")"))))
  57. ;; Test %-escaping with \ character.
  58. (should
  59. (equal "%i\n"
  60. (let ((org-store-link-plist nil))
  61. (org-capture-fill-template "\\%i" "success!"))))
  62. (should
  63. (equal "\\success!\n"
  64. (let ((org-store-link-plist nil))
  65. (org-capture-fill-template "\\\\%i" "success!"))))
  66. (should
  67. (equal "\\%i\n"
  68. (let ((org-store-link-plist nil))
  69. (org-capture-fill-template "\\\\\\%i" "success!"))))
  70. ;; More than one placeholder in the same template.
  71. (should
  72. (equal "success! success! success! success!\n"
  73. (let ((org-store-link-plist nil))
  74. (org-capture-fill-template "%i %i %i %i" "success!"))))
  75. ;; %(sexp) placeholder with an input containing the traps %, " and )
  76. ;; all at once which is complicated to parse.
  77. (should
  78. (equal
  79. "5 % Less (See Item \"3)\" Somewhere)\n"
  80. (let ((org-store-link-plist nil))
  81. (org-capture-fill-template
  82. "%(capitalize \"%i\")"
  83. "5 % less (see item \"3)\" somewhere)")))))
  84. (provide 'test-org-capture)
  85. ;;; test-org-capture.el ends here