Minilisp.pm/t/dotimes.t

31 lines
792 B
Perl
Raw Normal View History

2021-04-10 01:16:03 +02:00
(plan 5)
(expect "dotimes - executes body n times"
(let ((pings 0))
(dotimes (i 5)
(set pings (+ 1 pings)))
(equal pings 5)))
(expect "dotimes - evaluates result form"
(equal 6
(dotimes (i 6 i))))
(expect "dotimes - implicit block nil"
(equal 'ok
(dotimes (i 6)
(return 'ok))))
(expect "dotimes - body is not evaluated if count is 0"
(equal 'ok
(catch 'test
(dotimes (i 0)
(throw 'test 'fail))
'ok)))
(expect "dotimes - body is not evaluated if count is negative"
(equal 'ok
(catch 'test
(dotimes (i -3)
(throw 'test 'fail))
'ok)))