aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorPaul Eggert2017-02-10 11:52:41 +0200
committerEli Zaretskii2017-02-10 11:52:41 +0200
commit65298ff4d5861cbc8d88162d58c18fa972b81acf (patch)
tree2fae2cfcb08c48749d72c5e151f00ded4b0ae44c /test/src
parentc48f8fa51b51746ffd39f7b973c471cd60994c8e (diff)
downloademacs-65298ff4d5861cbc8d88162d58c18fa972b81acf.tar.gz
emacs-65298ff4d5861cbc8d88162d58c18fa972b81acf.zip
Move cyclic tests to fns-tests.el
* test/src/fns-tests.el (cyc1, cyc2, dot1, dot2): New functions. (test-cycle-length, test-cycle-safe-length, test-cycle-member) (test-cycle-memq, test-cycle-memql, test-cycle-assq) (test-cycle-assoc, test-cycle-rassq, test-cycle-rassoc) (test-cycle-delq, test-cycle-delete, test-cycle-reverse) (test-cycle-plist-get, test-cycle-lax-plist-get) (test-cycle-plist-member, test-cycle-plist-put) (test-cycle-lax-plist-put, test-cycle-equal, test-cycle-nconc): New tests. * test/manual/cyclic-tests.el: File deleted.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/fns-tests.el298
1 files changed, 298 insertions, 0 deletions
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index ee3c5dc77e4..160d0f106e9 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -245,3 +245,301 @@
245 (let ((data '((foo) (bar)))) 245 (let ((data '((foo) (bar))))
246 (should (equal (mapcan #'identity data) '(foo bar))) 246 (should (equal (mapcan #'identity data) '(foo bar)))
247 (should (equal data '((foo bar) (bar)))))) 247 (should (equal data '((foo bar) (bar))))))
248
249;; Test handling of cyclic and dotted lists.
250
251(defun cyc1 (a)
252 (let ((ls (make-list 10 a)))
253 (nconc ls ls)
254 ls))
255
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))
262
263(defun dot1 (a)
264 (let ((ls (make-list 10 a)))
265 (nconc ls 'tail)
266 ls))
267
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))
274
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))
280
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)))))
286
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)))
304
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)))
322
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)))
340
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)))
358
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)))
376
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)))
394
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)))
412
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))
426
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))
440
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))
446
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))))
464
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-not (lax-plist-get d1 2))
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-not (lax-plist-get d1 3))
481 (should-not (lax-plist-get d2 3))))
482
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)))
500
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 (plist-put d1 2 2))
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 (plist-put d1 3 3))
517 (should (plist-put d2 3 3))))
518
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 (lax-plist-put d1 2 2))
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 (lax-plist-put d1 3 3))
535 (should (lax-plist-put d2 3 3))))
536
537(ert-deftest test-cycle-equal ()
538 (should-error (equal (cyc1 1) (cyc1 1)))
539 (should-error (equal (cyc2 1 2) (cyc2 1 2))))
540
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))
544
545(provide 'fns-tests)