Software /
code /
prosody
Annotate
tests/test_util_jid.lua @ 8073:7361412a9664
SQL: Use standard quotes for columns and other identifiers, rewrite to grave accents for MySQL only (fixes #885)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 10 Apr 2017 23:13:39 +0200 |
parent | 7473:a558fef9d018 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2247
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2247
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
5776
bd0ff8ae98a8
Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents:
3479
diff
changeset
|
4 -- |
758 | 5 -- This project is MIT/X11 licensed. Please see the |
6 -- COPYING file in the source package for more information. | |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
366
diff
changeset
|
7 -- |
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
366
diff
changeset
|
8 |
2247
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
9 function join(join) |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
10 assert_equal(join("a", "b", "c"), "a@b/c", "builds full JID"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
11 assert_equal(join("a", "b", nil), "a@b", "builds bare JID"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
12 assert_equal(join(nil, "b", "c"), "b/c", "builds full host JID"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
13 assert_equal(join(nil, "b", nil), "b", "builds bare host JID"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
14 assert_equal(join(nil, nil, nil), nil, "invalid JID is nil"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
15 assert_equal(join("a", nil, nil), nil, "invalid JID is nil"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
16 assert_equal(join(nil, nil, "c"), nil, "invalid JID is nil"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
17 assert_equal(join("a", nil, "c"), nil, "invalid JID is nil"); |
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
18 end |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
366
diff
changeset
|
19 |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 function split(split) |
7473
a558fef9d018
test_util_jid: make function test() local [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7296
diff
changeset
|
22 local function test(input_jid, expected_node, expected_server, expected_resource) |
240
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
23 local rnode, rserver, rresource = split(input_jid); |
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
24 assert_equal(expected_node, rnode, "split("..tostring(input_jid)..") failed"); |
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
25 assert_equal(expected_server, rserver, "split("..tostring(input_jid)..") failed"); |
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
26 assert_equal(expected_resource, rresource, "split("..tostring(input_jid)..") failed"); |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 end |
3451
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
28 |
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
29 -- Valid JIDs |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 test("node@server", "node", "server", nil ); |
3479
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
31 test("node@server/resource", "node", "server", "resource" ); |
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
32 test("server", nil, "server", nil ); |
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
33 test("server/resource", nil, "server", "resource" ); |
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
34 test("server/resource@foo", nil, "server", "resource@foo" ); |
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
35 test("server/resource@foo/bar", nil, "server", "resource@foo/bar"); |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
36 |
3451
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
37 -- Always invalid JIDs |
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
38 test(nil, nil, nil, nil); |
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
39 test("node@/server", nil, nil, nil); |
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
40 test("@server", nil, nil, nil); |
6402a9defcdc
tests/test_util_jid.lua: Better formatting, comments, and stop giving 5 arguments to a 4-argument function (thanks Asterix :) )
Matthew Wild <mwild1@gmail.com>
parents:
3375
diff
changeset
|
41 test("@server/resource", nil, nil, nil); |
3479
f68198c2f68f
tests/test_util_jid.lua: Add more tests for JID splitting
Matthew Wild <mwild1@gmail.com>
parents:
3451
diff
changeset
|
42 test("@/resource", nil, nil, nil); |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
366
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
44 |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
45 function bare(bare) |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
46 assert_equal(bare("user@host"), "user@host", "bare JID remains bare"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
47 assert_equal(bare("host"), "host", "Host JID remains host"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
48 assert_equal(bare("host/resource"), "host", "Host JID with resource becomes host"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
49 assert_equal(bare("user@host/resource"), "user@host", "user@host JID with resource becomes user@host"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
50 assert_equal(bare("user@/resource"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
51 assert_equal(bare("@/resource"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
52 assert_equal(bare("@/"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
53 assert_equal(bare("/"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
54 assert_equal(bare(""), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
55 assert_equal(bare("@"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
56 assert_equal(bare("user@"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
57 assert_equal(bare("user@@"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
58 assert_equal(bare("user@@host"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
59 assert_equal(bare("user@@host/resource"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
60 assert_equal(bare("user@host/"), nil, "invalid JID is nil"); |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
61 end |
2247
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
62 |
3375
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
63 function compare(compare) |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
64 assert_equal(compare("host", "host"), true, "host should match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
65 assert_equal(compare("host", "other-host"), false, "host should not match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
66 assert_equal(compare("other-user@host/resource", "host"), true, "host should match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
67 assert_equal(compare("other-user@host", "user@host"), false, "user should not match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
68 assert_equal(compare("user@host", "host"), true, "host should match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
69 assert_equal(compare("user@host/resource", "host"), true, "host should match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
70 assert_equal(compare("user@host/resource", "user@host"), true, "user and host should match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
71 assert_equal(compare("user@other-host", "host"), false, "host should not match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
72 assert_equal(compare("user@other-host", "user@host"), false, "host should not match"); |
29e51e1c7c3d
util.jid: compare() added, with some tests.
Kim Alvefur <zash@zash.se>
parents:
2923
diff
changeset
|
73 end |
7296
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
74 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
75 function node(node) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
76 local function test(jid, expected_node) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
77 assert_equal(node(jid), expected_node, "Unexpected node for "..tostring(jid)); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
78 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
79 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
80 test("example.com", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
81 test("foo.example.com", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
82 test("foo.example.com/resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
83 test("foo.example.com/some resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
84 test("foo.example.com/some@resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
85 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
86 test("foo@foo.example.com/some@resource", "foo"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
87 test("foo@example/some@resource", "foo"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
88 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
89 test("foo@example/@resource", "foo"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
90 test("foo@example@resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
91 test("foo@example", "foo"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
92 test("foo", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
93 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
94 test(nil, nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
95 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
96 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
97 function host(host) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
98 local function test(jid, expected_host) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
99 assert_equal(host(jid), expected_host, "Unexpected host for "..tostring(jid)); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
100 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
101 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
102 test("example.com", "example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
103 test("foo.example.com", "foo.example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
104 test("foo.example.com/resource", "foo.example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
105 test("foo.example.com/some resource", "foo.example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
106 test("foo.example.com/some@resource", "foo.example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
107 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
108 test("foo@foo.example.com/some@resource", "foo.example.com"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
109 test("foo@example/some@resource", "example"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
110 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
111 test("foo@example/@resource", "example"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
112 test("foo@example@resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
113 test("foo@example", "example"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
114 test("foo", "foo"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
115 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
116 test(nil, nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
117 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
118 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
119 function resource(resource) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
120 local function test(jid, expected_resource) |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
121 assert_equal(resource(jid), expected_resource, "Unexpected resource for "..tostring(jid)); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
122 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
123 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
124 test("example.com", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
125 test("foo.example.com", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
126 test("foo.example.com/resource", "resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
127 test("foo.example.com/some resource", "some resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
128 test("foo.example.com/some@resource", "some@resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
129 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
130 test("foo@foo.example.com/some@resource", "some@resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
131 test("foo@example/some@resource", "some@resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
132 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
133 test("foo@example/@resource", "@resource"); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
134 test("foo@example@resource", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
135 test("foo@example", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
136 test("foo", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
137 test("/foo", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
138 test("@x/foo", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
139 test("@/foo", nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
140 |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
141 test(nil, nil); |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
142 end |
1859e07ae082
util.jid+tests: Add simple helpers... node(), host() and resource() for extracting specific parts of a JID
Matthew Wild <mwild1@gmail.com>
parents:
5776
diff
changeset
|
143 |