1
0
mirror of synced 2026-05-05 23:54:46 +00:00
Files
Interlisp.medley/internal/test/LANGUAGE/AUTO/7-6-WHEN.TEST

143 lines
3.6 KiB
Plaintext

;; Function To Be Tested: when
;;
;; Source: Steele's book
;; Section 7.6: Conditionals
;; Page: 115
;;
;; Created By: Bob Bane
;; Henry Cate III
;;
;; Creation Date: June 26,1986
;;
;; Last Update: June 26,1986
;; October 9,1986 HC3/ documented, and added
;; several more test cases
;; October 24,1986 HC3/ broke into several tests
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>7-6-WHEN.TEST
;;
;;
;; Syntax: (when test {form}*)
;;
;; (when p a b c) is exactly equal to:
;; (cond (p a b c))
;; (and p (progn a b c))
;; (if p (progn a b c) nil)
;; (unless (not p) a b c)
;;
;;
;; Function Description:
;; First TEST is evaluated. If the result is nil, then no
;; form is used. Otherwise the forms are evaluated sequentially
;; from left to right. The value of the last one is returned.
;;
;;
;;
;; Argument(s): TEST - a form which returns nil or non-nil
;; {forms}* - a sequence of lisp data objects
;;
;; Returns: value(s) of the last evaluated form of
;; the selected clause
;;
(do-test "test for the simple cases"
(and
; Does when evaluate and return the appropriate things?
; Check just boolean values
(when T T)
(when T nil nil T)
(eq (when nil T) nil)
(eq (when T T nil nil) nil)
))
(do-test "test when build test from a function"
(and
(when (> 5 0) T)
(when (> 5 0) nil nil T)
(eq (when (> 5 0) T) T)
(eq (when (> 5 0) T nil nil) nil)
(eq (when (> 5 10) T T T) nil)
))
(do-test "test with a local function, & able to pass symbols"
; Define two functions, tee returning T,
; and nill returning nil
(flet ((tee nil t) (nill nil nil))
(and
; check symbols
(eq (when (tee) 'foo) 'foo)
(eq (when (nill) 'foo) nil)
(eq (when (tee) 'bar 'bar 'foo) 'foo)
(eq (when (nill) 'bar 'bar 'foo) nil)
)))
(do-test "test with a local function, & able to pass numbers"
; Define two functions, tee returning T,
; and nill returning nil
(flet ((tee nil t) (nill nil nil))
(and
; check numbers
(eq (when (tee) (* 3 5)) 15)
(eq (when (tee) (* 3 5) (* 5 7)) 35)
(eq (when (tee) (* 3 5) (* 5 7) (* 9 4)) 36)
(eq (when (nill) (* 3 5)) nil)
(eq (when (nill) (* 3 5) (* 5 7) (* 9 4)) nil)
)))
(do-test "test non nil acts at true values"
(and
(when 5 T)
(when 5 nil T)
(when 'hi T)
(when 'hi nil nil T)
))
(do-test "test able to pass multiple values"
(flet ((tee nil t) (nill nil nil))
(and
(equal (multiple-value-list
(when (tee) (values 'foo 'bar)))
'(foo bar))
(equal (multiple-value-list
(when (tee) 56 'Hello (values 'bar 'foo)))
'(bar foo))
)))
(do-test "test values set in still set outside of when"
(flet ((tee nil t) (nill nil nil))
(let ((sideffect nil))
(and
(eq (when (tee) (setq sideffect T)) T)
(eq sideffect T)
(eq (when (tee) (setq sideffect 'foo)
'bar) 'bar)
(eq sideffect 'foo)
(eq (when (tee) (setq sideffect 5) 23) 23)
(eq sideffect 5)
))))
(do-test "test path not taken, was not taken"
(flet ((tee nil t) (nill nil nil))
(let ((sideffect nil))
(and
(eq (when (nill) (setq sideffect T)
nil) nil)
(eq sideffect nil)
(eq (when (nill) (setq sideffect 23)) nil)
(eq sideffect nil)
))))
STOP