when, unless: check for wrongful evaluation

when and unless must not evaluate their bodies if the condition does not require it.
This commit is contained in:
madmaurice 2021-04-05 04:07:22 +02:00
parent 9c0db610bf
commit c954f0216f
2 changed files with 8 additions and 0 deletions

View file

@ -3,3 +3,7 @@
(expect "unless - false condition" (expect "unless - false condition"
(equal 'ok (unless nil 'ok))) (equal 'ok (unless nil 'ok)))
(let ((a 'ok))
(unless t (set a 'fail))
(expect "unless - does not evaluate on true" (equal a 'ok)))

View file

@ -3,3 +3,7 @@
(expect "when - false condition" (expect "when - false condition"
(null (when nil 'fail))) (null (when nil 'fail)))
(let ((a 'ok))
(when nil (set a 'fail))
(expect "when - does not evaluate on false" (equal a 'ok)))