aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorEric Abrahamsen2018-04-26 16:26:27 -0700
committerEric Abrahamsen2019-03-22 10:23:30 -0700
commitc1b63af4458e92bad33da0def2b15c206656e2fa (patch)
tree267503989ec0475b76800bb309f6cdc1da53e74e /test
parent3375d08299bbc1e224d19a871012cdbbf5d787ee (diff)
downloademacs-c1b63af4458e92bad33da0def2b15c206656e2fa.tar.gz
emacs-c1b63af4458e92bad33da0def2b15c206656e2fa.zip
Change Gnus hash tables into real hash tables
Gnus has used obarrays as makeshift hash tables for groups: group names are coerced to unibyte and interned in custom obarrays, and their symbol-value set to whatever value needs to be stored. This patch replaces those obarrays with actual hash tables. * lisp/gnus/gnus-util.el (gnus-intern-safe, gnus-create-hash-size): Remove functions. (gnus-make-hashtable): Change to return a real hash table. (gnus-text-property-search): Utility similar to `text-property-any', but compares on `equal'. Needed because the 'gnus-group text property is now a string. * lisp/gnus/gnus.el (gnus-gethash, gnus-gethash-safe, gnus-sethash): Remove macros. (gnus-group-list): New variable holding all group names as an ordered list. Used because `gnus-newsrc-hashtb' used to preserve `gnus-newsrc-alist' ordering, but now doesn't. * lisp/gnus/nnmaildir.el (nnmaildir--servers): Change from obarray to alist. (nnmaildir--up2-1): Remove function. * lisp/thingatpt.el (thing-at-point-newsgroup-p): This was making use of Gnus obarrays, replace with a cond that can handle many different possibilities. * lisp/gnus/gnus-bcklg.el (gnus-backlog-articles): Remove gnus-backlog-hashtb, which wasn't doing anything. Just keep a list of ident strings in gnus-backlog-articles. (gnus-backlog-setup): Delete unnecessary function. (gnus-backlog-enter-article, gnus-backlog-remove-oldest-article, gnus-backlog-remove-article, gnus-backlog-request-article): Alter calls accordingly. * lisp/gnus/gnus-dup.el (gnus-duplicate-list-max-length): Rename from `gnus-duplicate-list-length', for accuracy. * lisp/gnus/gnus-start.el (gnus-active-to-gnus-format, gnus-groups-to-gnus-format, gnus-newsrc-to-gnus-format): Read group names as strings. (gnus-gnus-to-quick-newsrc-format): Write `gnus-newsrc-alist' using the ordering in `gnus-group-list'. * lisp/gnus/gnus-agent.el: * lisp/gnus/gnus-async.el: * lisp/gnus/gnus-cache.el: * lisp/gnus/gnus-group.el: * lisp/gnus/gnus-score.el: * lisp/gnus/gnus-sum.el: * lisp/gnus/gnus-topic.el: * lisp/gnus/message.el: * lisp/gnus/mml.el: * lisp/gnus/nnagent.el: * lisp/gnus/nnbabyl.el: * lisp/gnus/nnvirtual.el: * lisp/gnus/nnweb.el: In all files, change obarrays to hash-tables, and swap `gnus-sethash' for `puthash', `gnus-gethash' for `gethash', `mapatoms' for `maphash', etc. * test/lisp/gnus/gnus-test-headers.el (gnus-headers-make-dependency-table, gnus-headers-loop-dependencies): New tests to make sure we're building `gnus-newsgroup-dependencies' correctly.
Diffstat (limited to 'test')
-rw-r--r--test/lisp/gnus/gnus-test-headers.el176
1 files changed, 176 insertions, 0 deletions
diff --git a/test/lisp/gnus/gnus-test-headers.el b/test/lisp/gnus/gnus-test-headers.el
new file mode 100644
index 00000000000..805a3003331
--- /dev/null
+++ b/test/lisp/gnus/gnus-test-headers.el
@@ -0,0 +1,176 @@
1;;; gnus-test-headers.el --- Tests for Gnus header-related functions -*- lexical-binding: t; -*-
2
3;; Copyright (C) 2018 Free Software Foundation, Inc.
4
5;; Author: Eric Abrahamsen <eric@ericabrahamsen.net>
6
7;; This program is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
11
12;; This program is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with this program. If not, see <https://www.gnu.org/licenses/>.
19
20;;; Commentary:
21
22;; The tests her are for
23
24;;; Code:
25
26(require 'ert)
27(require 'gnus-sum)
28
29(defconst gnus-headers-test-data
30 '([2 "Re: [Emacs-devel] Emacs move" "Dave Love <d.love@dl.ac.uk>"
31 "Thu, 14 Sep 2000 11:10:46 +0100"
32 "<200009141010.LAA26351@djlvig.dl.ac.uk>"
33 "<20000913175943.A26093@sparky.nisa.net>"
34 1882 16 "nnmaildir mails:2"
35 ((To . "Jeff Bailey <jbailey@nisa.net>")
36 (Cc . "emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
37 [3 "Re: [Emacs-devel] Emacs move" "Sam Steingold <sds@gnu.org>"
38 "14 Sep 2000 10:21:56 -0400" "<upum7xddn.fsf@xchange.com>"
39 "<20000913175943.A26093@sparky.nisa.net>"
40 2991 50 "nnmaildir mails:3"
41 ((To . "Jeff Bailey <jbailey@nisa.net>")
42 (Cc . "emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
43 [4 "Re: [Emacs-devel] Emacs move" "Jeff Bailey <jbailey@nisa.net>"
44 "Thu, 14 Sep 2000 09:14:47 -0700"
45 "<20000914091447.G4827@sparky.nisa.net>"
46 "<20000913175943.A26093@sparky.nisa.net> <upum7xddn.fsf@xchange.com>"
47 1780 15 "nnmaildir mails:4"
48 ((To . "sds@gnu.org, Jeff Bailey <jbailey@nisa.net>")
49 (Cc . "emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
50 [5 "Re: [Emacs-devel] Emacs move" "Dave Love <d.love@dl.ac.uk>"
51 "Thu, 14 Sep 2000 18:24:36 +0100"
52 "<200009141724.SAA26807@djlvig.dl.ac.uk>"
53 "<20000913175943.A26093@sparky.nisa.net>"
54 1343 9 "nnmaildir mails:5"
55 ((To . "Jeff Bailey <jbailey@nisa.net>")
56 (Cc . "emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
57 [6 "Re: [Emacs-devel] Emacs move" "Karl Fogel <kfogel@galois.collab.net>"
58 "14 Sep 2000 10:37:35 -0500" "<87em2nyog0.fsf@galois.collab.net>"
59 "<20000913175943.A26093@sparky.nisa.net> <200009141724.SAA26807@djlvig.dl.ac.uk>"
60 3740 124 "nnmaildir mails:6"
61 ((To . "Dave Love <d.love@dl.ac.uk>")
62 (Cc . "Jeff Bailey <jbailey@nisa.net>, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
63 [7 "Re: [Emacs-devel] Emacs move" "Jeff Bailey <jbailey@nisa.net>"
64 "Thu, 14 Sep 2000 10:55:12 -0700"
65 "<20000914105512.A29291@sparky.nisa.net>"
66 "<20000913175943.A26093@sparky.nisa.net> <200009141724.SAA26807@djlvig.dl.ac.uk> <87em2nyog0.fsf@galois.collab.net>"
67 1687 16 "nnmaildir mails:7"
68 ((To . "kfogel@red-bean.com, Dave Love <d.love@dl.ac.uk>")
69 (Cc . "Jeff Bailey <jbailey@nisa.net>, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
70 [8 "Re: [Emacs-devel] Emacs move" "John Wiegley <johnw@gnu.org>"
71 "Thu, 14 Sep 2000 12:19:01 -0700"
72 "<200009141919.MAA05085@localhost.localdomain>"
73 "<20000913175943.A26093@sparky.nisa.net>"
74 1978 27 "nnmaildir mails:8"
75 ((To . "emacs-devel@gnu.org"))]
76 [9 "Re: [Emacs-devel] Emacs move"
77 "\"Robert J. Chassell\" <bob@rattlesnake.com>"
78 "Thu, 14 Sep 2000 07:33:15 -0400 (EDT)"
79 "<m13ZXGV-000BCgC@megalith.rattlesnake.com>"
80 "<20000913175943.A26093@sparky.nisa.net>"
81 3046 72 "nnmaildir mails:9"
82 ((To . "jbailey@nisa.net")
83 (Cc . "emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
84 [10 "Re: [Emacs-devel] Emacs move"
85 "wmperry@aventail.com (William M. Perry)"
86 "14 Sep 2000 09:10:25 -0500"
87 "<86g0n3f4j2.fsf@megalith.bp.aventail.com>"
88 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com>"
89 3104 44 "nnmaildir mails:10"
90 ((To . "bob@rattlesnake.com")
91 (Cc . "jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
92 [11 "Re: [Emacs-devel] Emacs move" "Gerd Moellmann <gerd@gnu.org>"
93 "Thu, 14 Sep 2000 21:51:05 +0200 (CEST)"
94 "<200009141951.VAA06005@gerd.segv.de>"
95 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com> <86g0n3f4j2.fsf@megalith.bp.aventail.com>"
96 1884 6 "nnmaildir mails:11"
97 ((To . "wmvperry@aventail.com")
98 (Cc . "bob@rattlesnake.com, jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
99 [12 "Re: [Emacs-devel] Emacs move" "Gerd Moellmann <gerd@gnu.org>"
100 "Thu, 14 Sep 2000 21:49:03 +0200 (CEST)"
101 "<200009141949.VAA05998@gerd.segv.de>"
102 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com>"
103 2408 24 "nnmaildir mails:12"
104 ((To . "bob@rattlesnake.com")
105 (Cc . "jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
106 [13 "Re: [Emacs-devel] Emacs move"
107 "\"Robert J. Chassell\" <bob@rattlesnake.com>"
108 "Thu, 14 Sep 2000 17:50:01 -0400 (EDT)"
109 "<m13ZgtN-000BD3C@megalith.rattlesnake.com>"
110 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com> <200009141949.VAA05998@gerd.segv.de>"
111 1968 23 "nnmaildir mails:13"
112 ((To . "gerd@gnu.org")
113 (Cc . "bob@rattlesnake.com, jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
114 [14 "Re: [Emacs-devel] Emacs move" "Richard Stallman <rms@gnu.org>"
115 "Fri, 15 Sep 2000 16:28:12 -0600 (MDT)"
116 "<200009152228.QAA20526@wijiji.santafe.edu>"
117 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com>"
118 1288 2 "nnmaildir mails:14"
119 ((To . "jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))]
120 [15 "[Emacs-devel] Emacs move" "Jeff Bailey <jbailey@nisa.net>"
121 "Wed, 13 Sep 2000 17:59:43 -0700"
122 "<20000913175943.A26093@sparky.nisa.net>" ""
123 1661 26 "nnmaildir mails:15"
124 ((To . "emacs-devel@gnu.org")
125 (Cc . "cvs-hackers@gnu.org"))]
126 [16 "Re: [Emacs-devel] Emacs move" "Jeff Bailey <jbailey@nisa.net>"
127 "Fri, 15 Sep 2000 22:00:12 -0700"
128 "<20000915220012.A3923@sparky.nisa.net>"
129 "<20000913175943.A26093@sparky.nisa.net> <m13ZXGV-000BCgC@megalith.rattlesnake.com> <200009141949.VAA05998@gerd.segv.de> <m13ZgtN-000BD3C@megalith.rattlesnake.com>"
130 2857 51 "nnmaildir mails:16"
131 ((To . "bob@rattlesnake.com, gerd@gnu.org")
132 (Cc . "jbailey@nisa.net, emacs-devel@gnu.org, cvs-hackers@gnu.org"))])
133 "A pile of headers with potential interdependencies.")
134
135(ert-deftest gnus-headers-make-dependency-table ()
136 (let ((table (gnus-make-hashtable 20))
137 (data (copy-sequence gnus-headers-test-data))
138 ret)
139 (dolist (h data)
140 ;; `gnus-dependencies-add-header' returns nil if it fails to add
141 ;; the header.
142 (should (gnus-dependencies-add-header h table nil)))
143 ;; Pick a value to test.
144 (setq ret (gethash "<m13ZXGV-000BCgC@megalith.rattlesnake.com>"
145 table))
146 ;; The message has three children.
147 (should (= 3 (length (cdr ret))))
148 ;; The first of those children has one child.
149 (should (= 1 (length (cdr (nth 1 ret)))))))
150
151(ert-deftest gnus-headers-loop-dependencies ()
152 "Intentionally create a reference loop."
153 (let ((table (gnus-make-hashtable 20))
154 (data (copy-sequence gnus-headers-test-data))
155 (parent-id "<200009141724.SAA26807@djlvig.dl.ac.uk>")
156 (child-id "<87em2nyog0.fsf@galois.collab.net>")
157 parent)
158 (dolist (h data)
159 (gnus-dependencies-add-header h table nil))
160
161 (setq parent (gethash parent-id table))
162
163 ;; Put the parent header in the child references of one of its own
164 ;; children. `gnus-thread-loop-p' only checks if there's a loop
165 ;; between parent and immediate child, not parent and random
166 ;; descendant. At least, near as I can tell that's the case.
167
168 (push (list (car parent)) (cdr (gethash child-id table)))
169
170 (let ((gnus-newsgroup-dependencies table))
171 (should
172 (= 1 ; 1 indicates an infloop.
173 (gnus-thread-loop-p (car parent) (cadr parent)))))))
174
175(provide 'gnus-test-headers)
176;;; gnus-test-headers.el ends here