test-xml.lisp
 1 ;;;; -*- mode: lisp -*-
2 ;;;;
3 ;;;; $Id: test-xml.lisp,v 1.3 2005/11/06 12:44:48 scaekenberghe Exp $
4 ;;;;
5 ;;;; Unit and functional tests for xml.lisp
6 ;;;;
7 ;;;; Copyright (C) 2002, 2004 Sven Van Caekenberghe, Beta Nine BVBA.
8 ;;;;
9 ;;;; You are granted the rights to distribute and use this software
10 ;;;; as governed by the terms of the Lisp Lesser General Public License
11 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
12
13 (in-package :s-xml)
14
15 (assert
16 (whitespace-char-p (character " ")))
17
18 (assert
19 (whitespace-char-p (character " ")))
20
21 (assert
22 (whitespace-char-p (code-char 10)))
23
24 (assert
25 (whitespace-char-p (code-char 13)))
26
27 (assert
28 (not (whitespace-char-p #\A)))
29
30 (assert
31 (char= (with-input-from-string (stream " ABC")
32 (skip-whitespace stream))
33 #\A))
34
35 (assert
36 (char= (with-input-from-string (stream "ABC")
37 (skip-whitespace stream))
38 #\A))
39
40 (assert
41 (string-equal (with-output-to-string (stream) (print-string-xml "<foo>" stream))
42 "&lt;foo&gt;"))
43
44 (assert
45 (string-equal (with-output-to-string (stream) (print-string-xml "' '" stream))
46 "' '"))
47
48 (assert
49 (let ((string (map 'string #'identity '(#\return #\tab #\newline))))
50 (string-equal (with-output-to-string (stream) (print-string-xml string stream))
51 string)))
52
53 (defun simple-echo-xml (in out)
54 (start-parse-xml
55 in
56 (make-instance 'xml-parser-state
57 :new-element-hook #'(lambda (name attributes seed)
58 (declare (ignore seed))
59 (format out "<~a~:{ ~a='~a'~}>"
60 name
61 (mapcar #'(lambda (p) (list (car p) (cdr p)))
62 (reverse attributes))))
63 :finish-element-hook #'(lambda (name attributes parent-seed seed)
64 (declare (ignore attributes parent-seed seed))
65 (format out "</~a>" name))
66 :text-hook #'(lambda (string seed)
67 (declare (ignore seed))
68 (princ string out)))))
69
70 (defun simple-echo-xml-string (string)
71 (with-input-from-string (in string)
72 (with-output-to-string (out)
73 (simple-echo-xml in out))))
74
75 (assert
76 (let ((xml "<FOO ATT1='1' ATT2='2'><B>Text</B><EMPTY></EMPTY>More text!<SUB><SUB></SUB></SUB></FOO>"))
77 (equal (simple-echo-xml-string xml)
78 xml)))
79
80 (assert
81 (let ((xml "<p> </p>"))
82 (equal (simple-echo-xml-string xml)
83 xml)))
84
85 ;;;; eof