Software /
code /
prosody
Comparison
spec/util_jid_spec.lua @ 12190:3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
A boolean false should blow up.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 15 Jan 2022 16:25:25 +0100 |
parent | 11055:5fb95410f89c |
child | 12767:3b75943fa5c1 |
comparison
equal
deleted
inserted
replaced
12189:82c8e855c850 | 12190:3616128cd2e3 |
---|---|
11 assert.are.equal(jid.join(nil, nil, nil), nil, "invalid JID is nil"); | 11 assert.are.equal(jid.join(nil, nil, nil), nil, "invalid JID is nil"); |
12 assert.are.equal(jid.join("a", nil, nil), nil, "invalid JID is nil"); | 12 assert.are.equal(jid.join("a", nil, nil), nil, "invalid JID is nil"); |
13 assert.are.equal(jid.join(nil, nil, "c"), nil, "invalid JID is nil"); | 13 assert.are.equal(jid.join(nil, nil, "c"), nil, "invalid JID is nil"); |
14 assert.are.equal(jid.join("a", nil, "c"), nil, "invalid JID is nil"); | 14 assert.are.equal(jid.join("a", nil, "c"), nil, "invalid JID is nil"); |
15 end); | 15 end); |
16 it("should reject invalid arguments", function () | |
17 assert.has_error(function () jid.join(false, "bork", nil) end) | |
18 assert.has_error(function () jid.join(nil, "bork", false) end) | |
19 assert.has_error(function () jid.join(false, false, false) end) | |
20 end) | |
16 end); | 21 end); |
17 describe("#split()", function() | 22 describe("#split()", function() |
18 it("should work", function() | 23 it("should work", function() |
19 local function test(input_jid, expected_node, expected_server, expected_resource) | 24 local function test(input_jid, expected_node, expected_server, expected_resource) |
20 local rnode, rserver, rresource = jid.split(input_jid); | 25 local rnode, rserver, rresource = jid.split(input_jid); |
36 test("node@/server", nil, nil, nil); | 41 test("node@/server", nil, nil, nil); |
37 test("@server", nil, nil, nil); | 42 test("@server", nil, nil, nil); |
38 test("@server/resource", nil, nil, nil); | 43 test("@server/resource", nil, nil, nil); |
39 test("@/resource", nil, nil, nil); | 44 test("@/resource", nil, nil, nil); |
40 end); | 45 end); |
46 it("should reject invalid arguments", function () | |
47 assert.has_error(function () jid.split(false) end) | |
48 end) | |
41 end); | 49 end); |
42 | 50 |
43 | 51 |
44 describe("#bare()", function() | 52 describe("#bare()", function() |
45 it("should work", function() | 53 it("should work", function() |
57 assert.are.equal(jid.bare("user@@"), nil, "invalid JID is nil"); | 65 assert.are.equal(jid.bare("user@@"), nil, "invalid JID is nil"); |
58 assert.are.equal(jid.bare("user@@host"), nil, "invalid JID is nil"); | 66 assert.are.equal(jid.bare("user@@host"), nil, "invalid JID is nil"); |
59 assert.are.equal(jid.bare("user@@host/resource"), nil, "invalid JID is nil"); | 67 assert.are.equal(jid.bare("user@@host/resource"), nil, "invalid JID is nil"); |
60 assert.are.equal(jid.bare("user@host/"), nil, "invalid JID is nil"); | 68 assert.are.equal(jid.bare("user@host/"), nil, "invalid JID is nil"); |
61 end); | 69 end); |
70 it("should reject invalid arguments", function () | |
71 assert.has_error(function () jid.bare(false) end) | |
72 end) | |
62 end); | 73 end); |
63 | 74 |
64 describe("#compare()", function() | 75 describe("#compare()", function() |
65 it("should work", function() | 76 it("should work", function() |
66 assert.are.equal(jid.compare("host", "host"), true, "host should match"); | 77 assert.are.equal(jid.compare("host", "host"), true, "host should match"); |