* xml.el (xml-parse-dtd): Use proper regexps for ELEMENT declarations.
[bpt/emacs.git] / test / automated / xml-parse-tests.el
1 ;;; xml-parse-tests.el --- Test suite for XML parsing.
2
3 ;; Copyright (C) 2012 Free Software Foundation, Inc.
4
5 ;; Author: Chong Yidong <cyd@stupidchicken.com>
6 ;; Keywords: internal
7 ;; Human-Keywords: internal
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
23
24 ;;; Commentary:
25
26 ;; Type M-x test-xml-parse RET to generate the test buffer.
27
28 ;;; Code:
29
30 (require 'xml)
31
32 (defvar xml-parse-tests--data
33 '(;; General entity substitution
34 ("<?xml version=\"1.0\"?><!DOCTYPE foo SYSTEM \"bar.dtd\" [<!ENTITY ent \"AbC\">]><foo a=\"b\"><bar>&ent;;</bar></foo>" .
35 ((foo ((a . "b")) (bar nil "AbC;"))))
36 ;; Parameter entity substitution
37 ("<?xml version=\"1.0\"?><!DOCTYPE foo SYSTEM \"bar.dtd\" [<!ENTITY % pent \"AbC\"><!ENTITY ent \"%pent;\">]><foo a=\"b\"><bar>&ent;;</bar></foo>" .
38 ((foo ((a . "b")) (bar nil "AbC;"))))
39 ;; Tricky parameter entity substitution (like XML spec Appendix D)
40 ("<?xml version='1.0'?><!DOCTYPE foo [ <!ENTITY % xx '&#37;zz;'><!ENTITY % zz '&#60;!ENTITY ent \"b\" >' > %xx; ]><foo>A&ent;C</foo>" .
41 ((foo nil "AbC")))
42 ;; Bug#7172
43 ("<?xml version=\"1.0\"?><!DOCTYPE foo [ <!ELEMENT EXAM_PLE EMPTY> ]><foo></foo>" .
44 ((foo nil))))
45 "Alist of XML strings and their expected parse trees.")
46
47 (ert-deftest xml-parse-tests ()
48 "Test XML parsing."
49 (with-temp-buffer
50 (dolist (test xml-parse-tests--data)
51 (erase-buffer)
52 (insert (car test))
53 (should (equal (cdr test)
54 (xml-parse-region (point-min) (point-max)))))))
55
56 ;; Local Variables:
57 ;; no-byte-compile: t
58 ;; End:
59
60 ;;; xml-parse-tests.el ends here.