From: Frédéric Perrin Date: Tue, 26 Mar 2024 19:58:28 +0000 (+0000) Subject: Add tests for atom.el X-Git-Url: http://gitweb.fperrin.net/?p=atom.el.git;a=commitdiff_plain;h=74b5d88f9cb0ff532f5db89e402c4a991caf8678 Add tests for atom.el --- diff --git a/atom-tests.el b/atom-tests.el new file mode 100644 index 0000000..3c5330c --- /dev/null +++ b/atom-tests.el @@ -0,0 +1,119 @@ +;;; 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