unless.lsp 1.64 KB
Newer Older
1 2 3 4 5
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Fri Oct 18 19:39:34 2002
;;;; Contains: Tests of UNLESS

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

(deftest unless.1
  (unless t)
  nil)

(deftest unless.2
  (unless nil)
  nil)

(deftest unless.3
  (unless 'b 'a)
  nil)

(deftest unless.4
  (unless nil 'a)
  a)

(deftest unless.5 (unless nil (values)))

(deftest unless.6
  (unless nil (values 1 2 3 4))
  1 2 3 4)

(deftest unless.7
  (unless 1 (values))
  nil)

(deftest unless.8
  (unless #() (values 1 2 3 4))
  nil)

(deftest unless.9
  (let ((x 0))
    (values
     (unless nil
       (incf x)
       'a)
     x))
  a 1)

47 48 49 50 51 52 53 54 55 56 57 58
;;; No implicit tagbody
(deftest unless.10
  (block done
    (tagbody
     (unless nil
       (go 10)
       10
       (return-from done 'bad))
     10
     (return-from done 'good)))
  good)

59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
;;; Test that explicit calls to macroexpand in subforms
;;; are done in the correct environment

(deftest unless.11
  (macrolet
   ((%m (z) z))
   (unless (expand-in-current-env (%m nil)) :good))
  :good)

(deftest unless.12
  (macrolet
   ((%m (z) z))
   (unless (expand-in-current-env (%m t)) :bad))
  nil)

(deftest unless.13
  (macrolet
   ((%m (z) z))
   (let ((x 1) (p nil))
     (values
      (unless p (expand-in-current-env (%m (incf x))))
      x)))
  2 2)

83
(deftest unless.error.1
84 85
  (signals-error (funcall (macro-function 'unless)) program-error)
  t)
86 87

(deftest unless.error.2
88
  (signals-error (funcall (macro-function 'unless)
sds's avatar
sds committed
89 90
                           '(unless t))
                 program-error)
91
  t)
92 93

(deftest unless.error.3
94
  (signals-error (funcall (macro-function 'unless)
sds's avatar
sds committed
95 96
                           '(unless t) nil nil)
                 program-error)
97
  t)