2021-04-10 22:36:18 +02:00
|
|
|
(plan 6)
|
2021-04-10 02:19:09 +02:00
|
|
|
|
|
|
|
(expect "dolist - body is evaluated with every element"
|
|
|
|
(let ((lst (list 1 2 5 'cool 'list 'bro nil))
|
|
|
|
(lst-expected (list nil 'bro 'list 'cool 5 2 1))
|
|
|
|
(lst-actual (list)))
|
|
|
|
(dolist (it lst)
|
|
|
|
(set lst-actual (cons it lst-actual)))
|
|
|
|
(equal lst-expected lst-actual)))
|
|
|
|
|
|
|
|
(expect "dolist - body is not evaluated if list is empty"
|
|
|
|
(equal 'ok
|
|
|
|
(catch 'test
|
|
|
|
(dolist (e (list))
|
|
|
|
(throw 'test 'fail))
|
|
|
|
'ok)))
|
|
|
|
|
|
|
|
(expect "dolist - result form is evaluated"
|
|
|
|
(equal 'ok
|
|
|
|
(dolist (e (list 1) 'ok))))
|
|
|
|
|
|
|
|
(expect "dolist - returns nil if no result form"
|
|
|
|
(null (dolist (e (list 1)))))
|
|
|
|
|
|
|
|
(expect "dolist - var is bound to nil during result form"
|
|
|
|
(equal 'ok
|
|
|
|
(catch 'test
|
|
|
|
(dolist (e (list 'fail)
|
|
|
|
(unless (null e)
|
|
|
|
(throw 'test 'fail))))
|
|
|
|
'ok)))
|
2021-04-10 22:36:18 +02:00
|
|
|
|
|
|
|
(defun nop () nil)
|
|
|
|
|
|
|
|
(expect "dolist - implicit tagbody"
|
|
|
|
(equal 'ok
|
|
|
|
(catch 'test
|
|
|
|
(dolist (e (list 1) 'ok)
|
|
|
|
nil
|
|
|
|
(go end)
|
|
|
|
middle
|
|
|
|
(throw 'test 'fail)
|
|
|
|
end)
|
|
|
|
'ok)))
|