all-macro-tests.ss
;;;
;;; Time-stamp: <05/10/28 10:57:03 nhw>
;;;
;;; Copyright (C) 2005 by Noel Welsh.
;;;

;;; This library is free software; you can redistribute it
;;; and/or modify it under the terms of the GNU Lesser
;;; General Public License as published by the Free Software
;;; Foundation; either version 2.1 of the License, or (at
;;; your option) any later version.

;;; This library is distributed in the hope that it will be
;;; useful, but WITHOUT ANY WARRANTY; without even the
;;; implied warranty of MERCHANTABILITY or FITNESS FOR A
;;; PARTICULAR PURPOSE.  See the GNU Lesser General Public
;;; License for more details.

;;; You should have received a copy of the GNU Lesser
;;; General Public License along with this library; if not,
;;; write to the Free Software Foundation, Inc., 59 Temple
;;; Place, Suite 330, Boston, MA 02111-1307 USA

;;; Author: Noel Welsh <noelwelsh@yahoo.com>
;;
;;
;; Commentary:

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

     
     ))
  )