2 -- Copyright (C) 2008 Matthew Wild
3 -- Copyright (C) 2008 Waqas Hussain
5 -- This program is free software; you can redistribute it and/or
6 -- modify it under the terms of the GNU General Public License
7 -- as published by the Free Software Foundation; either version 2
8 -- of the License, or (at your option) any later version.
10 -- This program is distributed in the hope that it will be useful,
11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 -- GNU General Public License for more details.
15 -- You should have received a copy of the GNU General Public License
16 -- along with this program; if not, write to the Free Software
17 -- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 function test(input_jid, expected_node, expected_server, expected_resource)
24 local rnode, rserver, rresource = split(input_jid);
25 assert_equal(expected_node, rnode, "split("..tostring(input_jid)..") failed");
26 assert_equal(expected_server, rserver, "split("..tostring(input_jid)..") failed");
27 assert_equal(expected_resource, rresource, "split("..tostring(input_jid)..") failed");
29 test("node@server", "node", "server", nil );
30 test("node@server/resource", "node", "server", "resource" );
31 test("server", nil, "server", nil );
32 test("server/resource", nil, "server", "resource" );
33 test(nil, nil, nil , nil );
35 test("node@/server", nil, nil, nil , nil );
39 assert_equal(bare("user@host"), "user@host", "bare JID remains bare");
40 assert_equal(bare("host"), "host", "Host JID remains host");
41 assert_equal(bare("host/resource"), "host", "Host JID with resource becomes host");
42 assert_equal(bare("user@host/resource"), "user@host", "user@host JID with resource becomes user@host");
43 assert_equal(bare("user@/resource"), nil, "invalid JID is nil");
44 assert_equal(bare("@/resource"), nil, "invalid JID is nil");
45 assert_equal(bare("@/"), nil, "invalid JID is nil");
46 assert_equal(bare("/"), nil, "invalid JID is nil");
47 assert_equal(bare(""), nil, "invalid JID is nil");
48 assert_equal(bare("@"), nil, "invalid JID is nil");
49 assert_equal(bare("user@"), nil, "invalid JID is nil");
50 assert_equal(bare("user@@"), nil, "invalid JID is nil");
51 assert_equal(bare("user@@host"), nil, "invalid JID is nil");
52 assert_equal(bare("user@@host/resource"), nil, "invalid JID is nil");
53 assert_equal(bare("user@host/"), nil, "invalid JID is nil");