make-list.lsp 2.33 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Apr 19 22:04:27 2003
;;;; Contains: Tests of MAKE-LIST

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
(deftest make-list-empty.1
  (make-list 0)
  nil)

(deftest make-list-empty.2
  (make-list 0 :initial-element 'a)
  nil)

(deftest make-list-no-initial-element
  (make-list 6)
  (nil nil nil nil nil nil))

(deftest make-list-with-initial-element
  (make-list 6 :initial-element 'a)
  (a a a a a a))

(deftest make-list.allow-other-keys.1
  (make-list 5 :allow-other-keys t :foo 'a)
  (nil nil nil nil nil))

(deftest make-list.allow-other-keys.2
  (make-list 5 :bar nil :allow-other-keys t)
  (nil nil nil nil nil))

(deftest make-list.allow-other-keys.3
  (make-list 5 :allow-other-keys nil)
  (nil nil nil nil nil))

(deftest make-list.allow-other-keys.4
  (make-list 5 :allow-other-keys t :allow-other-keys nil 'bad t)
  (nil nil nil nil nil))

(deftest make-list.allow-other-keys.5
  (make-list 5 :allow-other-keys t)
  (nil nil nil nil nil))

(deftest make-list-repeated-keyword
  (make-list 5 :initial-element 'a :initial-element 'b)
  (a a a a a))

(deftest make-list.order.1
  (let ((i 0) x y)
    (values
     (make-list (progn (setf x (incf i)) 5)
sds's avatar
sds committed
54 55
                :initial-element
                (progn (setf y (incf i)) 'a))
56 57 58 59 60 61 62 63
     i x y))
  (a a a a a)
  2 1 2)

(deftest make-list.order.2
  (let ((i 0) x y z)
    (values
     (make-list (progn (setf x (incf i)) 5)
sds's avatar
sds committed
64 65 66 67
                :initial-element
                (progn (setf y (incf i)) 'a)
                :initial-element
                (progn (setf z (incf i)) 'b))
68 69 70 71
     i x y z))
  (a a a a a)
  3 1 2 3)

pfdietz's avatar
pfdietz committed
72 73 74 75
(def-fold-test make-list.fold.1 (make-list 1))
(def-fold-test make-list.fold.2 (make-list 10 :initial-element 'x))

;;; Error tests
76 77

(deftest make-list.error.1
pfdietz's avatar
pfdietz committed
78 79
  (check-type-error #'make-list (typef 'unsigned-byte))
  nil)
80 81

(deftest make-list.error.3
82 83
  (signals-error (make-list) program-error)
  t)
84 85

(deftest make-list.error.4
86 87
  (signals-error (make-list 5 :bad t) program-error)
  t)
88 89

(deftest make-list.error.5
90 91
  (signals-error (make-list 5 :initial-element) program-error)
  t)
92 93

(deftest make-list.error.6
94 95
  (signals-error (make-list 5 1 2) program-error)
  t)
96 97

(deftest make-list.error.7
98
  (signals-error (make-list 5 :bad t :allow-other-keys nil)
sds's avatar
sds committed
99
                 program-error)
100
  t)
101 102

(deftest make-list.error.8
103 104
  (signals-error (locally (make-list 'a) t) type-error)
  t)