1 ;;;; tests related to lists
3 ;;;; This software is part of the SBCL system. See the README file for
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
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.
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
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 (t) :result nil)
25 (:args (foosymbol 0) :result foosymbol)
26 (:args (foosymbol) :result nil)
27 (:args (foosymbol 1) :result nil)
28 (:args (foosymbol 2) :result nil)
29 (:args ((1 2 3) 0) :result (1 2 3))
30 (:args ((1 2 3) 1) :result (1 2))
31 (:args ((1 2 3)) :result (1 2))
32 (:args ((1 2 3) 2) :result (1))
33 (:args ((1 2 3) 3) :result nil)
34 (:args ((1 2 3) 4) :result nil)
35 (:args ((1 2 3 . 4) 0) :result (1 2 3 . 4))
36 (:args ((1 2 3 . 4) 1) :result (1 2))
37 (:args ((1 2 3 . 4)) :result (1 2))
38 (:args ((1 2 3 . 4) 2) :result (1))
39 (:args ((1 2 3 . 4) 3) :result nil)
40 (:args ((1 2 3 . 4) 4) :result nil)))
41 (destructuring-bind (&key args result) testcase
42 (destructuring-bind (list &rest rest) args
44 (let ((actual-result (apply #'butlast args)))
45 (when (and (consp list) (eq actual-result list))
46 (error "not a copy in BUTLAST for ~S" args))
47 (unless (equal actual-result result)
48 (error "failed BUTLAST for ~S" args)))
49 ;; Test with NBUTLAST.
50 (let* ((copied-list (copy-list list))
51 (actual-result (apply #'nbutlast copied-list rest)))
52 (unless (equal actual-result result)
53 (error "failed NBUTLAST for ~S" args))))))