test-org-capture.el 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. ;; %(sexp) placeholder.
  21. (should
  22. (equal "success!\n"
  23. (org-capture-fill-template "%(concat \"success\" \"!\")")))
  24. ;; %<...> placeholder.
  25. (should
  26. (equal (concat (format-time-string "%Y") "\n")
  27. (org-capture-fill-template "%<%Y>")))
  28. ;; %t and %T placeholders.
  29. (should
  30. (equal (concat (format-time-string (car org-time-stamp-formats)) "\n")
  31. (org-capture-fill-template "%t")))
  32. (should
  33. (equal (concat (format-time-string (cdr org-time-stamp-formats)) "\n")
  34. (org-capture-fill-template "%T")))
  35. ;; %u and %U placeholders.
  36. (should
  37. (string-match-p
  38. (format-time-string (substring (car org-time-stamp-formats) 1 -1))
  39. (org-capture-fill-template "%u")))
  40. (should
  41. (string-match-p
  42. (format-time-string (substring (cdr org-time-stamp-formats) 1 -1))
  43. (org-capture-fill-template "%U")))
  44. ;; %i placeholder. Make sure sexp placeholders are not expanded
  45. ;; when they are inserted through this one.
  46. (should
  47. (equal "success!\n"
  48. (let ((org-store-link-plist nil))
  49. (org-capture-fill-template "%i" "success!"))))
  50. (should-not
  51. (equal "failure!\n"
  52. (let ((org-store-link-plist nil))
  53. (org-capture-fill-template "%i" "%(concat \"failure\" \"!\")"))))
  54. ;; Test %-escaping with / character.
  55. (should
  56. (equal "%i\n"
  57. (let ((org-store-link-plist nil))
  58. (org-capture-fill-template "\\%i" "success!"))))
  59. (should
  60. (equal "\\success!\n"
  61. (let ((org-store-link-plist nil))
  62. (org-capture-fill-template "\\\\%i" "success!"))))
  63. (should
  64. (equal "\\%i\n"
  65. (let ((org-store-link-plist nil))
  66. (org-capture-fill-template "\\\\\\%i" "success!")))))
  67. (provide 'test-org-capture)
  68. ;;; test-org-capture.el ends here