Extract jabber-xml-parse-next-stanza, and test it
Move the functionality of reading the next complete stanza into a separate function, and add some test cases for it. I'd like to get rid of jabber-xml-skip-tag-forward at some point, so a good first step towards that should be moving calls to it into a function that's easy to test in isolation.
This commit is contained in:
parent
d4d7782741
commit
98dc8e429b
|
@ -899,10 +899,7 @@ DATA is any sexp."
|
||||||
(while (search-forward-regexp " \\w+=''" nil t)
|
(while (search-forward-regexp " \\w+=''" nil t)
|
||||||
(replace-match "")))
|
(replace-match "")))
|
||||||
|
|
||||||
(setq xml-data (and (catch 'unfinished
|
(setq xml-data (jabber-xml-parse-next-stanza))
|
||||||
(jabber-xml-skip-tag-forward)
|
|
||||||
(> (point) (point-min)))
|
|
||||||
(xml-parse-region (point-min) (point))))
|
|
||||||
|
|
||||||
while xml-data
|
while xml-data
|
||||||
do
|
do
|
||||||
|
|
|
@ -133,6 +133,17 @@ enough for us."
|
||||||
(t
|
(t
|
||||||
(throw 'unfinished nil))))
|
(throw 'unfinished nil))))
|
||||||
|
|
||||||
|
(defun jabber-xml-parse-next-stanza ()
|
||||||
|
"Parse the first XML stanza in the current buffer.
|
||||||
|
Parse and return the first complete XML element in the buffer,
|
||||||
|
leaving point at the end of it. If there is no complete XML
|
||||||
|
element, return `nil'."
|
||||||
|
(and (catch 'unfinished
|
||||||
|
(goto-char (point-min))
|
||||||
|
(jabber-xml-skip-tag-forward)
|
||||||
|
(> (point) (point-min)))
|
||||||
|
(xml-parse-region (point-min) (point))))
|
||||||
|
|
||||||
(defsubst jabber-xml-node-name (node)
|
(defsubst jabber-xml-node-name (node)
|
||||||
"Return the tag associated with NODE.
|
"Return the tag associated with NODE.
|
||||||
The tag is a lower-case symbol."
|
The tag is a lower-case symbol."
|
||||||
|
|
|
@ -2,5 +2,5 @@
|
||||||
# check" or "make distcheck" to work with earlier versions.
|
# check" or "make distcheck" to work with earlier versions.
|
||||||
LOG_COMPILER = env top_builddir=$(top_builddir) $(EMACS) -batch -L $(top_builddir) -L $(top_srcdir) -L $(srcdir) -l
|
LOG_COMPILER = env top_builddir=$(top_builddir) $(EMACS) -batch -L $(top_builddir) -L $(top_srcdir) -L $(srcdir) -l
|
||||||
TESTS = load-all.el skip-tag-forward.el history.el jabberd.el nick-change-fail.el
|
TESTS = load-all.el skip-tag-forward.el history.el jabberd.el nick-change-fail.el
|
||||||
TESTS += caps-hash.el
|
TESTS += caps-hash.el parse-next-stanza.el
|
||||||
dist_noinst_DATA = $(TESTS)
|
dist_noinst_DATA = $(TESTS)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
;; Tests for jabber-xml-parse-next-stanza
|
||||||
|
|
||||||
|
(require 'jabber-xml)
|
||||||
|
|
||||||
|
(defun parse-it (text)
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert text)
|
||||||
|
(jabber-xml-parse-next-stanza)))
|
||||||
|
|
||||||
|
(unless (equal
|
||||||
|
(parse-it "<presence from='foo@example.com/resource' type='unavailable' to='bar@example.com'/>")
|
||||||
|
'((presence ((from . "foo@example.com/resource") (type . "unavailable") (to . "bar@example.com")))))
|
||||||
|
(error "Testcase 1 failed"))
|
||||||
|
|
||||||
|
(unless (equal
|
||||||
|
(parse-it "<presence from='foo@example.com/resource' ")
|
||||||
|
nil)
|
||||||
|
(error "Testcase 2 failed"))
|
Loading…
Reference in New Issue