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")
34 (my-atom-feed (atom-create "My feed" "http://example.org"))
36 ;; A simple, text-only entry
40 "http://example.org/hello"
44 ;; <?xml version="1.0" encoding="utf-8"?>
45 ;; <feed xmlns="http://www.w3.org/2005/Atom">
46 ;; <title>My feed</title><link href="http://example.org"/><author>
47 ;; <name>John Smith</name>
48 ;; <email>john.smith@example.org</email>
49 ;; </author><updated>2024-03-13T21:55:38+00:00</updated><id>http://example.org</id><entry>
50 ;; <title>Hello world</title>
51 ;; <link href="http://example.org/hello"/>
52 ;; <id>http://example.org/hello</id>
53 ;; <updated>2024-03-13T21:54:14+00:00</updated>
54 ;; <content>Hello the world!</content>
59 (atom-print my-atom-feed)
60 (let ((expected-strings
62 "<title>My feed</title>"
63 "<name>John Smith</name>"
64 "<email>john.smith@example.org</email>"
65 "<link href=\"http://example.org\"/>"
66 "<entry>[[:space:]]+<title>Hello world</title>"
67 "<link href=\"http://example.org/hello\"/>"
68 "<id>http://example.org/hello</id>"
69 "<content>Hello the world!</content>")))
70 (dolist (exp-string expected-strings)
71 (goto-char (point-min))
72 (should (re-search-forward exp-string))))
73 (goto-char (point-min))
74 (re-search-forward "updated>\\(.*\\)</updated>")
75 (let* ((updated-string (match-string 1))
76 (updated-time (atom-parse-time updated-string)))
77 (should (equal updated-time (seq-take now 2)))))))
79 (ert-deftest html-xhtml-feed ()
80 (let ((my-atom-feed (atom-create "My feed" "http://example.org")))
85 "http://example.org/text"
90 "http://example.org/html"
91 "<p>One can also use <acronym>HTML</acronym> in the entries.</p>")
95 "http://example.org/xhtml"
96 "<p>One can also use <acronym>xHTML</acronym> in the entries.</p>")
98 ;; only check that we can print the feed...
99 (atom-print my-atom-feed)
100 (atom-print-as-rss my-atom-feed)))
102 (ert-deftest atom-opt-elements ()
103 (let ((my-atom-feed (atom-create "My Feed" "http://example.org"
104 "Feed subtitle" ; subtitle
105 "http://example.org/feed.atom" ; self link
106 "urn:example-id" ; id
107 (cons "Author name" "Author addr")
108 "2024-04-23T01:02:03+04:00" ; updated
113 "http://example.org/text"
115 "2024-04-23T01:02:03+04:00" ; updated
116 (atom-generate-id "http://example.org/text" (current-time)))))
118 (provide 'atom-tests)
119 ;;; atom-tests.el ends here