Software /
code /
prosody
Annotate
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 |
rev | line source |
---|---|
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 function split(split) |
240
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
3 function test(input_jid, expected_node, expected_server, expected_resource) |
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
4 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
|
5 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
|
6 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
|
7 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
|
8 end |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 test("node@server", "node", "server", nil ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 test("node@server/resource", "node", "server", "resource" ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 test("server", nil, "server", nil ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 test("server/resource", nil, "server", "resource" ); |
239 | 13 test(nil, nil, nil , nil ); |
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
|
14 |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
15 test("node@/server", nil, nil, nil , nil ); |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 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
|
17 |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
18 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
|
19 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
|
20 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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 end |