Software /
code /
prosody
Annotate
tests/test_util_jid.lua @ 2482:a1570e371258
util.stanza: Trailing whitespace
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Thu, 21 Jan 2010 13:22:41 +0000 |
parent | 2247:f62af2a9974e |
child | 2923:b7049746bd29 |
rev | line source |
---|---|
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
896
diff
changeset
|
1 -- Prosody IM |
760
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
2 -- Copyright (C) 2008-2009 Matthew Wild |
90ce865eebd8
Update copyright notices for 2009
Matthew Wild <mwild1@gmail.com>
parents:
759
diff
changeset
|
3 -- Copyright (C) 2008-2009 Waqas Hussain |
519
cccd610a0ef9
Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents:
366
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) |
240
c48dbfa6b1a6
Renamed some of the variables in jid.split test to make it clearer
Matthew Wild <mwild1@gmail.com>
parents:
239
diff
changeset
|
22 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
|
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 |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 test("node@server", "node", "server", nil ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 test("node@server/resource", "node", "server", "resource" ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 test("server", nil, "server", nil ); |
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 test("server/resource", nil, "server", "resource" ); |
239 | 32 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
|
33 |
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 test("node@/server", nil, nil, nil , nil ); |
556
624367a765cd
Add a couple more tests for jid.split
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
35 test("@server", nil, nil, nil , nil ); |
624367a765cd
Add a couple more tests for jid.split
Matthew Wild <mwild1@gmail.com>
parents:
519
diff
changeset
|
36 test("@server/resource",nil,nil,nil, nil ); |
28
4a238233f278
Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 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
|
38 |
5691edc7dd63
Improve jid.split() and jid.bare() to pass new test cases with invalid JIDs
Matthew Wild <mwild1@gmail.com>
parents:
240
diff
changeset
|
39 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
|
40 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
|
41 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
|
42 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
|
43 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
|
44 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
|
45 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
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 end |
2247
f62af2a9974e
tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
56 |