]> gitweb.fperrin.net Git - atom.el.git/blob - atom-tests.el
941580a32d598f9e5b5bdc535f2a75155d5b9f1d
[atom.el.git] / atom-tests.el
1 ;;; atom-tests.el --- Tests for the atom.el library  -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2024  Frédéric Perrin
4
5 ;; Author: Frédéric Perrin <frederic.perrin@resel.fr>
6 ;; Keywords: 
7
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.
12
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.
17
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/>.
20
21 ;;; Commentary:
22
23 ;; 
24
25 ;;; Code:
26
27 (normal-top-level-add-to-load-path (list default-directory))
28 (require 'atom)
29
30
31 (ert-deftest text-feed ()
32   (let* ((user-full-name "John Smith")
33          (user-mail-address "john.smith@example.org")
34          (now (current-time))
35          (my-atom-feed (atom-create "My feed" "http://example.org"
36                                     (list :updated now))))
37     ;; A simple, text-only entry
38     (atom-add-text-entry
39      my-atom-feed
40      "Hello world"
41      "http://example.org/hello"
42      "Hello the world!"
43      (list :updated now))
44
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>
56     ;; </entry>
57     ;; </feed>
58
59     (with-temp-buffer
60       (atom-print my-atom-feed)
61       (let ((expected-strings
62              (list
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)))))))
84
85 (ert-deftest html-xhtml-feed ()
86   (let ((my-atom-feed (atom-create "My feed" "http://example.org")))
87
88     (atom-add-text-entry
89      my-atom-feed
90      "A text entry"
91      "http://example.org/text"
92      "Some text only")
93     (atom-add-html-entry
94      my-atom-feed
95      "An HTML entry"
96      "http://example.org/html"
97      "<p>One can also use <acronym>HTML</acronym> in the entries.</p>")
98     (atom-add-xhtml-entry
99      my-atom-feed
100      "A xHTML entry"
101      "http://example.org/xhtml"
102      "<p>One can also use <acronym>xHTML</acronym> in the entries.</p>")
103
104     ;; only check that we can print the feed...
105     (atom-print my-atom-feed)
106     (atom-print-as-rss my-atom-feed)))
107
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")))))
115     (atom-add-text-entry
116      my-atom-feed
117      "A text entry"
118      "http://example.org/text"
119      "Some text"
120      (list :updated (atom-parse-time "2024-03-23T01:02:04+0400")
121            :summary "summary"))
122     (atom-add-html-entry
123      my-atom-feed
124      "A HTLM entry"
125      "http://example.org/html"
126      "<p>Some text</p>"
127      (list :updated (atom-parse-time "2024-03-23T01:02:05+04:00")
128            :summary "<p>summary...</p>"))
129     (atom-add-xhtml-entry
130      my-atom-feed
131      "A XHTML entry"
132      "http://example.org/xhtml"
133      "<p>Some text</p>"
134      (list :updated (atom-parse-time "2024-03-23T01:02:06+04:00")
135            :summary "<p>summary...</p>"))
136
137     (atom-print my-atom-feed)
138     (atom-print-as-rss my-atom-feed "http://example.org/feed.rss")))
139
140 (provide 'atom-tests)
141 ;;; atom-tests.el ends here