Fix typos in tests for lax-plist-get etc.
[emacs.git] / test / src / fns-tests.el
bloba1b48a643e1e2aa513a0ad660e36a3ae585b2a8d
1 ;;; fns-tests.el --- tests for src/fns.c
3 ;; Copyright (C) 2014-2017 Free Software Foundation, Inc.
5 ;; This file is part of GNU Emacs.
7 ;; This program is free software: you can redistribute it and/or
8 ;; modify it under the terms of the GNU General Public License as
9 ;; published by the Free Software Foundation, either version 3 of the
10 ;; License, or (at your option) any later version.
12 ;; This program is distributed in the hope that it will be useful, but
13 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 ;; General Public License for more details.
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see `http://www.gnu.org/licenses/'.
20 ;;; Commentary:
22 ;;; Code:
24 (require 'cl-lib)
25 (eval-when-compile (require 'cl))
27 (ert-deftest fns-tests-reverse ()
28 (should-error (reverse))
29 (should-error (reverse 1))
30 (should-error (reverse (make-char-table 'foo)))
31 (should (equal [] (reverse [])))
32 (should (equal [0] (reverse [0])))
33 (should (equal [1 2 3 4] (reverse (reverse [1 2 3 4]))))
34 (should (equal '(a b c d) (reverse (reverse '(a b c d)))))
35 (should (equal "xyzzy" (reverse (reverse "xyzzy"))))
36 (should (equal "こんにちは / コンニチハ" (reverse (reverse "こんにちは / コンニチハ")))))
38 (ert-deftest fns-tests-nreverse ()
39 (should-error (nreverse))
40 (should-error (nreverse 1))
41 (should-error (nreverse (make-char-table 'foo)))
42 (should (equal (nreverse "xyzzy") "yzzyx"))
43 (let ((A []))
44 (nreverse A)
45 (should (equal A [])))
46 (let ((A [0]))
47 (nreverse A)
48 (should (equal A [0])))
49 (let ((A [1 2 3 4]))
50 (nreverse A)
51 (should (equal A [4 3 2 1])))
52 (let ((A [1 2 3 4]))
53 (nreverse A)
54 (nreverse A)
55 (should (equal A [1 2 3 4])))
56 (let* ((A [1 2 3 4])
57 (B (nreverse (nreverse A))))
58 (should (equal A B))))
60 (ert-deftest fns-tests-reverse-bool-vector ()
61 (let ((A (make-bool-vector 10 nil)))
62 (dotimes (i 5) (aset A i t))
63 (should (equal [nil nil nil nil nil t t t t t] (vconcat (reverse A))))
64 (should (equal A (reverse (reverse A))))))
66 (ert-deftest fns-tests-nreverse-bool-vector ()
67 (let ((A (make-bool-vector 10 nil)))
68 (dotimes (i 5) (aset A i t))
69 (nreverse A)
70 (should (equal [nil nil nil nil nil t t t t t] (vconcat A)))
71 (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))
73 (ert-deftest fns-tests-compare-strings ()
74 (should-error (compare-strings))
75 (should-error (compare-strings "xyzzy" "xyzzy"))
76 (should (= (compare-strings "xyzzy" 0 10 "zyxxy" 0 5) -1))
77 (should-error (compare-strings "xyzzy" 0 5 "zyxxy" -1 2))
78 (should-error (compare-strings "xyzzy" 'foo nil "zyxxy" 0 1))
79 (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3))
80 (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3))
81 (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo))
82 (should (eq (compare-strings "" nil nil "" nil nil) t))
83 (should (eq (compare-strings "" 0 0 "" 0 0) t))
84 (should (eq (compare-strings "test" nil nil "test" nil nil) t))
85 (should (eq (compare-strings "test" nil nil "test" nil nil t) t))
86 (should (eq (compare-strings "test" nil nil "test" nil nil nil) t))
87 (should (eq (compare-strings "Test" nil nil "test" nil nil t) t))
88 (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
89 (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
90 (should (= (compare-strings "test" nil nil "Test" nil nil) 1))
91 (should (= (compare-strings "foobaz" nil nil "barbaz" nil nil) 1))
92 (should (= (compare-strings "barbaz" nil nil "foobar" nil nil) -1))
93 (should (= (compare-strings "foobaz" nil nil "farbaz" nil nil) 2))
94 (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2))
95 (should (eq (compare-strings "abcxyz" 0 2 "abcprq" 0 2) t))
96 (should (eq (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3) t))
97 (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4))
98 (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4))
99 (should (eq (compare-strings "xyzzy" -3 4 "azza" -3 3) t))
100 (should (eq (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil) t))
101 (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1))
102 (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1)))
104 (defun fns-tests--collate-enabled-p ()
105 "Check whether collation functions are enabled."
106 (and
107 ;; When there is no collation library, collation functions fall back
108 ;; to their lexicographic counterparts. We don't need to test then.
109 (not (ignore-errors (string-collate-equalp "" "" t)))
110 ;; We use a locale, which might not be installed. Check it.
111 (ignore-errors
112 (string-collate-equalp
113 "" "" (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
115 (ert-deftest fns-tests-collate-strings ()
116 (skip-unless (fns-tests--collate-enabled-p))
118 (should (string-collate-equalp "xyzzy" "xyzzy"))
119 (should-not (string-collate-equalp "xyzzy" "XYZZY"))
121 ;; In POSIX or C locales, collation order is lexicographic.
122 (should (string-collate-lessp "XYZZY" "xyzzy" "POSIX"))
123 ;; In a language specific locale, collation order is different.
124 (should (string-collate-lessp
125 "xyzzy" "XYZZY"
126 (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))
128 ;; Ignore case.
129 (should (string-collate-equalp "xyzzy" "XYZZY" nil t))
131 ;; Locale must be valid.
132 (should-error (string-collate-equalp "xyzzy" "xyzzy" "en_DE.UTF-8")))
134 ;; There must be a check for valid codepoints. (Check not implemented yet)
135 ; (should-error
136 ; (string-collate-equalp (string ?\x00110000) (string ?\x00110000)))
137 ;; Invalid UTF-8 sequences shall be indicated. How to create such strings?
139 (ert-deftest fns-tests-sort ()
140 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (< x y)))
141 '(-1 2 3 4 5 5 7 8 9)))
142 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y)))
143 '(9 8 7 5 5 4 3 2 -1)))
144 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (< x y)))
145 [-1 2 3 4 5 5 7 8 9]))
146 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (> x y)))
147 [9 8 7 5 5 4 3 2 -1]))
148 (should (equal
149 (sort
150 (vector
151 '(8 . "xxx") '(9 . "aaa") '(8 . "bbb") '(9 . "zzz")
152 '(9 . "ppp") '(8 . "ttt") '(8 . "eee") '(9 . "fff"))
153 (lambda (x y) (< (car x) (car y))))
154 [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee")
155 (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")])))
157 (ert-deftest fns-tests-collate-sort ()
158 ;; See https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02505.html.
159 :expected-result (if (eq system-type 'cygwin) :failed :passed)
160 (skip-unless (fns-tests--collate-enabled-p))
162 ;; Punctuation and whitespace characters are relevant for POSIX.
163 (should
164 (equal
165 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
166 (lambda (a b) (string-collate-lessp a b "POSIX")))
167 '("1 1" "1 2" "1.1" "1.2" "11" "12")))
168 ;; Punctuation and whitespace characters are not taken into account
169 ;; for collation in other locales.
170 (should
171 (equal
172 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
173 (lambda (a b)
174 (let ((w32-collate-ignore-punctuation t))
175 (string-collate-lessp
176 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
177 '("11" "1 1" "1.1" "12" "1 2" "1.2")))
179 ;; Diacritics are different letters for POSIX, they sort lexicographical.
180 (should
181 (equal
182 (sort '("Ævar" "Agustín" "Adrian" "Eli")
183 (lambda (a b) (string-collate-lessp a b "POSIX")))
184 '("Adrian" "Agustín" "Eli" "Ævar")))
185 ;; Diacritics are sorted between similar letters for other locales.
186 (should
187 (equal
188 (sort '("Ævar" "Agustín" "Adrian" "Eli")
189 (lambda (a b)
190 (let ((w32-collate-ignore-punctuation t))
191 (string-collate-lessp
192 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
193 '("Adrian" "Ævar" "Agustín" "Eli"))))
195 (ert-deftest fns-tests-string-version-lessp ()
196 (should (string-version-lessp "foo2.png" "foo12.png"))
197 (should (not (string-version-lessp "foo12.png" "foo2.png")))
198 (should (string-version-lessp "foo12.png" "foo20000.png"))
199 (should (not (string-version-lessp "foo20000.png" "foo12.png")))
200 (should (string-version-lessp "foo.png" "foo2.png"))
201 (should (not (string-version-lessp "foo2.png" "foo.png")))
202 (should (equal (sort '("foo12.png" "foo2.png" "foo1.png")
203 'string-version-lessp)
204 '("foo1.png" "foo2.png" "foo12.png")))
205 (should (string-version-lessp "foo2" "foo1234"))
206 (should (not (string-version-lessp "foo1234" "foo2")))
207 (should (string-version-lessp "foo.png" "foo2"))
208 (should (string-version-lessp "foo1.25.5.png" "foo1.125.5"))
209 (should (string-version-lessp "2" "1245"))
210 (should (not (string-version-lessp "1245" "2"))))
212 (ert-deftest fns-tests-func-arity ()
213 (should (equal (func-arity 'car) '(1 . 1)))
214 (should (equal (func-arity 'caar) '(1 . 1)))
215 (should (equal (func-arity 'format) '(1 . many)))
216 (require 'info)
217 (should (equal (func-arity 'Info-goto-node) '(1 . 3)))
218 (should (equal (func-arity (lambda (&rest x))) '(0 . many)))
219 (should (equal (func-arity (eval (lambda (x &optional y)) nil)) '(1 . 2)))
220 (should (equal (func-arity (eval (lambda (x &optional y)) t)) '(1 . 2)))
221 (should (equal (func-arity 'let) '(1 . unevalled))))
223 (ert-deftest fns-tests-hash-buffer ()
224 (should (equal (sha1 "foo") "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"))
225 (should (equal (with-temp-buffer
226 (insert "foo")
227 (buffer-hash))
228 (sha1 "foo")))
229 ;; This tests whether the presence of a gap in the middle of the
230 ;; buffer is handled correctly.
231 (should (equal (with-temp-buffer
232 (insert "foo")
233 (goto-char 2)
234 (insert " ")
235 (backward-delete-char 1)
236 (buffer-hash))
237 (sha1 "foo"))))
239 (ert-deftest fns-tests-mapcan ()
240 (should-error (mapcan))
241 (should-error (mapcan #'identity))
242 (should-error (mapcan #'identity (make-char-table 'foo)))
243 (should (equal (mapcan #'list '(1 2 3)) '(1 2 3)))
244 ;; `mapcan' is destructive
245 (let ((data '((foo) (bar))))
246 (should (equal (mapcan #'identity data) '(foo bar)))
247 (should (equal data '((foo bar) (bar))))))
249 ;; Test handling of cyclic and dotted lists.
251 (defun cyc1 (a)
252 (let ((ls (make-list 10 a)))
253 (nconc ls ls)
254 ls))
256 (defun cyc2 (a b)
257 (let ((ls1 (make-list 10 a))
258 (ls2 (make-list 1000 b)))
259 (nconc ls2 ls2)
260 (nconc ls1 ls2)
261 ls1))
263 (defun dot1 (a)
264 (let ((ls (make-list 10 a)))
265 (nconc ls 'tail)
266 ls))
268 (defun dot2 (a b)
269 (let ((ls1 (make-list 10 a))
270 (ls2 (make-list 10 b)))
271 (nconc ls1 ls2)
272 (nconc ls2 'tail)
273 ls1))
275 (ert-deftest test-cycle-length ()
276 (should-error (length (cyc1 1)) :type 'circular-list)
277 (should-error (length (cyc2 1 2)) :type 'circular-list)
278 (should-error (length (dot1 1)) :type 'wrong-type-argument)
279 (should-error (length (dot2 1 2)) :type 'wrong-type-argument))
281 (ert-deftest test-cycle-safe-length ()
282 (should (<= 10 (safe-length (cyc1 1))))
283 (should (<= 1010 (safe-length (cyc2 1 2))))
284 (should (= 10 (safe-length (dot1 1))))
285 (should (= 20 (safe-length (dot2 1 2)))))
287 (ert-deftest test-cycle-member ()
288 (let ((c1 (cyc1 1))
289 (c2 (cyc2 1 2))
290 (d1 (dot1 1))
291 (d2 (dot2 1 2)))
292 (should (member 1 c1))
293 (should (member 1 c2))
294 (should (member 1 d1))
295 (should (member 1 d2))
296 (should-error (member 2 c1) :type 'circular-list)
297 (should (member 2 c2))
298 (should-error (member 2 d1) :type 'wrong-type-argument)
299 (should (member 2 d2))
300 (should-error (member 3 c1) :type 'circular-list)
301 (should-error (member 3 c2) :type 'circular-list)
302 (should-error (member 3 d1) :type 'wrong-type-argument)
303 (should-error (member 3 d2) :type 'wrong-type-argument)))
305 (ert-deftest test-cycle-memq ()
306 (let ((c1 (cyc1 1))
307 (c2 (cyc2 1 2))
308 (d1 (dot1 1))
309 (d2 (dot2 1 2)))
310 (should (memq 1 c1))
311 (should (memq 1 c2))
312 (should (memq 1 d1))
313 (should (memq 1 d2))
314 (should-error (memq 2 c1) :type 'circular-list)
315 (should (memq 2 c2))
316 (should-error (memq 2 d1) :type 'wrong-type-argument)
317 (should (memq 2 d2))
318 (should-error (memq 3 c1) :type 'circular-list)
319 (should-error (memq 3 c2) :type 'circular-list)
320 (should-error (memq 3 d1) :type 'wrong-type-argument)
321 (should-error (memq 3 d2) :type 'wrong-type-argument)))
323 (ert-deftest test-cycle-memql ()
324 (let ((c1 (cyc1 1))
325 (c2 (cyc2 1 2))
326 (d1 (dot1 1))
327 (d2 (dot2 1 2)))
328 (should (memql 1 c1))
329 (should (memql 1 c2))
330 (should (memql 1 d1))
331 (should (memql 1 d2))
332 (should-error (memql 2 c1) :type 'circular-list)
333 (should (memql 2 c2))
334 (should-error (memql 2 d1) :type 'wrong-type-argument)
335 (should (memql 2 d2))
336 (should-error (memql 3 c1) :type 'circular-list)
337 (should-error (memql 3 c2) :type 'circular-list)
338 (should-error (memql 3 d1) :type 'wrong-type-argument)
339 (should-error (memql 3 d2) :type 'wrong-type-argument)))
341 (ert-deftest test-cycle-assq ()
342 (let ((c1 (cyc1 '(1)))
343 (c2 (cyc2 '(1) '(2)))
344 (d1 (dot1 '(1)))
345 (d2 (dot2 '(1) '(2))))
346 (should (assq 1 c1))
347 (should (assq 1 c2))
348 (should (assq 1 d1))
349 (should (assq 1 d2))
350 (should-error (assq 2 c1) :type 'circular-list)
351 (should (assq 2 c2))
352 (should-error (assq 2 d1) :type 'wrong-type-argument)
353 (should (assq 2 d2))
354 (should-error (assq 3 c1) :type 'circular-list)
355 (should-error (assq 3 c2) :type 'circular-list)
356 (should-error (assq 3 d1) :type 'wrong-type-argument)
357 (should-error (assq 3 d2) :type 'wrong-type-argument)))
359 (ert-deftest test-cycle-assoc ()
360 (let ((c1 (cyc1 '(1)))
361 (c2 (cyc2 '(1) '(2)))
362 (d1 (dot1 '(1)))
363 (d2 (dot2 '(1) '(2))))
364 (should (assoc 1 c1))
365 (should (assoc 1 c2))
366 (should (assoc 1 d1))
367 (should (assoc 1 d2))
368 (should-error (assoc 2 c1) :type 'circular-list)
369 (should (assoc 2 c2))
370 (should-error (assoc 2 d1) :type 'wrong-type-argument)
371 (should (assoc 2 d2))
372 (should-error (assoc 3 c1) :type 'circular-list)
373 (should-error (assoc 3 c2) :type 'circular-list)
374 (should-error (assoc 3 d1) :type 'wrong-type-argument)
375 (should-error (assoc 3 d2) :type 'wrong-type-argument)))
377 (ert-deftest test-cycle-rassq ()
378 (let ((c1 (cyc1 '(0 . 1)))
379 (c2 (cyc2 '(0 . 1) '(0 . 2)))
380 (d1 (dot1 '(0 . 1)))
381 (d2 (dot2 '(0 . 1) '(0 . 2))))
382 (should (rassq 1 c1))
383 (should (rassq 1 c2))
384 (should (rassq 1 d1))
385 (should (rassq 1 d2))
386 (should-error (rassq 2 c1) :type 'circular-list)
387 (should (rassq 2 c2))
388 (should-error (rassq 2 d1) :type 'wrong-type-argument)
389 (should (rassq 2 d2))
390 (should-error (rassq 3 c1) :type 'circular-list)
391 (should-error (rassq 3 c2) :type 'circular-list)
392 (should-error (rassq 3 d1) :type 'wrong-type-argument)
393 (should-error (rassq 3 d2) :type 'wrong-type-argument)))
395 (ert-deftest test-cycle-rassoc ()
396 (let ((c1 (cyc1 '(0 . 1)))
397 (c2 (cyc2 '(0 . 1) '(0 . 2)))
398 (d1 (dot1 '(0 . 1)))
399 (d2 (dot2 '(0 . 1) '(0 . 2))))
400 (should (rassoc 1 c1))
401 (should (rassoc 1 c2))
402 (should (rassoc 1 d1))
403 (should (rassoc 1 d2))
404 (should-error (rassoc 2 c1) :type 'circular-list)
405 (should (rassoc 2 c2))
406 (should-error (rassoc 2 d1) :type 'wrong-type-argument)
407 (should (rassoc 2 d2))
408 (should-error (rassoc 3 c1) :type 'circular-list)
409 (should-error (rassoc 3 c2) :type 'circular-list)
410 (should-error (rassoc 3 d1) :type 'wrong-type-argument)
411 (should-error (rassoc 3 d2) :type 'wrong-type-argument)))
413 (ert-deftest test-cycle-delq ()
414 (should-error (delq 1 (cyc1 1)) :type 'circular-list)
415 (should-error (delq 1 (cyc2 1 2)) :type 'circular-list)
416 (should-error (delq 1 (dot1 1)) :type 'wrong-type-argument)
417 (should-error (delq 1 (dot2 1 2)) :type 'wrong-type-argument)
418 (should-error (delq 2 (cyc1 1)) :type 'circular-list)
419 (should-error (delq 2 (cyc2 1 2)) :type 'circular-list)
420 (should-error (delq 2 (dot1 1)) :type 'wrong-type-argument)
421 (should-error (delq 2 (dot2 1 2)) :type 'wrong-type-argument)
422 (should-error (delq 3 (cyc1 1)) :type 'circular-list)
423 (should-error (delq 3 (cyc2 1 2)) :type 'circular-list)
424 (should-error (delq 3 (dot1 1)) :type 'wrong-type-argument)
425 (should-error (delq 3 (dot2 1 2)) :type 'wrong-type-argument))
427 (ert-deftest test-cycle-delete ()
428 (should-error (delete 1 (cyc1 1)) :type 'circular-list)
429 (should-error (delete 1 (cyc2 1 2)) :type 'circular-list)
430 (should-error (delete 1 (dot1 1)) :type 'wrong-type-argument)
431 (should-error (delete 1 (dot2 1 2)) :type 'wrong-type-argument)
432 (should-error (delete 2 (cyc1 1)) :type 'circular-list)
433 (should-error (delete 2 (cyc2 1 2)) :type 'circular-list)
434 (should-error (delete 2 (dot1 1)) :type 'wrong-type-argument)
435 (should-error (delete 2 (dot2 1 2)) :type 'wrong-type-argument)
436 (should-error (delete 3 (cyc1 1)) :type 'circular-list)
437 (should-error (delete 3 (cyc2 1 2)) :type 'circular-list)
438 (should-error (delete 3 (dot1 1)) :type 'wrong-type-argument)
439 (should-error (delete 3 (dot2 1 2)) :type 'wrong-type-argument))
441 (ert-deftest test-cycle-reverse ()
442 (should-error (reverse (cyc1 1)) :type 'circular-list)
443 (should-error (reverse (cyc2 1 2)) :type 'circular-list)
444 (should-error (reverse (dot1 1)) :type 'wrong-type-argument)
445 (should-error (reverse (dot2 1 2)) :type 'wrong-type-argument))
447 (ert-deftest test-cycle-plist-get ()
448 (let ((c1 (cyc1 1))
449 (c2 (cyc2 1 2))
450 (d1 (dot1 1))
451 (d2 (dot2 1 2)))
452 (should (plist-get c1 1))
453 (should (plist-get c2 1))
454 (should (plist-get d1 1))
455 (should (plist-get d2 1))
456 (should-not (plist-get c1 2))
457 (should (plist-get c2 2))
458 (should-not (plist-get d1 2))
459 (should (plist-get d2 2))
460 (should-not (plist-get c1 3))
461 (should-not (plist-get c2 3))
462 (should-not (plist-get d1 3))
463 (should-not (plist-get d2 3))))
465 (ert-deftest test-cycle-lax-plist-get ()
466 (let ((c1 (cyc1 1))
467 (c2 (cyc2 1 2))
468 (d1 (dot1 1))
469 (d2 (dot2 1 2)))
470 (should (lax-plist-get c1 1))
471 (should (lax-plist-get c2 1))
472 (should (lax-plist-get d1 1))
473 (should (lax-plist-get d2 1))
474 (should-error (lax-plist-get c1 2) :type 'circular-list)
475 (should (lax-plist-get c2 2))
476 (should-error (lax-plist-get d1 2) :type 'wrong-type-argument)
477 (should (lax-plist-get d2 2))
478 (should-error (lax-plist-get c1 3) :type 'circular-list)
479 (should-error (lax-plist-get c2 3) :type 'circular-list)
480 (should-error (lax-plist-get d1 3) :type 'wrong-type-argument)
481 (should-error (lax-plist-get d2 3) :type 'wrong-type-argument)))
483 (ert-deftest test-cycle-plist-member ()
484 (let ((c1 (cyc1 1))
485 (c2 (cyc2 1 2))
486 (d1 (dot1 1))
487 (d2 (dot2 1 2)))
488 (should (plist-member c1 1))
489 (should (plist-member c2 1))
490 (should (plist-member d1 1))
491 (should (plist-member d2 1))
492 (should-error (plist-member c1 2) :type 'circular-list)
493 (should (plist-member c2 2))
494 (should-error (plist-member d1 2) :type 'wrong-type-argument)
495 (should (plist-member d2 2))
496 (should-error (plist-member c1 3) :type 'circular-list)
497 (should-error (plist-member c2 3) :type 'circular-list)
498 (should-error (plist-member d1 3) :type 'wrong-type-argument)
499 (should-error (plist-member d2 3) :type 'wrong-type-argument)))
501 (ert-deftest test-cycle-plist-put ()
502 (let ((c1 (cyc1 1))
503 (c2 (cyc2 1 2))
504 (d1 (dot1 1))
505 (d2 (dot2 1 2)))
506 (should (plist-put c1 1 1))
507 (should (plist-put c2 1 1))
508 (should (plist-put d1 1 1))
509 (should (plist-put d2 1 1))
510 (should-error (plist-put c1 2 2) :type 'circular-list)
511 (should (plist-put c2 2 2))
512 (should-error (plist-put d1 2 2) :type 'wrong-type-argument)
513 (should (plist-put d2 2 2))
514 (should-error (plist-put c1 3 3) :type 'circular-list)
515 (should-error (plist-put c2 3 3) :type 'circular-list)
516 (should-error (plist-put d1 3 3) :type 'wrong-type-argument)
517 (should-error (plist-put d2 3 3) :type 'wrong-type-argument)))
519 (ert-deftest test-cycle-lax-plist-put ()
520 (let ((c1 (cyc1 1))
521 (c2 (cyc2 1 2))
522 (d1 (dot1 1))
523 (d2 (dot2 1 2)))
524 (should (lax-plist-put c1 1 1))
525 (should (lax-plist-put c2 1 1))
526 (should (lax-plist-put d1 1 1))
527 (should (lax-plist-put d2 1 1))
528 (should-error (lax-plist-put c1 2 2) :type 'circular-list)
529 (should (lax-plist-put c2 2 2))
530 (should-error (lax-plist-put d1 2 2) :type 'wrong-type-argument)
531 (should (lax-plist-put d2 2 2))
532 (should-error (lax-plist-put c1 3 3) :type 'circular-list)
533 (should-error (lax-plist-put c2 3 3) :type 'circular-list)
534 (should-error (lax-plist-put d1 3 3) :type 'wrong-type-argument)
535 (should-error (lax-plist-put d2 3 3) :type 'wrong-type-argument)))
537 (ert-deftest test-cycle-equal ()
538 (should-error (equal (cyc1 1) (cyc1 1)))
539 (should-error (equal (cyc2 1 2) (cyc2 1 2))))
541 (ert-deftest test-cycle-nconc ()
542 (should-error (nconc (cyc1 1) 'tail) :type 'circular-list)
543 (should-error (nconc (cyc2 1 2) 'tail) :type 'circular-list))
545 (provide 'fns-tests)