44 lines
1.3 KiB
Raku
44 lines
1.3 KiB
Raku
(plan 6)
|
|
|
|
(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)))
|
|
|
|
(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)))
|