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

145 lines
3.8 KiB
Plaintext

;; Function To Be Tested: unless
;;
;; 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 10,1986 HC3/ documented, and added
;; several more test cases
;; October 24,1986 HC3/ broke up into several tests
;;
;; Filed As: {ERIS}<LISPCORE>CML>TEST>7-6-UNLESS.TEST
;;
;;
;; Syntax: (unless test {form}*)
;;
;; (unless p a b c) is exactly equal to:
;; (cond ((not p) a b c))
;; (if p nil (progn a b c))
;; (when (not p) a b c)
;;
;;
;; Function Description:
;; First TEST is evaluated. If the result is not nil (T),
;; 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 simple cases"
(and
; Does when evaluate and return the appropriate things?
; Check just boolean values
(unless nil T)
(unless nil nil nil T)
(eq (unless T T) nil)
(eq (unless T nil nil T) nil)
))
(do-test "test work generating test"
(and
(unless (> 0 95) T)
(unless (> 0 95) nil nil T)
(eq (unless (> 0 13) T) T)
(eq (unless (> 0 13) T nil nil) nil)
(eq (unless (> 10 6) T T T) nil)
))
(do-test "test local functions for test & returning symbols"
; Define two functions, tee returning T,
; and nill returning nil
(flet ((tee nil t) (nill nil nil))
(and
; check symbols
(eq (unless (nill) 'foo) 'foo)
(eq (unless (tee) 'foo) nil)
(eq (unless (nill) 'bar 'bar 'foo) 'foo)
(eq (unless (tee) 'bar 'bar 'foo) nil)
)))
(do-test "test returning numbers"
; Define two functions, tee returning T,
; and nill returning nil
(flet ((tee nil t) (nill nil nil))
(and
(eq (unless (nill) (* 3 5)) 15)
(eq (unless (nill) (* 3 5) (* 5 7)) 35)
(eq (unless (nill) (* 3 5) (* 5 7) (* 9 4)) 36)
(eq (unless (tee) (* 3 5)) nil)
(eq (unless (tee) (* 3 5) (* 5 7) (* 9 4)) nil)
)))
(do-test "test using numbers and symbols for true"
(and
(eq (unless 5 T) nil)
(eq (unless 5 T T) nil)
(eq (unless 'hi T) nil)
(eq (unless 'hi T nil T) nil)
))
(do-test "test passing back multiple values"
(flet ((nill () nil))
(and
(equal (multiple-value-list
(unless (nill)
(values 'foo 'bar)))
'(foo bar))
(equal (multiple-value-list
(unless (nill)
56
'Hello
(values 'bar 'foo)))
'(bar foo))
)))
(do-test "test values set in UNLESS, still set outside"
(flet ((nill () nil))
(let ((sideffect nil))
(and
(eq (unless (nill) (setq sideffect T)) T)
(eq sideffect T)
(eq (unless (nill) (setq sideffect 'foo)
'bar) 'bar)
(eq sideffect 'foo)
(eq (unless (nill) (setq sideffect 5) 23) 23)
(eq sideffect 5)
))))
(do-test "test path not taken was not taken"
(flet ((tee nil t))
(let ((sideffect nil))
(and
(eq (unless (tee) (setq sideffect T)
nil) nil)
(eq sideffect nil)
(eq (unless (tee) (setq sideffect 23)) nil)
(eq sideffect nil)
))))
STOP