1 ;;;; sxml.simple.test --- (sxml simple) -*- mode: scheme; coding: utf-8; -*-
3 ;;;; Copyright (C) 2010, 2013 Free Software Foundation, Inc.
5 ;;;; This library is free software; you can redistribute it and/or
6 ;;;; modify it under the terms of the GNU Lesser General Public
7 ;;;; License as published by the Free Software Foundation; either
8 ;;;; version 3 of the License, or (at your option) any later version.
10 ;;;; This library is distributed in the hope that it will be useful,
11 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 ;;;; Lesser General Public License for more details.
15 ;;;; You should have received a copy of the GNU Lesser General Public
16 ;;;; License along with this library; if not, write to the Free Software
17 ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 (define-module (test-sxml-simple)
20 #:use-module (test-suite lib)
21 #:use-module (sxml simple))
23 (define parser-error '(parser-error . ""))
26 ;; An XML sample without any space in between tags, to make it easier.
27 (string-append "<?xml version='1.0' encoding='utf-8'?>"
28 "<foo chbouib=\"yes\">"
36 (with-test-prefix "simple"
39 (equal? (xml->sxml (open-input-string %xml-sample))
41 (*PI* xml "version='1.0' encoding='utf-8'")
42 (foo (@ (chbouib "yes"))
44 (baz (smurf (@ (one "1"))))))))
46 (pass-if "xml->sxml->xml->sxml"
47 ;; Regression test for bug #29260.
48 (equal? (xml->sxml (open-input-string %xml-sample))
51 (with-output-to-string
54 (xml->sxml (open-input-string %xml-sample))))))))))
56 (with-test-prefix "namespaces"
58 (xml->sxml "<foo xmlns=\"http://example.org/ns1\">text</foo>")
59 '(*TOP* (http://example.org/ns1:foo "text")))
62 (xml->sxml "<foo xmlns=\"http://example.org/ns1\">text</foo>"
63 #:namespaces '((ns1 . "http://example.org/ns1")))
64 '(*TOP* (ns1:foo "text")))
67 (xml->sxml "<foo xmlns:bar=\"http://example.org/ns2\"><bar:baz/></foo>"
68 #:namespaces '((ns2 . "http://example.org/ns2")))
69 '(*TOP* (foo (ns2:baz))))
72 (xml->sxml "<foo><ns2:baz/></foo>"
73 #:namespaces '((ns2 . "http://example.org/ns2")))
74 '(*TOP* (foo (ns2:baz))))
76 (pass-if-exception "namespace undeclared" parser-error
77 (xml->sxml "<foo><ns2:baz/></foo>"
78 #:namespaces '((ns2 . "http://example.org/ns2"))
79 #:declare-namespaces? #f)))
81 (with-test-prefix "whitespace"
83 (xml->sxml "<foo>\n<bar> Alfie the parrot! </bar>\n</foo>")
84 '(*TOP* (foo "\n" (bar " Alfie the parrot! ") "\n")))
87 (xml->sxml "<foo>\n<bar> Alfie the parrot! </bar>\n</foo>"
88 #:trim-whitespace? #t)
89 '(*TOP* (foo (bar " Alfie the parrot! ")))))
91 (with-test-prefix "parsed entities"
94 (xml->sxml "<foo>&</foo>"))
96 (pass-if-exception "nbsp undefined" parser-error
97 (xml->sxml "<foo> </foo>"))
100 '(*TOP* (foo "\xA0"))
101 (xml->sxml "<foo> </foo>"
102 #:entities '((nbsp . "\xA0"))))
105 '(*TOP* (foo "\xA0"))
106 (xml->sxml "<foo> </foo>"))
110 (xml->sxml "<foo> &foo;</foo>"
111 #:default-entity-handler
116 (set! ents (cons name ents))
118 '(*TOP* (foo "\xa0 qux")))
124 (with-test-prefix "doctype handlers"
125 (define (handle-foo docname systemid internal-subset)
128 (values #:entities '((greets . "<i>Hello, world!</i>"))))
133 (xml->sxml "<!DOCTYPE foo><p>&greets;</p>"
134 #:doctype-handler handle-foo)
135 '(*TOP* (p (i "Hello, world!")))))