diff options
author | Chong Yidong <cyd@gnu.org> | 2012-07-01 15:17:05 +0800 |
---|---|---|
committer | Chong Yidong <cyd@gnu.org> | 2012-07-01 15:17:05 +0800 |
commit | fbf2e7ad3bd676083dae339aba16bf812dfc51a3 (patch) | |
tree | 1ee6f4f014de8f97f8a711f58d3323aebbf8ce41 /test/automated/xml-parse-tests.el | |
parent | b95b72547b5a2c5e4e294e9e703d3a85928f58f4 (diff) | |
download | emacs-fbf2e7ad3bd676083dae339aba16bf812dfc51a3.tar.gz |
Improve xml parameter entity parsing, and add a new ERT test.
* test/automated/xml-parse-tests.el: New file.
* lisp/xml.el (xml--parse-buffer): New function. Move most of
xml-parse-region here.
(xml-parse-region): Copy region into a temporary buffer, since
parameter entity substitution requires changing buffer contents.
Use xml--parse-buffer.
(xml-parse-file): Use xml--parse-buffer.
(xml-parse-dtd): Make parameter entity substitution work right.
Diffstat (limited to 'test/automated/xml-parse-tests.el')
-rw-r--r-- | test/automated/xml-parse-tests.el | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/test/automated/xml-parse-tests.el b/test/automated/xml-parse-tests.el new file mode 100644 index 00000000000..8e8ef291bdc --- /dev/null +++ b/test/automated/xml-parse-tests.el @@ -0,0 +1,57 @@ +;;; xml-parse-tests.el --- Test suite for XML parsing. + +;; Copyright (C) 2012 Free Software Foundation, Inc. + +;; Author: Chong Yidong <cyd@stupidchicken.com> +;; Keywords: internal +;; Human-Keywords: internal + +;; This file is part of GNU Emacs. + +;; GNU Emacs is free software: you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation, either version 3 of the License, or +;; (at your option) any later version. + +;; GNU Emacs is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. + +;;; Commentary: + +;; Type M-x test-xml-parse RET to generate the test buffer. + +;;; Code: + +(require 'xml) + +(defvar xml-parse-tests--data + '(;; General entity substitution + ("<?xml version=\"1.0\"?><!DOCTYPE foo SYSTEM \"bar.dtd\" [<!ENTITY ent \"AbC\">]><foo a=\"b\"><bar>&ent;;</bar></foo>" . + ((foo ((a . "b")) (bar nil "AbC;")))) + ;; Parameter entity substitution + ("<?xml version=\"1.0\"?><!DOCTYPE foo SYSTEM \"bar.dtd\" [<!ENTITY % pent \"AbC\"><!ENTITY ent \"%pent;\">]><foo a=\"b\"><bar>&ent;;</bar></foo>" . + ((foo ((a . "b")) (bar nil "AbC;")))) + ;; Tricky parameter entity substitution (like XML spec Appendix D) + ("<?xml version='1.0'?><!DOCTYPE foo [ <!ENTITY % xx '%zz;'><!ENTITY % zz '<!ENTITY ent \"b\" >' > %xx; ]><foo>A&ent;C</foo>" . + ((foo nil "AbC")))) + "Alist of XML strings and their expected parse trees.") + +(ert-deftest xml-parse-tests () + "Test XML parsing." + (with-temp-buffer + (dolist (test xml-parse-tests--data) + (erase-buffer) + (insert (car test)) + (should (equal (cdr test) + (xml-parse-region (point-min) (point-max))))))) + +;; Local Variables: +;; no-byte-compile: t +;; End: + +;;; xml-parse-tests.el ends here. |