diff options
author | Matthew Wild <mwild1@gmail.com> | 2016-03-18 14:03:35 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2016-03-18 14:03:35 +0000 |
commit | c7e80a8b0191239b7d7103154d4c079868234e41 (patch) | |
tree | cc8a353f9fd1d39993e99256dd784e813d0e4153 /tests/test_util_jid.lua | |
parent | f76d7cdfb91850381b47ec3abfbc280f32136682 (diff) | |
parent | f739ed2c46827cca1b0b7af08320584886e76283 (diff) | |
download | prosody-c7e80a8b0191239b7d7103154d4c079868234e41.tar.gz prosody-c7e80a8b0191239b7d7103154d4c079868234e41.zip |
Merge 0.10->trunk
Diffstat (limited to 'tests/test_util_jid.lua')
-rw-r--r-- | tests/test_util_jid.lua | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/test_util_jid.lua b/tests/test_util_jid.lua index 02a90c3b..c697e63f 100644 --- a/tests/test_util_jid.lua +++ b/tests/test_util_jid.lua @@ -71,3 +71,73 @@ function compare(compare) 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 + |