-
Notifications
You must be signed in to change notification settings - Fork 7
/
list.pure.lisp
57 lines (52 loc) · 2.15 KB
/
list.pure.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;;; tests related to lists
;;;; This software is part of the SBCL system. See the README file for
;;;; more information.
;;;;
;;;; While most of SBCL is derived from the CMU CL system, the test
;;;; files (like this one) were written from scratch after the fork
;;;; from CMU CL.
;;;;
;;;; This software is in the public domain and is provided with
;;;; absolutely no warranty. See the COPYING and CREDITS files for
;;;; more information.
(in-package :cl-user)
;;; Since *another* BUTLAST problem was reported (anonymously!) on the
;;; SourceForge summary page magical bugs web interface 2001-09-01, it
;;; looks as though it's past time to start accumulating regression
;;; tests for these.
(dolist (testcase
'((:args ((1 2 3 4 5)) :result (1 2 3 4))
(:args ((1 2 3 4 5) 6) :result nil)
(:args (nil) :result nil)
(:args ((1 2 3) 0) :result (1 2 3))
(:args ((1 2 3) 1) :result (1 2))
(:args ((1 2 3)) :result (1 2))
(:args ((1 2 3) 2) :result (1))
(:args ((1 2 3) 3) :result nil)
(:args ((1 2 3) 4) :result nil)
(:args ((1 2 3 . 4) 0) :result (1 2 3 . 4))
(:args ((1 2 3 . 4) 1) :result (1 2))
(:args ((1 2 3 . 4)) :result (1 2))
(:args ((1 2 3 . 4) 2) :result (1))
(:args ((1 2 3 . 4) 3) :result nil)
(:args ((1 2 3 . 4) 4) :result nil)))
(destructuring-bind (&key args result) testcase
(destructuring-bind (list &rest rest) args
;; Test with BUTLAST.
(let ((actual-result (apply #'butlast args)))
(when (and (consp list) (eq actual-result list))
(error "not a copy in BUTLAST for ~S" args))
(unless (equal actual-result result)
(error "failed BUTLAST for ~S" args)))
;; Test with NBUTLAST.
(let* ((copied-list (copy-list list))
(actual-result (apply #'nbutlast copied-list rest)))
(unless (equal actual-result result)
(error "failed NBUTLAST for ~S" args))))))
(multiple-value-bind (result error)
(ignore-errors (apply #'butlast (list t)))
(assert (null result))
(assert (typep error 'type-error)))
;;; reported by Paul Dietz on cmucl-imp: LDIFF does not check type of
;;; its first argument
(assert (not (ignore-errors (ldiff 1 2))))