1 ;;; atom-tests.el --- Tests for the atom.el library -*- lexical-binding: t; -*-
3 ;; Copyright (C) 2024 Frédéric Perrin
5 ;; Author: Frédéric Perrin <frederic.perrin@resel.fr>
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
27 (normal-top-level-add-to-load-path (list default-directory))
31 (ert-deftest text-feed ()
32 (let* ((user-full-name "John Smith")
33 (user-mail-address "john.smith@example.org")
35 (my-atom-feed (atom-create "My feed" "http://example.org"
36 (list :updated now))))
37 ;; A simple, text-only entry
41 "http://example.org/hello"
45 ;; <?xml version="1.0" encoding="utf-8"?>
46 ;; <feed xmlns="http://www.w3.org/2005/Atom">
47 ;; <title>My feed</title><link href="http://example.org"/><author>
48 ;; <name>John Smith</name>
49 ;; <email>john.smith@example.org</email>
50 ;; </author><updated>2024-03-13T21:55:38+00:00</updated><id>http://example.org</id><entry>
51 ;; <title>Hello world</title>
52 ;; <link href="http://example.org/hello"/>
53 ;; <id>http://example.org/hello</id>
54 ;; <updated>2024-03-13T21:54:14+00:00</updated>
55 ;; <content>Hello the world!</content>
60 (atom-print my-atom-feed)
61 (let ((expected-strings
63 "<title>My feed</title>"
64 "<name>John Smith</name>"
65 "<email>john.smith@example.org</email>"
66 "<link href=\"http://example.org\"/>"
67 "<entry>[[:space:]]+<title>Hello world</title>"
68 "<link href=\"http://example.org/hello\"/>"
69 "<id>http://example.org/hello</id>"
70 "<content>Hello the world!</content>")))
71 (dolist (exp-string expected-strings)
72 (goto-char (point-min))
73 (should (re-search-forward exp-string))))
74 (goto-char (point-min))
75 ;; there will be two updated elements, for the feed and the entry
76 (re-search-forward "updated>\\(.*\\)</updated>")
77 (let* ((updated-string (match-string 1))
78 (updated-time (atom-parse-time updated-string)))
79 (should (equal updated-time (seq-take now 2))))
80 (re-search-forward "updated>\\(.*\\)</updated>")
81 (let* ((updated-string (match-string 1))
82 (updated-time (atom-parse-time updated-string)))
83 (should (equal updated-time (seq-take now 2)))))))
85 (ert-deftest html-xhtml-feed ()
86 (let ((my-atom-feed (atom-create "My feed" "http://example.org")))
91 "http://example.org/text"
96 "http://example.org/html"
97 "<p>One can also use <acronym>HTML</acronym> in the entries.</p>")
101 "http://example.org/xhtml"
102 "<p>One can also use <acronym>xHTML</acronym> in the entries.</p>")
104 ;; only check that we can print the feed...
105 (atom-print my-atom-feed)
106 (atom-print-as-rss my-atom-feed)))
108 (ert-deftest atom-opt-elements ()
109 (let ((my-atom-feed (atom-create "My Feed" "http://example.org"
110 (list :subtitle "Feed subtitle"
111 :self "http://example.org/feed.atom"
112 :id "urn:example-id:1"
113 :author (list "Author name" "Author@example.org")
114 :updated (atom-parse-time "2024-03-23T01:02:03+04:00")))))
118 "http://example.org/text"
120 (list :updated (atom-parse-time "2024-03-23T01:02:04+0400")
125 "http://example.org/html"
127 (list :updated (atom-parse-time "2024-03-23T01:02:05+04:00")
128 :summary "<p>summary...</p>"))
129 (atom-add-xhtml-entry
132 "http://example.org/xhtml"
134 (list :updated (atom-parse-time "2024-03-23T01:02:06+04:00")
135 :summary "<p>summary...</p>"))
137 (atom-print my-atom-feed)
138 (atom-print-as-rss my-atom-feed)))
140 (provide 'atom-tests)
141 ;;; atom-tests.el ends here