if.lsp 1.38 KB
Newer Older
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
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Fri Oct 18 08:21:29 2002
;;;; Contains: Tests for IF

(in-package :cl-test)

(deftest if.1
  (if t 1 2)
  1)

(deftest if.2
  (if nil 1 2)
  2)

(deftest if.3 (if t (values) 'a))

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

(deftest if.5
  (if t (values 'a 'b 'c) 'd)
  a b c)

(deftest if.6
  (if nil 'a (values 'b 'c 'd))
  b c d)

(deftest if.7 (if nil 'a (values)))

32 33 34 35
;;; Macros are expanded in the appropriate environment

(deftest if.8
  (macrolet ((%m (z) z))
sds's avatar
sds committed
36
            (if (expand-in-current-env (%m t)) :good :bad))
37 38 39 40
  :good)

(deftest if.9
  (macrolet ((%m (z) z))
sds's avatar
sds committed
41
            (if (expand-in-current-env (%m nil)) :bad))
42 43 44 45
  nil)

(deftest if.10
  (macrolet ((%m (z) z))
sds's avatar
sds committed
46
            (if (expand-in-current-env (%m t)) :good))
47 48 49 50
  :good)

(deftest if.11
  (macrolet ((%m (z) z))
sds's avatar
sds committed
51
            (if (expand-in-current-env (%m nil)) :bad :good))
52 53 54 55 56 57
  :good)

(deftest if.12
  (macrolet
   ((%m (z) z))
   (flet ((%f (x y) (if x (expand-in-current-env (%m y)))))
sds's avatar
sds committed
58 59
         (declare (notinline %f))
         (values (%f t :good) (%f nil :bad))))
60
  :good nil)
sds's avatar
sds committed
61

62 63 64 65
(deftest if.13
  (macrolet
   ((%m (z) z))
   (flet ((%f (x y z) (if x y (expand-in-current-env (%m z)))))
sds's avatar
sds committed
66 67 68
         (declare (notinline %f))
         (values (%f t :good :bad) (%f nil :bad :good))))
  :good :good)
69

70 71 72 73
(deftest if.order.1
  (let ((i 0))
    (values (if (= (incf i) 1) 't nil) i))
  t 1)