;;;; srfi-89.test --- Test suite for SRFI-89              -*- Scheme -*-
;;;; Julian Graham <julian.graham@aya.yale.edu>
;;;;
;;;; 	Copyright (C) 2008 Free Software Foundation, Inc.
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2, or (at your option)
;;;; any later version.
;;;;
;;;; This program 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 General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this software; see the file COPYING.  If not, write to
;;;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;;;; Boston, MA 02110-1301 USA

(define-module (test-srfi-89)
  :use-module (test-suite lib)
  :use-module (srfi srfi-89))


;; These are all taken from SRFI-89.

(define* (f a (b #f)) (list a b))
(define* (g a (b a) (key: k (* a b))) (list a b k))
(define* (h1 a (key: k #f) . r) (list a k r))
(define* (h2 (key: k #f) a . r) (list a k r))

(with-test-prefix "srfi-89"

  (pass-if "default-values-1" (equal? (f 1) '(1 #f)))
  (pass-if "default-values-2" (equal? (f 1 2) '(1 2)))
  (pass-if "argument-count-1" (not (false-if-exception (f 1 2 3))))

  (pass-if "default-values-3" (equal? (g 3) '(3 3 9)))
  (pass-if "default-values-4" (equal? (g 3 4) '(3 4 12)))
  (pass-if "malformed-keyword" (not (false-if-exception (g 3 4 key:))))
  (pass-if "keyword-1" (equal? (g 3 4 key: 5) '(3 4 5)))
  (pass-if "undefined-keyword" (not (false-if-exception (g 3 4 zoo: 5))))
  (pass-if "duplicate-keyword" 
    (not (false-if-exception (g 3 4 key: 5 key: 6))))

  (pass-if "keywords-and-rest-1" (equal? (h1 7) '(7 #f ())))
  (pass-if "keywords-and-rest-2" (equal? (h1 7 8 9 10) '(7 #f (8 9 10))))
  (pass-if "keywords-and-rest-3" (equal? (h1 7 key: 8 9 10) '(7 8 (9 10))))
  (pass-if "undefined-keyword-2" 
    (not (false-if-exception (h1 7 key: 8 zoo: 9))))
  
  (pass-if "required-positionals-1" (equal? (h2 7) '(7 #f ())))
  (pass-if "required-positionals-2" (equal? (h2 7 8 9 10) '(7 #f (8 9 10))))
  (pass-if "required-positionals-3" (equal? (h2 key: 8 9 10) '(9 8 (10))))
  (pass-if "undefined-keyword-3" 
    (not (false-if-exception (h2 key: 8 zoo: 9) ))))

;;; Local Variables:
;;; coding: latin-1
;;; End:
