;;; atom-tests.el --- Tests for the atom.el library -*- lexical-binding: t; -*- ;; Copyright (C) 2024 Frédéric Perrin ;; Author: Frédéric Perrin ;; Keywords: ;; This program is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation, either version 3 of the License, or ;; (at your option) any later version. ;; This program is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with this program. If not, see . ;;; Commentary: ;; ;;; Code: (normal-top-level-add-to-load-path (list default-directory)) (require 'atom) (ert-deftest text-feed () (let* ((user-full-name "John Smith") (user-mail-address "john.smith@example.org") (now (current-time)) (my-atom-feed (atom-create "My feed" "http://example.org" (list :updated now)))) ;; A simple, text-only entry (atom-add-text-entry my-atom-feed "Hello world" "http://example.org/hello" "Hello the world!" (list :updated now)) ;; ;; ;; My feed ;; John Smith ;; john.smith@example.org ;; 2024-03-13T21:55:38+00:00http://example.org ;; Hello world ;; ;; http://example.org/hello ;; 2024-03-13T21:54:14+00:00 ;; Hello the world! ;; ;; (with-temp-buffer (atom-print my-atom-feed) (let ((expected-strings (list "My feed" "John Smith" "john.smith@example.org" "" "[[:space:]]+Hello world" "" "http://example.org/hello" "Hello the world!"))) (dolist (exp-string expected-strings) (goto-char (point-min)) (should (re-search-forward exp-string)))) (goto-char (point-min)) ;; there will be two updated elements, for the feed and the entry (re-search-forward "updated>\\(.*\\)") (let* ((updated-string (match-string 1)) (updated-time (atom-parse-time updated-string))) (should (equal updated-time (seq-take now 2)))) (re-search-forward "updated>\\(.*\\)") (let* ((updated-string (match-string 1)) (updated-time (atom-parse-time updated-string))) (should (equal updated-time (seq-take now 2))))))) (ert-deftest html-xhtml-feed () (let ((my-atom-feed (atom-create "My feed" "http://example.org"))) (atom-add-text-entry my-atom-feed "A text entry" "http://example.org/text" "Some text only") (atom-add-html-entry my-atom-feed "An HTML entry" "http://example.org/html" "

One can also use HTML in the entries.

") (atom-add-xhtml-entry my-atom-feed "A xHTML entry" "http://example.org/xhtml" "

One can also use xHTML in the entries.

") ;; only check that we can print the feed... (atom-print my-atom-feed) (atom-print-as-rss my-atom-feed))) (ert-deftest atom-opt-elements () (let ((my-atom-feed (atom-create "My Feed" "http://example.org" (list :subtitle "Feed subtitle" :self "http://example.org/feed.atom" :id "urn:example-id:1" :author (list "Author name" "Author@example.org") :updated (atom-parse-time "2024-03-23T01:02:03+04:00"))))) (atom-add-text-entry my-atom-feed "A text entry" "http://example.org/text" "Some text" (list :updated (atom-parse-time "2024-03-23T01:02:04+0400") :published (atom-parse-time "2024-03-23T01:02:04+0400") :summary "Summary")) (atom-add-html-entry my-atom-feed "A HTLM entry" "http://example.org/html" "

Some text

" (list :updated (atom-parse-time "2024-03-23T01:02:05+04:00") :summary "

summary...

")) (atom-add-xhtml-entry my-atom-feed "A XHTML entry" "http://example.org/xhtml" "

Some text

" (list :updated (atom-parse-time "2024-03-23T01:02:06+04:00") :summary "

summary...

")) (atom-print my-atom-feed) (atom-print-as-rss my-atom-feed "http://example.org/feed.rss"))) (provide 'atom-tests) ;;; atom-tests.el ends here