(module all-macro-tests mzscheme
(require (planet "test.ss" ("schematics" "schemeunit.plt" 1 1)))
(require "macro.ss")
(provide all-macro-tests)
(define all-macro-tests
(make-test-suite
"all-macro-tests"
(make-test-case
"aif works without predicate"
(aif the 'hello
(assert-eq? the 'hello)
(fail "Wrong arm called"))
(aif the #f
(fail "Wrong arm called")
(assert-false the)))
(make-test-case
"aif works with predicate"
(aif the number? 1
(assert = the 1)
(fail "Wrong arm called"))
(aif the number? 'foo
(fail "Wrong arm called")
(assert-eq? the 'foo)))
(make-test-case
"for! executes start expr once"
(let ((counter 0))
(for! (i (begin (set! counter (add1 counter)) 0) 3)
(void))
(assert = counter 1)))
(make-test-case
"for! executes stop expr once"
(let ((counter 0))
(for! (i 0 (begin (set! counter (add1 counter)) 3))
(void))
(assert = counter 1)))
(make-test-case
"for! executes body expressions correct number of times"
(let ((counter 0))
(for! (i 0 4)
(set! counter (add1 counter)))
(assert = counter 4)))
(make-test-case
"for executes the correct number of times"
(assert =
(for ((i 0 4) (count 0))
(add1 count))
4))
(make-test-case
"for handles multiple accumulators"
(let-values (((a b c)
(for ((i 0 4) (a -4) (b 0) (c 4))
(values (add1 a)
(add1 b)
(add1 c)))))
(assert = 0 a)
(assert = 4 b)
(assert = 8 c)))
))
)