Minilisp.pm/t/dolist.t

31 lines
1,010 B
Raku

(plan 5)
(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)))