apply.lsp 1.52 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Mon Jan 13 15:13:07 2003
;;;; Contains: Tests of APPLY

(in-package :cl-test)

;;; Error cases

(deftest apply.error.1
11 12
  (signals-error (apply) program-error)
  t)
13 14

(deftest apply.error.2
15 16
  (signals-error (apply #'cons) program-error)
  t)
17 18

(deftest apply.error.3
19 20
  (signals-error (apply #'cons nil) program-error)
  t)
21

22
(deftest apply.error.4
23
  (signals-error (apply #'cons (list 1 2 3))
sds's avatar
sds committed
24
                 program-error)
25
  t)
26

27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
;;; Non-error cases

(deftest apply.1
  (apply #'cons 'a 'b nil)
  (a . b))

(deftest apply.2
  (apply #'cons 'a '(b))
  (a . b))

(deftest apply.3
  (apply #'cons '(a b))
  (a . b))

(deftest apply.4
  (let ((zeros (make-list (min 10000 (1- call-arguments-limit))
sds's avatar
sds committed
43
                          :initial-element 1)))
44 45 46 47 48 49
    (apply #'+ zeros))
  #.(min 10000 (1- call-arguments-limit)))

(deftest apply.5
  (apply 'cons '(a b))
  (a . b))
50

51 52
(deftest apply.6
  (macrolet ((%m (z) z))
sds's avatar
sds committed
53
            (apply (expand-in-current-env (%m 'cons)) 1 2 nil))
54 55 56 57
  (1 . 2))

(deftest apply.7
  (macrolet ((%m (z) z))
sds's avatar
sds committed
58
            (apply #'cons (expand-in-current-env (%m 1)) '(2)))
59 60 61 62
  (1 . 2))

(deftest apply.8
  (macrolet ((%m (z) z))
sds's avatar
sds committed
63
            (apply #'cons (expand-in-current-env (%m '(1 2)))))
64 65
  (1 . 2))

66 67
(deftest apply.order.1
  (let ((i 0) x y z)
68
    (values
69
     (apply (progn (setf x (incf i))
sds's avatar
sds committed
70 71 72 73 74
                   #'list)
            (progn (setf y (incf i))
                   'b)
            (progn (setf z (incf i))
                   (list 'a)))
75 76 77
     i x y z))
  (b a) 3 1 2 3)