Annotate

tests/test_util_jid.lua @ 3888:8e98ad57fcbb

util-src/Makefile, util-src/encodings.c{,pp}: Port ICU code to C, rename encodings.cpp back to .c and amend the Makefile accordingly
author Matthew Wild <mwild1@gmail.com>
date Fri, 17 Dec 2010 22:32:21 +0000
parent 3479:f68198c2f68f
child 5776:bd0ff8ae98a8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
519
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 366
diff changeset
4 --
758
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
b1885732e979 GPL->MIT!
Matthew Wild <mwild1@gmail.com>
parents: 615
diff changeset
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
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