tests/test_util_jid.lua
author Matthew Wild <mwild1@gmail.com>
Wed, 01 May 2013 13:54:31 +0100
branchsasl
changeset 5555 70a7ef4b6aaa
parent 1523 841d61be198f
child 2247 f62af2a9974e
permissions -rw-r--r--
Close 'sasl' branch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
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
cccd610a0ef9 Insert copyright/license headers
Matthew Wild <mwild1@gmail.com>
parents: 366
diff changeset
     9
28
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    10
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
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
    12
	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
    13
		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
    14
		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
    15
		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
    16
		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
    17
	end
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    18
	test("node@server", 		"node", "server", nil		);
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
	test("node@server/resource", 	"node", "server", "resource"	);
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
	test("server", 			nil, 	"server", nil		);
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    21
	test("server/resource", 	nil, 	"server", "resource"	);
239
6f4e9911c7d1 Fix jid.split test function
Matthew Wild <mwild1@gmail.com>
parents: 28
diff changeset
    22
	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
    23
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
	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
    25
	test("@server",      nil, nil, nil , nil );
624367a765cd Add a couple more tests for jid.split
Matthew Wild <mwild1@gmail.com>
parents: 519
diff changeset
    26
	test("@server/resource",nil,nil,nil, nil );
28
4a238233f278 Adding initial unit testing scripts
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    27
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
    28
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
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
    30
	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
    31
	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
    32
	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
    33
	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
    34
	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
    35
	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
    36
	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
    37
	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
    38
	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
    39
	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
    40
	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
    41
	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
    42
	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
    43
	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
    44
	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
    45
end