(fill-region): Leave point and mark where they were before filling
[emacs.git] / test / automated / newsticker-tests.el
blob5b60535e4638490fcc91092f2db1234b0754e245
1 ;;; newsticker-testsuite.el --- Test suite for newsticker.
3 ;; Copyright (C) 2003-2012 Free Software Foundation, Inc.
5 ;; Author: Ulf Jasper <ulf.jasper@web.de>
6 ;; Keywords: News, RSS, Atom
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23 ;;; Commentary:
25 ;;; Code:
27 (require 'ert)
28 (require 'newsticker)
30 ;; ======================================================================
31 ;; Tests for newsticker-backend
32 ;; ======================================================================
33 (ert-deftest newsticker--guid ()
34 "Test for `newsticker--guid-*'.
35 Signals an error if something goes wrong."
36 (should (string= "blah" (newsticker--guid-to-string "blah")))
37 (should (string= "myguid" (newsticker--guid '("title1" "description1" "link1"
38 nil 'new 42 nil nil
39 ((guid () "myguid")))))))
41 (ert-deftest newsticker--cache-contains ()
42 "Test for `newsticker--cache-contains'."
43 (let ((newsticker--cache '((feed1
44 ("title1" "description1" "link1" nil 'new 42
45 nil nil ((guid () "myguid")))))))
46 (newsticker--guid-to-string
47 (assoc 'guid (newsticker--extra '("title1" "description1"
48 "link1" nil 'new 42 nil nil
49 ((guid "myguid"))))))
50 (should (newsticker--cache-contains newsticker--cache 'feed1 "WRONGTITLE"
51 "description1" "link1" 'new "myguid"))
52 (should (not (newsticker--cache-contains newsticker--cache 'feed1 "title1"
53 "description1" "link1" 'new
54 "WRONG GUID")))
55 (should (newsticker--cache-contains newsticker--cache 'feed1 "title1"
56 "description1" "link1" 'new "myguid")))
57 (let ((newsticker--cache '((feed1
58 ("title1" "description1" "link1" nil 'new 42
59 nil nil ((guid () "myguid1")))
60 ("title1" "description1" "link1" nil 'new 42
61 nil nil ((guid () "myguid2")))))))
62 (should (not (newsticker--cache-contains newsticker--cache 'feed1 "title1"
63 "description1" "link1" 'new
64 "myguid")))
65 (should (string= "myguid1"
66 (newsticker--guid (newsticker--cache-contains
67 newsticker--cache 'feed1 "title1"
68 "description1" "link1" 'new
69 "myguid1"))))
70 (should (string= "myguid2"
71 (newsticker--guid (newsticker--cache-contains
72 newsticker--cache 'feed1 "title1"
73 "description1" "link1" 'new
74 "myguid2"))))))
76 (defun newsticker-tests--decode-iso8601-date (input expected)
77 "Actually test `newsticker--decode-iso8601-date'.
78 Apply to INPUT and compare with EXPECTED."
79 (let ((result (format-time-string "%Y-%m-%dT%H:%M:%S"
80 (newsticker--decode-iso8601-date input)
81 t)))
82 (should (string= result expected))))
84 (ert-deftest newsticker--decode-iso8601-date ()
85 "Test `newsticker--decode-iso8601-date'."
86 (newsticker-tests--decode-iso8601-date "2004"
87 "2004-01-01T00:00:00")
88 (newsticker-tests--decode-iso8601-date "2004-09"
89 "2004-09-01T00:00:00")
90 (newsticker-tests--decode-iso8601-date "2004-09-17"
91 "2004-09-17T00:00:00")
92 (newsticker-tests--decode-iso8601-date "2004-09-17T05:09"
93 "2004-09-17T05:09:00")
94 (newsticker-tests--decode-iso8601-date "2004-09-17T05:09:49"
95 "2004-09-17T05:09:49")
96 (newsticker-tests--decode-iso8601-date "2004-09-17T05:09:49.123"
97 "2004-09-17T05:09:49")
98 (newsticker-tests--decode-iso8601-date "2004-09-17T05:09+01:00"
99 "2004-09-17T04:09:00")
100 (newsticker-tests--decode-iso8601-date "2004-09-17T05:09-02:00"
101 "2004-09-17T07:09:00"))
103 (defun newsticker--do-test--decode-rfc822-date (input expected)
104 "Actually test `newsticker--decode-rfc822-date'.
105 Apply to INPUT and compare with EXPECTED."
106 (let ((result (format-time-string "%Y-%m-%dT%H:%M:%S"
107 (newsticker--decode-rfc822-date input)
108 t)))
109 (should (string= result expected))))
111 (ert-deftest newsticker--decode-rfc822-date ()
112 "Test `newsticker--decode-rfc822-date'."
113 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52 +0100"
114 "2008-03-10T18:27:52")
115 ;;(format-time-string "%d.%m.%y, %H:%M %T%z"
116 ;;(newsticker--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52 +0200"))
118 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27:52"
119 "2008-03-10T19:27:52")
120 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008 19:27"
121 "2008-03-10T19:27:00")
122 (newsticker--do-test--decode-rfc822-date "10 Mar 2008 19:27"
123 "2008-03-10T19:27:00")
124 (newsticker--do-test--decode-rfc822-date "Mon, 10 Mar 2008"
125 "2008-03-10T00:00:00")
126 (newsticker--do-test--decode-rfc822-date "10 Mar 2008"
127 "2008-03-10T00:00:00")
128 (newsticker--do-test--decode-rfc822-date "Sat, 01 Dec 2007 00:05:00 +0100"
129 "2007-11-30T23:05:00")
130 (newsticker--do-test--decode-rfc822-date "Sun, 30 Dec 2007 18:58:13 +0100"
131 "2007-12-30T17:58:13"))
133 ;; ======================================================================
134 ;; Tests for newsticker-treeview
135 ;; ======================================================================
136 (ert-deftest newsticker--group-manage-orphan-feeds ()
137 "Test `newsticker--group-manage-orphan-feeds'.
138 Signals an error if something goes wrong."
139 (let ((newsticker-groups '("Feeds"))
140 (newsticker-url-list-defaults nil)
141 (newsticker-url-list '(("feed1") ("feed2") ("feed3"))))
142 (newsticker--group-manage-orphan-feeds)
143 (should (equal '("Feeds" "feed3" "feed2" "feed1")
144 newsticker-groups))))
146 (provide 'newsticker-tests)
148 ;;; newsticker-tests.el ends here