test-xml-struct-dom.lisp
 1 ;;;; -*- mode: lisp -*-
2 ;;;;
3 ;;;; $Id: test-xml-struct-dom.lisp,v 1.2 2005/08/29 15:01:49 scaekenberghe Exp $
4 ;;;;
5 ;;;; Unit and functional tests for xml-struct-dom.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 (xml-equal (with-input-from-string (stream " <foo/>")
17 (parse-xml stream :output-type :xml-struct))
18 (make-xml-element :name :|foo|)))
19
20 (assert
21 (xml-equal (parse-xml-string "<tag1><tag2 att1='one'/>this is some text</tag1>"
22 :output-type :xml-struct)
23 (make-xml-element :name :|tag1|
24 :children (list (make-xml-element :name :|tag2|
25 :attributes '((:|att1| . "one")))
26 "this is some text"))))
27
28 (assert
29 (xml-equal (parse-xml-string "<tag>&lt;foo&gt;</tag>"
30 :output-type :xml-struct)
31 (make-xml-element :name :|tag|
32 :children (list "<foo>"))))
33
34 (assert
35 (xml-equal (parse-xml-string
36 "<P><INDEX ITEM='one'/> This is some <B>bold</B> text, with a leading &amp; trailing space </P>"
37 :output-type :xml-struct)
38 (make-xml-element :name :p
39 :children (list (make-xml-element :name :index
40 :attributes '((:item . "one")))
41 " This is some "
42 (make-xml-element :name :b
43 :children (list "bold"))
44 " text, with a leading & trailing space "))))
45
46 (assert
47 (xml-element-p (parse-xml-file (merge-pathnames "xhtml-page.xml" *load-pathname*)
48 :output-type :xml-struct)))
49
50 (assert
51 (xml-element-p (parse-xml-file (merge-pathnames "ant-build-file.xml" *load-pathname*)
52 :output-type :xml-struct)))
53
54 (assert
55 (xml-element-p (parse-xml-file (merge-pathnames "plist.xml" *load-pathname*)
56 :output-type :xml-struct)))
57
58 (assert
59 (string-equal (print-xml-string (make-xml-element :name "foo")
60 :input-type :xml-struct)
61 "<foo/>"))
62
63 (assert
64 (string-equal (print-xml-string (make-xml-element :name "foo" :attributes '((:|bar| . "1")))
65 :input-type :xml-struct)
66 "<foo bar=\"1\"/>"))
67
68 (assert
69 (string-equal (print-xml-string (make-xml-element :name "foo" :children (list "some text"))
70 :input-type :xml-struct)
71 "<foo>some text</foo>"))
72
73 (assert
74 (string-equal (print-xml-string (make-xml-element :name "foo" :children (list (make-xml-element :name "bar")))
75 :input-type :xml-struct)
76 "<foo><bar/></foo>"))
77
78 ;;;; eof