[Pkg-javascript-commits] [ltx] 50/469: test_jid, fix JID constructor arguments
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:00:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 0c6f0c1e583fc1df84ad7557fe1466c24dba8836
Author: Astro <astro at spaceboyz.net>
Date: Fri Aug 13 23:56:55 2010 +0200
test_jid, fix JID constructor arguments
---
lib/xmpp/jid.js | 5 +++--
test/test_jid.js | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/lib/xmpp/jid.js b/lib/xmpp/jid.js
index d2bcf95..0f0ff67 100644
--- a/lib/xmpp/jid.js
+++ b/lib/xmpp/jid.js
@@ -1,11 +1,12 @@
function JID(a, b, c) {
if (a && b == null && c == null) {
this.parseJID(a);
- } else if (a && b) {
+ } else if (b) {
this.user = a;
this.domain = b;
this.resource = c;
- }
+ } else
+ throw 'Argument error';
}
JID.prototype.parseJID = function(s) {
diff --git a/test/test_jid.js b/test/test_jid.js
new file mode 100644
index 0000000..49801c4
--- /dev/null
+++ b/test/test_jid.js
@@ -0,0 +1,62 @@
+var vows = require('vows'),
+assert = require('assert'),
+xmpp = require('./../lib/xmpp');
+
+// Create a Test Suite
+vows.describe('JID').addBatch({
+
+ 'parsing': {
+ 'parse a "domain" JID':
+ function() {
+ var j = new xmpp.JID('d');
+ assert.equal(j.user, null);
+ assert.equal(j.domain, 'd');
+ assert.equal(j.resource, null);
+ },
+ 'parse a "user at domain" JID':
+ function() {
+ var j = new xmpp.JID('u at d');
+ assert.equal(j.user, 'u');
+ assert.equal(j.domain, 'd');
+ assert.equal(j.resource, null);
+ },
+ 'parse a "domain/resource" JID':
+ function() {
+ var j = new xmpp.JID('d/r');
+ assert.equal(j.user, null);
+ assert.equal(j.domain, 'd');
+ assert.equal(j.resource, 'r');
+ },
+ 'parse a "user at domain/resource" JID':
+ function() {
+ var j = new xmpp.JID('u at d/r');
+ assert.equal(j.user, 'u');
+ assert.equal(j.domain, 'd');
+ assert.equal(j.resource, 'r');
+ }
+ },
+
+ 'serialization': {
+ 'serialize a "domain" JID':
+ function() {
+ var j = new xmpp.JID(null, 'd');
+ assert.equal(j.toString(), 'd');
+ },
+ 'serialize a "user at domain" JID':
+ function() {
+ var j = new xmpp.JID('u', 'd');
+ assert.equal(j.toString(), 'u at d');
+ },
+ 'serialize a "domain/resource" JID':
+ function() {
+ var j = new xmpp.JID(null, 'd', 'r');
+ assert.equal(j.toString(), 'd/r');
+ },
+ 'serialize a "user at domain/resource" JID':
+ function() {
+ var j = new xmpp.JID('u', 'd', 'r');
+ assert.equal(j.toString(), 'u at d/r');
+ }
+ }
+
+}).run();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list