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