spec/util_jid_spec.lua
changeset 12771 3b75943fa5c1
parent 12194 3616128cd2e3
child 12774 249bf1a53866
equal deleted inserted replaced
12770:bde224616766 12771:3b75943fa5c1
    44 			test("@/resource", nil, nil, nil);
    44 			test("@/resource", nil, nil, nil);
    45 		end);
    45 		end);
    46 		it("should reject invalid arguments", function ()
    46 		it("should reject invalid arguments", function ()
    47 			assert.has_error(function () jid.split(false) end)
    47 			assert.has_error(function () jid.split(false) end)
    48 		end)
    48 		end)
       
    49 	end);
       
    50 
       
    51 	describe("#prepped_split()", function()
       
    52 		local function test(input_jid, expected_node, expected_server, expected_resource)
       
    53 			local rnode, rserver, rresource = jid.prepped_split(input_jid);
       
    54 			assert.are.equal(expected_node, rnode, "split("..tostring(input_jid)..") failed");
       
    55 			assert.are.equal(expected_server, rserver, "split("..tostring(input_jid)..") failed");
       
    56 			assert.are.equal(expected_resource, rresource, "split("..tostring(input_jid)..") failed");
       
    57 		end
       
    58 
       
    59 		it("should work", function()
       
    60 			-- Valid JIDs
       
    61 			test("node@server", 		"node", "server", nil		);
       
    62 			test("node@server/resource", 	"node", "server", "resource"        );
       
    63 			test("server", 			nil, 	"server", nil               );
       
    64 			test("server/resource", 	nil, 	"server", "resource"        );
       
    65 			test("server/resource@foo", 	nil, 	"server", "resource@foo"    );
       
    66 			test("server/resource@foo/bar",	nil, 	"server", "resource@foo/bar");
       
    67 
       
    68 			-- Always invalid JIDs
       
    69 			test(nil,                nil, nil, nil);
       
    70 			test("node@/server",     nil, nil, nil);
       
    71 			test("@server",          nil, nil, nil);
       
    72 			test("@server/resource", nil, nil, nil);
       
    73 			test("@/resource", nil, nil, nil);
       
    74 			test("@server/", nil, nil, nil);
       
    75 			test("server/", nil, nil, nil);
       
    76 			test("/resource", nil, nil, nil);
       
    77 		end);
       
    78 		it("should reject invalid arguments", function ()
       
    79 			assert.has_error(function () jid.prepped_split(false) end)
       
    80 		end)
       
    81 		it("should strip empty root label", function ()
       
    82 			test("node@server.", "node", "server", nil);
       
    83 		end);
       
    84 		it("should fail for JIDs that fail stringprep", function ()
       
    85 			test("node@invalid-\128-server", nil, nil, nil);
       
    86 			test("<invalid node>@server", nil, nil, nil);
       
    87 			test("node@server/invalid-\000-resource", nil, nil, nil);
       
    88 		end);
    49 	end);
    89 	end);
    50 
    90 
    51 
    91 
    52 	describe("#bare()", function()
    92 	describe("#bare()", function()
    53 		it("should work", function()
    93 		it("should work", function()