xxexpr-test.ss
;;;
;;; Time-stamp: <05/11/13 21:26:05 noel>
;;;
;;; 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 xxexpr-test mzscheme
  
  (require (planet "test.ss" ("schematics" "schemeunit.plt" 1 1)))
  (require "xxexpr.ss")
  
  (provide xxexpr-tests)
  
  (define xxexpr-tests
    (make-test-suite
     "All tests for xxexpr"

     (make-test-case
      "xml-empty-tags-mode toggles empty tag printing"
      (parameterize
        ((xml-empty-tags-mode #t))
        (assert string=?
                (xxexpr->string '((p)))
                "<p/>"))
      (parameterize
        ((xml-empty-tags-mode #f))
        (assert string=?
                (xxexpr->string '((p)))
                "<p></p>")))

     (make-test-case
      "xml-double-quotes-mode toggles quotes in attribute printing"
      (parameterize
        ((xml-double-quotes-mode #t))
        (assert string=?
                (xxexpr->string '((p (@ (class "foo")) "Text")))
                "<p class=\"foo\">Text</p>"))
      (parameterize
        ((xml-double-quotes-mode #f))
        (assert string=?
                (xxexpr->string '((p (@ (class "foo")) "Text")))
                "<p class='foo'>Text</p>")))

     (make-test-case
      "xxexpr->string/notags"
      (assert string=?
              (xxexpr->string/notags '((p (@ (class "foo")) "Text")))
              "Text"))

     (make-test-case
      "write-xxexpr returns #t"
      (assert-true (write-xxexpr '((p (@ (class "foo")) "Text")))))

     (make-test-case
      "write-xxexpr outputs SXML to given port"
      (let ((port (open-output-string)))
        (write-xxexpr '((p (@ (class "foo")) "Text")) port)
        (assert string=?
                "<p class='foo'>Text</p>"
                (get-output-string port))))

     (make-test-case
      "write-xxexpr/notags outputs SXML to given port, skipping tags"
      (let ((port (open-output-string)))
        (assert-true (write-xxexpr/notags
                      '((p (@ (class "foo")) "Text"))
                      port))
        (assert string=?
                "Text"
                (get-output-string port))))
     ))
  )