Annotate

tests/test_util_jid.lua @ 2970:9b8e139eff5f

net.server_select: Support for listener.onconnect
author Matthew Wild <mwild1@gmail.com>
date Sun, 11 Apr 2010 01:11:42 +0100
parent 2923:b7049746bd29
child 3375:29e51e1c7c3d
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: 2821
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 2821
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
2821
c0981e104abc tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
9 function join(join)
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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");
c0981e104abc 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
6f4e9911c7d1 Fix jid.split test function
Matthew Wild <mwild1@gmail.com>
parents: 28
diff changeset
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
2821
c0981e104abc tests: Add tests for util.jid.join()
Matthew Wild <mwild1@gmail.com>
parents: 1523
diff changeset
56