test-org-feed.el 3.5 KB

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