diff options
| author | Chong Yidong | 2012-07-01 15:17:05 +0800 |
|---|---|---|
| committer | Chong Yidong | 2012-07-01 15:17:05 +0800 |
| commit | fbf2e7ad3bd676083dae339aba16bf812dfc51a3 (patch) | |
| tree | 1ee6f4f014de8f97f8a711f58d3323aebbf8ce41 /test | |
| parent | b95b72547b5a2c5e4e294e9e703d3a85928f58f4 (diff) | |
| download | emacs-fbf2e7ad3bd676083dae339aba16bf812dfc51a3.tar.gz emacs-fbf2e7ad3bd676083dae339aba16bf812dfc51a3.zip | |
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')
| -rw-r--r-- | test/ChangeLog | 4 | ||||
| -rw-r--r-- | test/automated/xml-parse-tests.el | 57 |
2 files changed, 61 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 45fc70e0440..d9d9bc5a9fa 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,7 @@ | |||
| 1 | 2012-07-01 Chong Yidong <cyd@gnu.org> | ||
| 2 | |||
| 3 | * automated/xml-parse-tests.el: New file. | ||
| 4 | |||
| 1 | 2012-06-27 Stefan Monnier <monnier@iro.umontreal.ca> | 5 | 2012-06-27 Stefan Monnier <monnier@iro.umontreal.ca> |
| 2 | 6 | ||
| 3 | * automated/ert-x-tests.el (ert-test-run-tests-interactively-2): | 7 | * automated/ert-x-tests.el (ert-test-run-tests-interactively-2): |
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 @@ | |||
| 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 '%zz;'><!ENTITY % zz '<!ENTITY ent \"b\" >' > %xx; ]><foo>A&ent;C</foo>" . | ||
| 41 | ((foo nil "AbC")))) | ||
| 42 | "Alist of XML strings and their expected parse trees.") | ||
| 43 | |||
| 44 | (ert-deftest xml-parse-tests () | ||
| 45 | "Test XML parsing." | ||
| 46 | (with-temp-buffer | ||
| 47 | (dolist (test xml-parse-tests--data) | ||
| 48 | (erase-buffer) | ||
| 49 | (insert (car test)) | ||
| 50 | (should (equal (cdr test) | ||
| 51 | (xml-parse-region (point-min) (point-max))))))) | ||
| 52 | |||
| 53 | ;; Local Variables: | ||
| 54 | ;; no-byte-compile: t | ||
| 55 | ;; End: | ||
| 56 | |||
| 57 | ;;; xml-parse-tests.el ends here. | ||