sxml.ssax.test 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. ;;;; sxml.ssax.test -*- scheme -*-
  2. ;;;;
  3. ;;;; Copyright (C) 2010 Free Software Foundation, Inc.
  4. ;;;; Copyright (C) 2001,2002,2003,2004 Oleg Kiselyov <oleg at pobox dot com>
  5. ;;;;
  6. ;;;; This library is free software; you can redistribute it and/or
  7. ;;;; modify it under the terms of the GNU Lesser General Public
  8. ;;;; License as published by the Free Software Foundation; either
  9. ;;;; version 3 of the License, or (at your option) any later version.
  10. ;;;;
  11. ;;;; This library is distributed in the hope that it will be useful,
  12. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. ;;;; Lesser General Public License for more details.
  15. ;;;;
  16. ;;;; You should have received a copy of the GNU Lesser General Public
  17. ;;;; License along with this library; if not, write to the Free Software
  18. ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. ;;; Commentary:
  20. ;;
  21. ;; Unit tests for (sxml ssax). You can tweak this harness to get more
  22. ;; debugging information, but in the end I just wanted to keep Oleg's
  23. ;; tests in the file and see if we could work with them directly.
  24. ;;
  25. ;;; Code:
  26. (define-module (test-suite sxml-ssax)
  27. #:use-module (sxml ssax input-parse)
  28. #:use-module (test-suite lib)
  29. #:use-module (srfi srfi-1)
  30. #:use-module (srfi srfi-13)
  31. #:use-module (sxml ssax)
  32. #:use-module (ice-9 pretty-print))
  33. (define pp pretty-print)
  34. (define-macro (import module . symbols)
  35. `(begin
  36. ,@(map (lambda (sym)
  37. `(module-define! (current-module) ',sym (module-ref (resolve-module ',module) ',sym)))
  38. symbols)))
  39. ;; This list was arrived at over time. See the problem is that SSAX's
  40. ;; test cases are inline with its text, and written in the private
  41. ;; language of SSAX. That is to say, they use procedures that (sxml
  42. ;; ssax) doesn't export. So here we test that the procedures from (sxml
  43. ;; ssax) actually work, but in order to do so we have to pull in private
  44. ;; definitions. It's not the greatest solution, but it's what we got.
  45. (import (sxml ssax)
  46. ssax:read-NCName
  47. ssax:read-QName
  48. ssax:largest-unres-name
  49. ssax:Prefix-XML
  50. ssax:resolve-name
  51. ssax:scan-Misc
  52. ssax:assert-token
  53. ssax:handle-parsed-entity
  54. ssax:warn
  55. ssax:skip-pi
  56. ssax:S-chars
  57. ssax:skip-S
  58. ssax:ncname-starting-char?
  59. ssax:define-labeled-arg-macro
  60. let*-values
  61. ssax:make-parser/positional-args
  62. when
  63. make-xml-token
  64. nl
  65. ;unesc-string
  66. parser-error
  67. ascii->char
  68. char->ascii
  69. char-newline
  70. char-return
  71. char-tab
  72. name-compare)
  73. (define (cout . args)
  74. "Similar to @code{cout << arguments << args}, where @var{argument} can
  75. be any Scheme object. If it's a procedure (e.g. @code{newline}), it's
  76. called without args rather than printed."
  77. (for-each (lambda (x)
  78. (if (procedure? x) (x) (display x)))
  79. args))
  80. (define (cerr . args)
  81. "Similar to @code{cerr << arguments << args}, where @var{argument} can
  82. be any Scheme object. If it's a procedure (e.g. @code{newline}), it's
  83. called without args rather than printed."
  84. (format (current-ssax-error-port)
  85. ";;; SSAX warning: ~a\n" args))
  86. (define (list-intersperse src-l elem)
  87. (if (null? src-l) src-l
  88. (let loop ((l (cdr src-l)) (dest (cons (car src-l) '())))
  89. (if (null? l) (reverse dest)
  90. (loop (cdr l) (cons (car l) (cons elem dest)))))))
  91. (define-syntax failed?
  92. (syntax-rules ()
  93. ((_ e ...)
  94. (not (false-if-exception (begin e ... #t))))))
  95. (define *saved-port* (current-output-port))
  96. (define-syntax assert
  97. (syntax-rules ()
  98. ((assert expr ...)
  99. (with-output-to-port *saved-port*
  100. (lambda ()
  101. (pass-if '(and expr ...)
  102. (let* ((out (open-output-string))
  103. (res (with-output-to-port out
  104. (lambda ()
  105. (with-ssax-error-to-port (current-output-port)
  106. (lambda ()
  107. (and expr ...)))))))
  108. ;; (get-output-string out)
  109. res)))))))
  110. (define (load-tests file)
  111. (with-input-from-file (%search-load-path file)
  112. (lambda ()
  113. (let loop ((sexp (read)))
  114. (cond
  115. ((eof-object? sexp))
  116. ((and (pair? sexp) (pair? (cdr sexp))
  117. (eq? (cadr sexp) 'run-test))
  118. (primitive-eval sexp)
  119. (loop (read)))
  120. ((and (pair? sexp) (eq? (car sexp) 'run-test))
  121. (primitive-eval sexp)
  122. (loop (read)))
  123. (else
  124. (loop (read))))))))
  125. (with-output-to-string
  126. (lambda ()
  127. (load-tests "sxml/upstream/SSAX.scm")))