This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "emacs-jabber".
The branch, master has been updated
via 98dc8e429ba6f79065f1c9fc3878d92314d4b510 (commit)
from d4d77827418c9b48c80c781a6f6f0d784977bfa6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 98dc8e429ba6f79065f1c9fc3878d92314d4b510
Author: Magnus Henoch <mag...@gm...>
Date: Sun Jan 24 13:52:22 2016 +0000
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.
diff --git a/jabber-core.el b/jabber-core.el
index de05a34..9258647 100644
--- a/jabber-core.el
+++ b/jabber-core.el
@@ -899,10 +899,7 @@ DATA is any sexp."
(while (search-forward-regexp " \\w+=''" nil t)
(replace-match "")))
- (setq xml-data (and (catch 'unfinished
- (jabber-xml-skip-tag-forward)
- (> (point) (point-min)))
- (xml-parse-region (point-min) (point))))
+ (setq xml-data (jabber-xml-parse-next-stanza))
while xml-data
do
diff --git a/jabber-xml.el b/jabber-xml.el
index e19a247..520f033 100644
--- a/jabber-xml.el
+++ b/jabber-xml.el
@@ -133,6 +133,17 @@ enough for us."
(t
(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)
"Return the tag associated with NODE.
The tag is a lower-case symbol."
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8575ddb..e171536 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -2,5 +2,5 @@
# 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
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)
diff --git a/tests/parse-next-stanza.el b/tests/parse-next-stanza.el
new file mode 100644
index 0000000..d4f57b0
--- /dev/null
+++ b/tests/parse-next-stanza.el
@@ -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='fo...@ex.../resource' type='unavailable' to='ba...@ex...'/>")
+ '((presence ((from . "fo...@ex.../resource") (type . "unavailable") (to . "ba...@ex...")))))
+ (error "Testcase 1 failed"))
+
+(unless (equal
+ (parse-it "<presence from='fo...@ex.../resource' ")
+ nil)
+ (error "Testcase 2 failed"))
-----------------------------------------------------------------------
Summary of changes:
jabber-core.el | 5 +----
jabber-xml.el | 11 +++++++++++
tests/Makefile.am | 2 +-
tests/parse-next-stanza.el | 18 ++++++++++++++++++
4 files changed, 31 insertions(+), 5 deletions(-)
create mode 100644 tests/parse-next-stanza.el
hooks/post-receive
--
emacs-jabber
|