;;; 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") (my-atom-feed (atom-create "My feed" "http://example.org")) (now (current-time))) ;; A simple, text-only entry (atom-add-text-entry my-atom-feed "Hello world" "http://example.org/hello" "Hello the world!" 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)) (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" "Feed subtitle" ; subtitle "http://example.org/feed.atom" ; self link "urn:example-id" ; id (cons "Author name" "Author addr") "2024-04-23T01:02:03+04:00" ; updated ))) (atom-add-text-entry my-atom-feed "A text entry" "http://example.org/text" "Some text" "2024-04-23T01:02:03+04:00" ; updated (atom-generate-id "http://example.org/text" (current-time))))) (provide 'atom-tests) ;;; atom-tests.el ends here