Merge branch 'maint'
[org-mode.git] / testing / lisp / test-org-feed.el
blobd28abb990f206b9f06dc39e88565a94a0e62647e
1 ;;; test-org-feed.el --- Tests for org-feed.el -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2016 Michael Brand
5 ;; Author: Michael Brand <michael.ch.brand@gmail.com>
7 ;; This program is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ;;; Commentary:
22 ;; Unit tests for Org Feed library.
24 ;;; Code:
26 (require 'org-feed)
28 (ert-deftest test-org-feed/fill-template ()
29 "Test `org-feed-format-entry' template specifications."
31 ;; When working on these tests consider to also change
32 ;; `test-org-capture/fill-template'.
34 ;; %(sexp) placeholder.
35 (should
36 (equal "success!"
37 (org-feed-format-entry nil "%(concat \"success\" \"!\")" nil)))
38 ;; %a placeholder.
39 (should
40 (equal "[[http://orgmode.org]]\n"
41 (org-feed-format-entry '(:link "http://orgmode.org") "%a" nil)))
42 ;; %t and %T placeholders.
43 (should
44 (equal (format-time-string (org-time-stamp-format nil nil))
45 (org-feed-format-entry nil "%t" nil)))
46 (should
47 (string-match-p
48 "<2016-01-02 \\S-+>"
49 (org-feed-format-entry
50 '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%t" nil)))
51 (should
52 (equal (format-time-string (org-time-stamp-format t nil))
53 (org-feed-format-entry nil "%T" nil)))
54 (should
55 (string-match-p
56 "<2016-01-02 \\S-+ 12:00>"
57 (org-feed-format-entry
58 '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%T" nil)))
59 ;; %u and %U placeholders.
60 (should
61 (equal (format-time-string (org-time-stamp-format nil t))
62 (org-feed-format-entry nil "%u" nil)))
63 (should
64 (string-match-p
65 "[2016-01-02 \\S-+]"
66 (org-feed-format-entry
67 '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%u" nil)))
68 (should
69 (equal (format-time-string (org-time-stamp-format t t))
70 (org-feed-format-entry nil "%U" nil)))
71 (should
72 (string-match-p
73 "[2016-01-02 \\S-+ 12:00]"
74 (org-feed-format-entry
75 '(:pubDate "Sat, 02 Jan 2016 12:00:00 +0000") "%U" nil)))
76 ;; %h placeholder. Make sure sexp placeholders are not expanded
77 ;; when they are inserted through this one.
78 (should
79 (equal "success!"
80 (org-feed-format-entry '(:title "success!") "%h" nil)))
81 (should
82 (equal "%(concat \"no \" \"evaluation\")"
83 (org-feed-format-entry
84 '(:title "%(concat \"no \" \"evaluation\")") "%h" nil)))
85 ;; Test %-escaping with \ character.
86 (should
87 (equal "%h"
88 (org-feed-format-entry '(:title "success!") "\\%h" nil)))
89 (should
90 (equal "\\success!"
91 (org-feed-format-entry '(:title "success!") "\\\\%h" nil)))
92 (should
93 (equal "\\%h"
94 (org-feed-format-entry '(:title "success!") "\\\\\\%h" nil)))
95 ;; More than one placeholder in the same template.
96 (should
97 (equal "success! success! success! success!"
98 (org-feed-format-entry '(:title "success!") "%h %h %h %h" nil)))
99 ;; %(sexp) placeholder with an input containing the traps %, ", )
100 ;; and \n all at once which is complicated to parse.
101 (should
102 (equal
103 "5 % Less (See\n Item \"3)\" Somewhere)"
104 (org-feed-format-entry
105 '(:title "5 % less (see\n item \"3)\" somewhere)")
106 "%(capitalize \"%h\")" nil))))
111 (provide 'test-org-feed)
112 ;;; test-org-feed.el ends here