Diff

tests/test_util_jid.lua @ 366:5691edc7dd63

Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
author Matthew Wild <mwild1@gmail.com>
date Fri, 21 Nov 2008 05:02:53 +0000
parent 240:c48dbfa6b1a6
child 519:cccd610a0ef9
line wrap: on
line diff
--- a/tests/test_util_jid.lua	Thu Nov 20 23:28:16 2008 +0000
+++ b/tests/test_util_jid.lua	Fri Nov 21 05:02:53 2008 +0000
@@ -11,4 +11,24 @@
 	test("server", 			nil, 	"server", nil		);
 	test("server/resource", 	nil, 	"server", "resource"	);
 	test(nil,			nil,	nil	, nil		);
+
+	test("node@/server", nil, nil, nil , nil );
 end
+
+function bare(bare)
+	assert_equal(bare("user@host"), "user@host", "bare JID remains bare");
+	assert_equal(bare("host"), "host", "Host JID remains host");
+	assert_equal(bare("host/resource"), "host", "Host JID with resource becomes host");
+	assert_equal(bare("user@host/resource"), "user@host", "user@host JID with resource becomes user@host");
+	assert_equal(bare("user@/resource"), nil, "invalid JID is nil");
+	assert_equal(bare("@/resource"), nil, "invalid JID is nil");
+	assert_equal(bare("@/"), nil, "invalid JID is nil");
+	assert_equal(bare("/"), nil, "invalid JID is nil");
+	assert_equal(bare(""), nil, "invalid JID is nil");
+	assert_equal(bare("@"), nil, "invalid JID is nil");
+	assert_equal(bare("user@"), nil, "invalid JID is nil");
+	assert_equal(bare("user@@"), nil, "invalid JID is nil");
+	assert_equal(bare("user@@host"), nil, "invalid JID is nil");
+	assert_equal(bare("user@@host/resource"), nil, "invalid JID is nil");
+	assert_equal(bare("user@host/"), nil, "invalid JID is nil");
+end