Diff

tests/test_util_jid.lua @ 7302:92d86016e1e3

Merge 0.10->trunk
author Matthew Wild <mwild1@gmail.com>
date Fri, 18 Mar 2016 14:03:35 +0000
parent 7296:1859e07ae082
child 7473:a558fef9d018
line wrap: on
line diff
--- a/tests/test_util_jid.lua	Fri Mar 18 00:08:58 2016 +0100
+++ b/tests/test_util_jid.lua	Fri Mar 18 14:03:35 2016 +0000
@@ -71,3 +71,73 @@
 	assert_equal(compare("user@other-host", "host"), false, "host should not match");
 	assert_equal(compare("user@other-host", "user@host"), false, "host should not match");
 end
+
+function node(node)
+	local function test(jid, expected_node)
+		assert_equal(node(jid), expected_node, "Unexpected node for "..tostring(jid));
+	end
+
+	test("example.com", nil);
+	test("foo.example.com", nil);
+	test("foo.example.com/resource", nil);
+	test("foo.example.com/some resource", nil);
+	test("foo.example.com/some@resource", nil);
+
+	test("foo@foo.example.com/some@resource", "foo");
+	test("foo@example/some@resource", "foo");
+
+	test("foo@example/@resource", "foo");
+	test("foo@example@resource", nil);
+	test("foo@example", "foo");
+	test("foo", nil);
+
+	test(nil, nil);
+end
+
+function host(host)
+	local function test(jid, expected_host)
+		assert_equal(host(jid), expected_host, "Unexpected host for "..tostring(jid));
+	end
+
+	test("example.com", "example.com");
+	test("foo.example.com", "foo.example.com");
+	test("foo.example.com/resource", "foo.example.com");
+	test("foo.example.com/some resource", "foo.example.com");
+	test("foo.example.com/some@resource", "foo.example.com");
+
+	test("foo@foo.example.com/some@resource", "foo.example.com");
+	test("foo@example/some@resource", "example");
+
+	test("foo@example/@resource", "example");
+	test("foo@example@resource", nil);
+	test("foo@example", "example");
+	test("foo", "foo");
+
+	test(nil, nil);
+end
+
+function resource(resource)
+	local function test(jid, expected_resource)
+		assert_equal(resource(jid), expected_resource, "Unexpected resource for "..tostring(jid));
+	end
+
+	test("example.com", nil);
+	test("foo.example.com", nil);
+	test("foo.example.com/resource", "resource");
+	test("foo.example.com/some resource", "some resource");
+	test("foo.example.com/some@resource", "some@resource");
+
+	test("foo@foo.example.com/some@resource", "some@resource");
+	test("foo@example/some@resource", "some@resource");
+
+	test("foo@example/@resource", "@resource");
+	test("foo@example@resource", nil);
+	test("foo@example", nil);
+	test("foo", nil);
+	test("/foo", nil);
+	test("@x/foo", nil);
+	test("@/foo", nil);
+
+	test(nil, nil);
+end
+