test-org-feed.el 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 "[[https://orgmode.org]]\n"
  29. (org-feed-format-entry '(:link "https://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. (string-match-p
  36. "<2016-01-02 \\S-+>"
  37. (org-feed-format-entry
  38. '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%t" nil)))
  39. (should
  40. (equal (format-time-string (org-time-stamp-format t nil))
  41. (org-feed-format-entry nil "%T" nil)))
  42. (should
  43. (string-match-p
  44. "<2016-01-02 \\S-+ 12:00>"
  45. (org-feed-format-entry
  46. '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%T" nil)))
  47. ;; %u and %U placeholders.
  48. (should
  49. (equal (format-time-string (org-time-stamp-format nil t))
  50. (org-feed-format-entry nil "%u" nil)))
  51. (should
  52. (string-match-p
  53. "[2016-01-02 \\S-+]"
  54. (org-feed-format-entry
  55. '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%u" nil)))
  56. (should
  57. (equal (format-time-string (org-time-stamp-format t t))
  58. (org-feed-format-entry nil "%U" nil)))
  59. (should
  60. (string-match-p
  61. "[2016-01-02 \\S-+ 12:00]"
  62. (org-feed-format-entry
  63. '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%U" nil)))
  64. ;; %h placeholder. Make sure sexp placeholders are not expanded
  65. ;; when they are inserted through this one.
  66. (should
  67. (equal "success!"
  68. (org-feed-format-entry '(:title "success!") "%h" nil)))
  69. (should
  70. (equal "%(concat \"no \" \"evaluation\")"
  71. (org-feed-format-entry
  72. '(:title "%(concat \"no \" \"evaluation\")") "%h" nil)))
  73. ;; Test %-escaping with \ character.
  74. (should
  75. (equal "%h"
  76. (org-feed-format-entry '(:title "success!") "\\%h" nil)))
  77. (should
  78. (equal "\\success!"
  79. (org-feed-format-entry '(:title "success!") "\\\\%h" nil)))
  80. (should
  81. (equal "\\%h"
  82. (org-feed-format-entry '(:title "success!") "\\\\\\%h" nil)))
  83. ;; More than one placeholder in the same template.
  84. (should
  85. (equal "success! success! success! success!"
  86. (org-feed-format-entry '(:title "success!") "%h %h %h %h" nil)))
  87. ;; %(sexp) placeholder with an input containing the traps %, ", )
  88. ;; and \n all at once which is complicated to parse.
  89. (should
  90. (equal
  91. "5 % Less (See\n Item \"3)\" Somewhere)"
  92. (org-feed-format-entry
  93. '(:title "5 % less (see\n item \"3)\" somewhere)")
  94. "%(capitalize \"%h\")" nil))))
  95. (provide 'test-org-feed)
  96. ;;; test-org-feed.el ends here