]> gitweb.fperrin.net Git - atom.el.git/blob - atom-tests.el
Add published propety
[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          (my-atom-feed (atom-create "My feed" "http://example.org"))
35          (now (current-time)))
36     ;; A simple, text-only entry
37     (atom-add-text-entry
38      my-atom-feed
39      "Hello world"
40      "http://example.org/hello"
41      "Hello the world!"
42      now)
43
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>
55     ;; </entry>
56     ;; </feed>
57
58     (with-temp-buffer
59       (atom-print my-atom-feed)
60       (let ((expected-strings
61              (list
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)))))))
78
79 (ert-deftest html-xhtml-feed ()
80   (let ((my-atom-feed (atom-create "My feed" "http://example.org")))
81
82     (atom-add-text-entry
83      my-atom-feed
84      "A text entry"
85      "http://example.org/text"
86      "Some text only")
87     (atom-add-html-entry
88      my-atom-feed
89      "An HTML entry"
90      "http://example.org/html"
91      "<p>One can also use <acronym>HTML</acronym> in the entries.</p>")
92     (atom-add-xhtml-entry
93      my-atom-feed
94      "A xHTML entry"
95      "http://example.org/xhtml"
96      "<p>One can also use <acronym>xHTML</acronym> in the entries.</p>")
97
98     ;; only check that we can print the feed...
99     (atom-print my-atom-feed)
100     (atom-print-as-rss my-atom-feed)))
101
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
109                                    )))
110     (atom-add-text-entry
111      my-atom-feed
112      "A text entry"
113      "http://example.org/text"
114      "Some text"
115      "2024-04-23T01:02:03+04:00" ; updated
116      (atom-generate-id "http://example.org/text" (current-time)))))
117
118 (provide 'atom-tests)
119 ;;; atom-tests.el ends here