* lisp/progmodes/cc-cmds.el: Remove unused vars
[emacs.git] / test / src / fns-tests.el
blob2e463455f0c825c4ab3600baad58aeaa2cadbffe
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)
26 (ert-deftest fns-tests-reverse ()
27 (should-error (reverse))
28 (should-error (reverse 1))
29 (should-error (reverse (make-char-table 'foo)))
30 (should (equal [] (reverse [])))
31 (should (equal [0] (reverse [0])))
32 (should (equal [1 2 3 4] (reverse (reverse [1 2 3 4]))))
33 (should (equal '(a b c d) (reverse (reverse '(a b c d)))))
34 (should (equal "xyzzy" (reverse (reverse "xyzzy"))))
35 (should (equal "こんにちは / コンニチハ" (reverse (reverse "こんにちは / コンニチハ")))))
37 (ert-deftest fns-tests-nreverse ()
38 (should-error (nreverse))
39 (should-error (nreverse 1))
40 (should-error (nreverse (make-char-table 'foo)))
41 (should (equal (nreverse "xyzzy") "yzzyx"))
42 (let ((A []))
43 (nreverse A)
44 (should (equal A [])))
45 (let ((A [0]))
46 (nreverse A)
47 (should (equal A [0])))
48 (let ((A [1 2 3 4]))
49 (nreverse A)
50 (should (equal A [4 3 2 1])))
51 (let ((A [1 2 3 4]))
52 (nreverse A)
53 (nreverse A)
54 (should (equal A [1 2 3 4])))
55 (let* ((A [1 2 3 4])
56 (B (nreverse (nreverse A))))
57 (should (equal A B))))
59 (ert-deftest fns-tests-reverse-bool-vector ()
60 (let ((A (make-bool-vector 10 nil)))
61 (dotimes (i 5) (aset A i t))
62 (should (equal [nil nil nil nil nil t t t t t] (vconcat (reverse A))))
63 (should (equal A (reverse (reverse A))))))
65 (ert-deftest fns-tests-nreverse-bool-vector ()
66 (let ((A (make-bool-vector 10 nil)))
67 (dotimes (i 5) (aset A i t))
68 (nreverse A)
69 (should (equal [nil nil nil nil nil t t t t t] (vconcat A)))
70 (should (equal [t t t t t nil nil nil nil nil] (vconcat (nreverse A))))))
72 (ert-deftest fns-tests-compare-strings ()
73 (should-error (compare-strings))
74 (should-error (compare-strings "xyzzy" "xyzzy"))
75 (should (= (compare-strings "xyzzy" 0 10 "zyxxy" 0 5) -1))
76 (should-error (compare-strings "xyzzy" 0 5 "zyxxy" -1 2))
77 (should-error (compare-strings "xyzzy" 'foo nil "zyxxy" 0 1))
78 (should-error (compare-strings "xyzzy" 0 'foo "zyxxy" 2 3))
79 (should-error (compare-strings "xyzzy" 0 2 "zyxxy" 'foo 3))
80 (should-error (compare-strings "xyzzy" nil 3 "zyxxy" 4 'foo))
81 (should (eq (compare-strings "" nil nil "" nil nil) t))
82 (should (eq (compare-strings "" 0 0 "" 0 0) t))
83 (should (eq (compare-strings "test" nil nil "test" nil nil) t))
84 (should (eq (compare-strings "test" nil nil "test" nil nil t) t))
85 (should (eq (compare-strings "test" nil nil "test" nil nil nil) t))
86 (should (eq (compare-strings "Test" nil nil "test" nil nil t) t))
87 (should (= (compare-strings "Test" nil nil "test" nil nil) -1))
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 "foobaz" nil nil "barbaz" nil nil) 1))
91 (should (= (compare-strings "barbaz" nil nil "foobar" nil nil) -1))
92 (should (= (compare-strings "foobaz" nil nil "farbaz" nil nil) 2))
93 (should (= (compare-strings "farbaz" nil nil "foobar" nil nil) -2))
94 (should (eq (compare-strings "abcxyz" 0 2 "abcprq" 0 2) t))
95 (should (eq (compare-strings "abcxyz" 0 -3 "abcprq" 0 -3) t))
96 (should (= (compare-strings "abcxyz" 0 6 "abcprq" 0 6) 4))
97 (should (= (compare-strings "abcprq" 0 6 "abcxyz" 0 6) -4))
98 (should (eq (compare-strings "xyzzy" -3 4 "azza" -3 3) t))
99 (should (eq (compare-strings "こんにちはコンニチハ" nil nil "こんにちはコンニチハ" nil nil) t))
100 (should (= (compare-strings "んにちはコンニチハこ" nil nil "こんにちはコンニチハ" nil nil) 1))
101 (should (= (compare-strings "こんにちはコンニチハ" nil nil "んにちはコンニチハこ" nil nil) -1)))
103 (defun fns-tests--collate-enabled-p ()
104 "Check whether collation functions are enabled."
105 (and
106 ;; When there is no collation library, collation functions fall back
107 ;; to their lexicographic counterparts. We don't need to test then.
108 (not (ignore-errors (string-collate-equalp "" "" t)))
109 ;; We use a locale, which might not be installed. Check it.
110 (ignore-errors
111 (string-collate-equalp
112 "" "" (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
114 (ert-deftest fns-tests-collate-strings ()
115 (skip-unless (fns-tests--collate-enabled-p))
117 (should (string-collate-equalp "xyzzy" "xyzzy"))
118 (should-not (string-collate-equalp "xyzzy" "XYZZY"))
120 ;; In POSIX or C locales, collation order is lexicographic.
121 (should (string-collate-lessp "XYZZY" "xyzzy" "POSIX"))
122 ;; In a language specific locale, collation order is different.
123 (should (string-collate-lessp
124 "xyzzy" "XYZZY"
125 (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))
127 ;; Ignore case.
128 (should (string-collate-equalp "xyzzy" "XYZZY" nil t))
130 ;; Locale must be valid.
131 (should-error (string-collate-equalp "xyzzy" "xyzzy" "en_DE.UTF-8")))
133 ;; There must be a check for valid codepoints. (Check not implemented yet)
134 ; (should-error
135 ; (string-collate-equalp (string ?\x00110000) (string ?\x00110000)))
136 ;; Invalid UTF-8 sequences shall be indicated. How to create such strings?
138 (ert-deftest fns-tests-sort ()
139 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (< x y)))
140 '(-1 2 3 4 5 5 7 8 9)))
141 (should (equal (sort '(9 5 2 -1 5 3 8 7 4) (lambda (x y) (> x y)))
142 '(9 8 7 5 5 4 3 2 -1)))
143 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (< x y)))
144 [-1 2 3 4 5 5 7 8 9]))
145 (should (equal (sort '[9 5 2 -1 5 3 8 7 4] (lambda (x y) (> x y)))
146 [9 8 7 5 5 4 3 2 -1]))
147 (should (equal
148 (sort
149 (vector
150 '(8 . "xxx") '(9 . "aaa") '(8 . "bbb") '(9 . "zzz")
151 '(9 . "ppp") '(8 . "ttt") '(8 . "eee") '(9 . "fff"))
152 (lambda (x y) (< (car x) (car y))))
153 [(8 . "xxx") (8 . "bbb") (8 . "ttt") (8 . "eee")
154 (9 . "aaa") (9 . "zzz") (9 . "ppp") (9 . "fff")])))
156 (ert-deftest fns-tests-collate-sort ()
157 ;; See https://lists.gnu.org/archive/html/emacs-devel/2015-10/msg02505.html.
158 :expected-result (if (eq system-type 'cygwin) :failed :passed)
159 (skip-unless (fns-tests--collate-enabled-p))
161 ;; Punctuation and whitespace characters are relevant for POSIX.
162 (should
163 (equal
164 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
165 (lambda (a b) (string-collate-lessp a b "POSIX")))
166 '("1 1" "1 2" "1.1" "1.2" "11" "12")))
167 ;; Punctuation and whitespace characters are not taken into account
168 ;; for collation in other locales.
169 (should
170 (equal
171 (sort '("11" "12" "1 1" "1 2" "1.1" "1.2")
172 (lambda (a b)
173 (let ((w32-collate-ignore-punctuation t))
174 (string-collate-lessp
175 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
176 '("11" "1 1" "1.1" "12" "1 2" "1.2")))
178 ;; Diacritics are different letters for POSIX, they sort lexicographical.
179 (should
180 (equal
181 (sort '("Ævar" "Agustín" "Adrian" "Eli")
182 (lambda (a b) (string-collate-lessp a b "POSIX")))
183 '("Adrian" "Agustín" "Eli" "Ævar")))
184 ;; Diacritics are sorted between similar letters for other locales.
185 (should
186 (equal
187 (sort '("Ævar" "Agustín" "Adrian" "Eli")
188 (lambda (a b)
189 (let ((w32-collate-ignore-punctuation t))
190 (string-collate-lessp
191 a b (if (eq system-type 'windows-nt) "enu_USA" "en_US.UTF-8")))))
192 '("Adrian" "Ævar" "Agustín" "Eli"))))
194 (ert-deftest fns-tests-string-version-lessp ()
195 (should (string-version-lessp "foo2.png" "foo12.png"))
196 (should (not (string-version-lessp "foo12.png" "foo2.png")))
197 (should (string-version-lessp "foo12.png" "foo20000.png"))
198 (should (not (string-version-lessp "foo20000.png" "foo12.png")))
199 (should (string-version-lessp "foo.png" "foo2.png"))
200 (should (not (string-version-lessp "foo2.png" "foo.png")))
201 (should (equal (sort '("foo12.png" "foo2.png" "foo1.png")
202 'string-version-lessp)
203 '("foo1.png" "foo2.png" "foo12.png")))
204 (should (string-version-lessp "foo2" "foo1234"))
205 (should (not (string-version-lessp "foo1234" "foo2")))
206 (should (string-version-lessp "foo.png" "foo2"))
207 (should (string-version-lessp "foo1.25.5.png" "foo1.125.5"))
208 (should (string-version-lessp "2" "1245"))
209 (should (not (string-version-lessp "1245" "2"))))
211 (ert-deftest fns-tests-func-arity ()
212 (should (equal (func-arity 'car) '(1 . 1)))
213 (should (equal (func-arity 'caar) '(1 . 1)))
214 (should (equal (func-arity 'format) '(1 . many)))
215 (require 'info)
216 (should (equal (func-arity 'Info-goto-node) '(1 . 3)))
217 (should (equal (func-arity (lambda (&rest x))) '(0 . many)))
218 (should (equal (func-arity (eval (lambda (x &optional y)) nil)) '(1 . 2)))
219 (should (equal (func-arity (eval (lambda (x &optional y)) t)) '(1 . 2)))
220 (should (equal (func-arity 'let) '(1 . unevalled))))
222 (ert-deftest fns-tests-hash-buffer ()
223 (should (equal (sha1 "foo") "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"))
224 (should (equal (with-temp-buffer
225 (insert "foo")
226 (buffer-hash))
227 (sha1 "foo")))
228 ;; This tests whether the presence of a gap in the middle of the
229 ;; buffer is handled correctly.
230 (should (equal (with-temp-buffer
231 (insert "foo")
232 (goto-char 2)
233 (insert " ")
234 (backward-delete-char 1)
235 (buffer-hash))
236 (sha1 "foo"))))
238 (ert-deftest fns-tests-mapcan ()
239 (should-error (mapcan))
240 (should-error (mapcan #'identity))
241 (should-error (mapcan #'identity (make-char-table 'foo)))
242 (should (equal (mapcan #'list '(1 2 3)) '(1 2 3)))
243 ;; `mapcan' is destructive
244 (let ((data '((foo) (bar))))
245 (should (equal (mapcan #'identity data) '(foo bar)))
246 (should (equal data '((foo bar) (bar))))))
248 ;; Test handling of cyclic and dotted lists.
250 (defun cyc1 (a)
251 (let ((ls (make-list 10 a)))
252 (nconc ls ls)
253 ls))
255 (defun cyc2 (a b)
256 (let ((ls1 (make-list 10 a))
257 (ls2 (make-list 1000 b)))
258 (nconc ls2 ls2)
259 (nconc ls1 ls2)
260 ls1))
262 (defun dot1 (a)
263 (let ((ls (make-list 10 a)))
264 (nconc ls 'tail)
265 ls))
267 (defun dot2 (a b)
268 (let ((ls1 (make-list 10 a))
269 (ls2 (make-list 10 b)))
270 (nconc ls1 ls2)
271 (nconc ls2 'tail)
272 ls1))
274 (ert-deftest test-cycle-length ()
275 (should-error (length (cyc1 1)) :type 'circular-list)
276 (should-error (length (cyc2 1 2)) :type 'circular-list)
277 (should-error (length (dot1 1)) :type 'wrong-type-argument)
278 (should-error (length (dot2 1 2)) :type 'wrong-type-argument))
280 (ert-deftest test-cycle-safe-length ()
281 (should (<= 10 (safe-length (cyc1 1))))
282 (should (<= 1010 (safe-length (cyc2 1 2))))
283 (should (= 10 (safe-length (dot1 1))))
284 (should (= 20 (safe-length (dot2 1 2)))))
286 (ert-deftest test-cycle-member ()
287 (let ((c1 (cyc1 1))
288 (c2 (cyc2 1 2))
289 (d1 (dot1 1))
290 (d2 (dot2 1 2)))
291 (should (member 1 c1))
292 (should (member 1 c2))
293 (should (member 1 d1))
294 (should (member 1 d2))
295 (should-error (member 2 c1) :type 'circular-list)
296 (should (member 2 c2))
297 (should-error (member 2 d1) :type 'wrong-type-argument)
298 (should (member 2 d2))
299 (should-error (member 3 c1) :type 'circular-list)
300 (should-error (member 3 c2) :type 'circular-list)
301 (should-error (member 3 d1) :type 'wrong-type-argument)
302 (should-error (member 3 d2) :type 'wrong-type-argument)))
304 (ert-deftest test-cycle-memq ()
305 (let ((c1 (cyc1 1))
306 (c2 (cyc2 1 2))
307 (d1 (dot1 1))
308 (d2 (dot2 1 2)))
309 (should (memq 1 c1))
310 (should (memq 1 c2))
311 (should (memq 1 d1))
312 (should (memq 1 d2))
313 (should-error (memq 2 c1) :type 'circular-list)
314 (should (memq 2 c2))
315 (should-error (memq 2 d1) :type 'wrong-type-argument)
316 (should (memq 2 d2))
317 (should-error (memq 3 c1) :type 'circular-list)
318 (should-error (memq 3 c2) :type 'circular-list)
319 (should-error (memq 3 d1) :type 'wrong-type-argument)
320 (should-error (memq 3 d2) :type 'wrong-type-argument)))
322 (ert-deftest test-cycle-memql ()
323 (let ((c1 (cyc1 1))
324 (c2 (cyc2 1 2))
325 (d1 (dot1 1))
326 (d2 (dot2 1 2)))
327 (should (memql 1 c1))
328 (should (memql 1 c2))
329 (should (memql 1 d1))
330 (should (memql 1 d2))
331 (should-error (memql 2 c1) :type 'circular-list)
332 (should (memql 2 c2))
333 (should-error (memql 2 d1) :type 'wrong-type-argument)
334 (should (memql 2 d2))
335 (should-error (memql 3 c1) :type 'circular-list)
336 (should-error (memql 3 c2) :type 'circular-list)
337 (should-error (memql 3 d1) :type 'wrong-type-argument)
338 (should-error (memql 3 d2) :type 'wrong-type-argument)))
340 (ert-deftest test-cycle-assq ()
341 (let ((c1 (cyc1 '(1)))
342 (c2 (cyc2 '(1) '(2)))
343 (d1 (dot1 '(1)))
344 (d2 (dot2 '(1) '(2))))
345 (should (assq 1 c1))
346 (should (assq 1 c2))
347 (should (assq 1 d1))
348 (should (assq 1 d2))
349 (should-error (assq 2 c1) :type 'circular-list)
350 (should (assq 2 c2))
351 (should-error (assq 2 d1) :type 'wrong-type-argument)
352 (should (assq 2 d2))
353 (should-error (assq 3 c1) :type 'circular-list)
354 (should-error (assq 3 c2) :type 'circular-list)
355 (should-error (assq 3 d1) :type 'wrong-type-argument)
356 (should-error (assq 3 d2) :type 'wrong-type-argument)))
358 (ert-deftest test-cycle-assoc ()
359 (let ((c1 (cyc1 '(1)))
360 (c2 (cyc2 '(1) '(2)))
361 (d1 (dot1 '(1)))
362 (d2 (dot2 '(1) '(2))))
363 (should (assoc 1 c1))
364 (should (assoc 1 c2))
365 (should (assoc 1 d1))
366 (should (assoc 1 d2))
367 (should-error (assoc 2 c1) :type 'circular-list)
368 (should (assoc 2 c2))
369 (should-error (assoc 2 d1) :type 'wrong-type-argument)
370 (should (assoc 2 d2))
371 (should-error (assoc 3 c1) :type 'circular-list)
372 (should-error (assoc 3 c2) :type 'circular-list)
373 (should-error (assoc 3 d1) :type 'wrong-type-argument)
374 (should-error (assoc 3 d2) :type 'wrong-type-argument)))
376 (ert-deftest test-cycle-rassq ()
377 (let ((c1 (cyc1 '(0 . 1)))
378 (c2 (cyc2 '(0 . 1) '(0 . 2)))
379 (d1 (dot1 '(0 . 1)))
380 (d2 (dot2 '(0 . 1) '(0 . 2))))
381 (should (rassq 1 c1))
382 (should (rassq 1 c2))
383 (should (rassq 1 d1))
384 (should (rassq 1 d2))
385 (should-error (rassq 2 c1) :type 'circular-list)
386 (should (rassq 2 c2))
387 (should-error (rassq 2 d1) :type 'wrong-type-argument)
388 (should (rassq 2 d2))
389 (should-error (rassq 3 c1) :type 'circular-list)
390 (should-error (rassq 3 c2) :type 'circular-list)
391 (should-error (rassq 3 d1) :type 'wrong-type-argument)
392 (should-error (rassq 3 d2) :type 'wrong-type-argument)))
394 (ert-deftest test-cycle-rassoc ()
395 (let ((c1 (cyc1 '(0 . 1)))
396 (c2 (cyc2 '(0 . 1) '(0 . 2)))
397 (d1 (dot1 '(0 . 1)))
398 (d2 (dot2 '(0 . 1) '(0 . 2))))
399 (should (rassoc 1 c1))
400 (should (rassoc 1 c2))
401 (should (rassoc 1 d1))
402 (should (rassoc 1 d2))
403 (should-error (rassoc 2 c1) :type 'circular-list)
404 (should (rassoc 2 c2))
405 (should-error (rassoc 2 d1) :type 'wrong-type-argument)
406 (should (rassoc 2 d2))
407 (should-error (rassoc 3 c1) :type 'circular-list)
408 (should-error (rassoc 3 c2) :type 'circular-list)
409 (should-error (rassoc 3 d1) :type 'wrong-type-argument)
410 (should-error (rassoc 3 d2) :type 'wrong-type-argument)))
412 (ert-deftest test-cycle-delq ()
413 (should-error (delq 1 (cyc1 1)) :type 'circular-list)
414 (should-error (delq 1 (cyc2 1 2)) :type 'circular-list)
415 (should-error (delq 1 (dot1 1)) :type 'wrong-type-argument)
416 (should-error (delq 1 (dot2 1 2)) :type 'wrong-type-argument)
417 (should-error (delq 2 (cyc1 1)) :type 'circular-list)
418 (should-error (delq 2 (cyc2 1 2)) :type 'circular-list)
419 (should-error (delq 2 (dot1 1)) :type 'wrong-type-argument)
420 (should-error (delq 2 (dot2 1 2)) :type 'wrong-type-argument)
421 (should-error (delq 3 (cyc1 1)) :type 'circular-list)
422 (should-error (delq 3 (cyc2 1 2)) :type 'circular-list)
423 (should-error (delq 3 (dot1 1)) :type 'wrong-type-argument)
424 (should-error (delq 3 (dot2 1 2)) :type 'wrong-type-argument))
426 (ert-deftest test-cycle-delete ()
427 (should-error (delete 1 (cyc1 1)) :type 'circular-list)
428 (should-error (delete 1 (cyc2 1 2)) :type 'circular-list)
429 (should-error (delete 1 (dot1 1)) :type 'wrong-type-argument)
430 (should-error (delete 1 (dot2 1 2)) :type 'wrong-type-argument)
431 (should-error (delete 2 (cyc1 1)) :type 'circular-list)
432 (should-error (delete 2 (cyc2 1 2)) :type 'circular-list)
433 (should-error (delete 2 (dot1 1)) :type 'wrong-type-argument)
434 (should-error (delete 2 (dot2 1 2)) :type 'wrong-type-argument)
435 (should-error (delete 3 (cyc1 1)) :type 'circular-list)
436 (should-error (delete 3 (cyc2 1 2)) :type 'circular-list)
437 (should-error (delete 3 (dot1 1)) :type 'wrong-type-argument)
438 (should-error (delete 3 (dot2 1 2)) :type 'wrong-type-argument))
440 (ert-deftest test-cycle-reverse ()
441 (should-error (reverse (cyc1 1)) :type 'circular-list)
442 (should-error (reverse (cyc2 1 2)) :type 'circular-list)
443 (should-error (reverse (dot1 1)) :type 'wrong-type-argument)
444 (should-error (reverse (dot2 1 2)) :type 'wrong-type-argument))
446 (ert-deftest test-cycle-plist-get ()
447 (let ((c1 (cyc1 1))
448 (c2 (cyc2 1 2))
449 (d1 (dot1 1))
450 (d2 (dot2 1 2)))
451 (should (plist-get c1 1))
452 (should (plist-get c2 1))
453 (should (plist-get d1 1))
454 (should (plist-get d2 1))
455 (should-not (plist-get c1 2))
456 (should (plist-get c2 2))
457 (should-not (plist-get d1 2))
458 (should (plist-get d2 2))
459 (should-not (plist-get c1 3))
460 (should-not (plist-get c2 3))
461 (should-not (plist-get d1 3))
462 (should-not (plist-get d2 3))))
464 (ert-deftest test-cycle-lax-plist-get ()
465 (let ((c1 (cyc1 1))
466 (c2 (cyc2 1 2))
467 (d1 (dot1 1))
468 (d2 (dot2 1 2)))
469 (should (lax-plist-get c1 1))
470 (should (lax-plist-get c2 1))
471 (should (lax-plist-get d1 1))
472 (should (lax-plist-get d2 1))
473 (should-error (lax-plist-get c1 2) :type 'circular-list)
474 (should (lax-plist-get c2 2))
475 (should-error (lax-plist-get d1 2) :type 'wrong-type-argument)
476 (should (lax-plist-get d2 2))
477 (should-error (lax-plist-get c1 3) :type 'circular-list)
478 (should-error (lax-plist-get c2 3) :type 'circular-list)
479 (should-error (lax-plist-get d1 3) :type 'wrong-type-argument)
480 (should-error (lax-plist-get d2 3) :type 'wrong-type-argument)))
482 (ert-deftest test-cycle-plist-member ()
483 (let ((c1 (cyc1 1))
484 (c2 (cyc2 1 2))
485 (d1 (dot1 1))
486 (d2 (dot2 1 2)))
487 (should (plist-member c1 1))
488 (should (plist-member c2 1))
489 (should (plist-member d1 1))
490 (should (plist-member d2 1))
491 (should-error (plist-member c1 2) :type 'circular-list)
492 (should (plist-member c2 2))
493 (should-error (plist-member d1 2) :type 'wrong-type-argument)
494 (should (plist-member d2 2))
495 (should-error (plist-member c1 3) :type 'circular-list)
496 (should-error (plist-member c2 3) :type 'circular-list)
497 (should-error (plist-member d1 3) :type 'wrong-type-argument)
498 (should-error (plist-member d2 3) :type 'wrong-type-argument)))
500 (ert-deftest test-cycle-plist-put ()
501 (let ((c1 (cyc1 1))
502 (c2 (cyc2 1 2))
503 (d1 (dot1 1))
504 (d2 (dot2 1 2)))
505 (should (plist-put c1 1 1))
506 (should (plist-put c2 1 1))
507 (should (plist-put d1 1 1))
508 (should (plist-put d2 1 1))
509 (should-error (plist-put c1 2 2) :type 'circular-list)
510 (should (plist-put c2 2 2))
511 (should-error (plist-put d1 2 2) :type 'wrong-type-argument)
512 (should (plist-put d2 2 2))
513 (should-error (plist-put c1 3 3) :type 'circular-list)
514 (should-error (plist-put c2 3 3) :type 'circular-list)
515 (should-error (plist-put d1 3 3) :type 'wrong-type-argument)
516 (should-error (plist-put d2 3 3) :type 'wrong-type-argument)))
518 (ert-deftest test-cycle-lax-plist-put ()
519 (let ((c1 (cyc1 1))
520 (c2 (cyc2 1 2))
521 (d1 (dot1 1))
522 (d2 (dot2 1 2)))
523 (should (lax-plist-put c1 1 1))
524 (should (lax-plist-put c2 1 1))
525 (should (lax-plist-put d1 1 1))
526 (should (lax-plist-put d2 1 1))
527 (should-error (lax-plist-put c1 2 2) :type 'circular-list)
528 (should (lax-plist-put c2 2 2))
529 (should-error (lax-plist-put d1 2 2) :type 'wrong-type-argument)
530 (should (lax-plist-put d2 2 2))
531 (should-error (lax-plist-put c1 3 3) :type 'circular-list)
532 (should-error (lax-plist-put c2 3 3) :type 'circular-list)
533 (should-error (lax-plist-put d1 3 3) :type 'wrong-type-argument)
534 (should-error (lax-plist-put d2 3 3) :type 'wrong-type-argument)))
536 (ert-deftest test-cycle-equal ()
537 (should-error (equal (cyc1 1) (cyc1 1)))
538 (should-error (equal (cyc2 1 2) (cyc2 1 2))))
540 (ert-deftest test-cycle-nconc ()
541 (should-error (nconc (cyc1 1) 'tail) :type 'circular-list)
542 (should-error (nconc (cyc2 1 2) 'tail) :type 'circular-list))
544 (provide 'fns-tests)