0.7.9.24:
[sbcl/lichteblau.git] / tests / list.pure.lisp
blob0abbdea906e0783d0acade57a53b77f850b80cd5
1 ;;;; tests related to lists
3 ;;;; This software is part of the SBCL system. See the README file for
4 ;;;; more information.
5 ;;;;
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
8 ;;;; from CMU CL.
9 ;;;;
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (in-package :cl-user)
16 ;;; Since *another* BUTLAST problem was reported (anonymously!) on the
17 ;;; SourceForge summary page magical bugs web interface 2001-09-01, it
18 ;;; looks as though it's past time to start accumulating regression
19 ;;; tests for these.
20 (dolist (testcase
21 '((:args ((1 2 3 4 5)) :result (1 2 3 4))
22 (:args ((1 2 3 4 5) 6) :result nil)
23 (:args (nil) :result nil)
24 (:args ((1 2 3) 0) :result (1 2 3))
25 (:args ((1 2 3) 1) :result (1 2))
26 (:args ((1 2 3)) :result (1 2))
27 (:args ((1 2 3) 2) :result (1))
28 (:args ((1 2 3) 3) :result nil)
29 (:args ((1 2 3) 4) :result nil)
30 (:args ((1 2 3 . 4) 0) :result (1 2 3 . 4))
31 (:args ((1 2 3 . 4) 1) :result (1 2))
32 (:args ((1 2 3 . 4)) :result (1 2))
33 (:args ((1 2 3 . 4) 2) :result (1))
34 (:args ((1 2 3 . 4) 3) :result nil)
35 (:args ((1 2 3 . 4) 4) :result nil)))
36 (destructuring-bind (&key args result) testcase
37 (destructuring-bind (list &rest rest) args
38 ;; Test with BUTLAST.
39 (let ((actual-result (apply #'butlast args)))
40 (when (and (consp list) (eq actual-result list))
41 (error "not a copy in BUTLAST for ~S" args))
42 (unless (equal actual-result result)
43 (error "failed BUTLAST for ~S" args)))
44 ;; Test with NBUTLAST.
45 (let* ((copied-list (copy-list list))
46 (actual-result (apply #'nbutlast copied-list rest)))
47 (unless (equal actual-result result)
48 (error "failed NBUTLAST for ~S" args))))))
50 (multiple-value-bind (result error)
51 (ignore-errors (apply #'butlast (list t)))
52 (assert (null result))
53 (assert (typep error 'type-error)))
55 ;;; reported by Paul Dietz on cmucl-imp: LDIFF does not check type of
56 ;;; its first argument
57 (assert (not (ignore-errors (ldiff 1 2))))
59 ;;; evaluation order in PUSH, PUSHNEW
60 (let ((a (map 'vector #'list '(a b c))))
61 (let ((i 0))
62 (pushnew (incf i) (aref a (incf i)))
63 (assert (equalp a #((a) (b) (1 c))))))
65 (symbol-macrolet ((s (aref a (incf i))))
66 (let ((a (map 'vector #'list '(a b c))))
67 (let ((i 0))
68 (push t s)
69 (assert (equalp a #((a) (t b) (c))))
70 (pushnew 1 s)
71 (assert (equalp a #((a) (t b) (1 c))))
72 (setq i 0)
73 (assert (eql (pop s) 't))
74 (assert (equalp a #((a) (b) (1 c)))))))