Software /
code /
prosody
Annotate
spec/util_jid_spec.lua @ 12650:e08bf2ad67da
moduleapi: Distribute permissions set from global modules to all hosts
Roles and permissions will always happen in the context of a host.
Prevents error upon indexing since `hosts["*"] == nil`
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 20 Jul 2022 13:05:35 +0200 |
parent | 12190:3616128cd2e3 |
child | 12767:3b75943fa5c1 |
rev | line source |
---|---|
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local jid = require "util.jid"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 describe("util.jid", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 describe("#join()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 assert.are.equal(jid.join("a", "b", "c"), "a@b/c", "builds full JID"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 assert.are.equal(jid.join("a", "b", nil), "a@b", "builds bare JID"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 assert.are.equal(jid.join(nil, "b", "c"), "b/c", "builds full host JID"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 assert.are.equal(jid.join(nil, "b", nil), "b", "builds bare host JID"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 assert.are.equal(jid.join(nil, nil, nil), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 assert.are.equal(jid.join("a", nil, nil), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 assert.are.equal(jid.join(nil, nil, "c"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 assert.are.equal(jid.join("a", nil, "c"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 end); |
12190
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
16 it("should reject invalid arguments", function () |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
17 assert.has_error(function () jid.join(false, "bork", nil) end) |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
18 assert.has_error(function () jid.join(nil, "bork", false) end) |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
19 assert.has_error(function () jid.join(false, false, false) end) |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
20 end) |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 describe("#split()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 local function test(input_jid, expected_node, expected_server, expected_resource) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 local rnode, rserver, rresource = jid.split(input_jid); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 assert.are.equal(expected_node, rnode, "split("..tostring(input_jid)..") failed"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 assert.are.equal(expected_server, rserver, "split("..tostring(input_jid)..") failed"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 assert.are.equal(expected_resource, rresource, "split("..tostring(input_jid)..") failed"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 -- Valid JIDs |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 test("node@server", "node", "server", nil ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 test("node@server/resource", "node", "server", "resource" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 test("server", nil, "server", nil ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 test("server/resource", nil, "server", "resource" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 test("server/resource@foo", nil, "server", "resource@foo" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 test("server/resource@foo/bar", nil, "server", "resource@foo/bar"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 -- Always invalid JIDs |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 test(nil, nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 test("node@/server", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 test("@server", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 test("@server/resource", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 test("@/resource", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 end); |
12190
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
46 it("should reject invalid arguments", function () |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
47 assert.has_error(function () jid.split(false) end) |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
48 end) |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 describe("#bare()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 assert.are.equal(jid.bare("user@host"), "user@host", "bare JID remains bare"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 assert.are.equal(jid.bare("host"), "host", "Host JID remains host"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 assert.are.equal(jid.bare("host/resource"), "host", "Host JID with resource becomes host"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 assert.are.equal(jid.bare("user@host/resource"), "user@host", "user@host JID with resource becomes user@host"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 assert.are.equal(jid.bare("user@/resource"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 assert.are.equal(jid.bare("@/resource"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 assert.are.equal(jid.bare("@/"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 assert.are.equal(jid.bare("/"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 assert.are.equal(jid.bare(""), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 assert.are.equal(jid.bare("@"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 assert.are.equal(jid.bare("user@"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 assert.are.equal(jid.bare("user@@"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 assert.are.equal(jid.bare("user@@host"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
67 assert.are.equal(jid.bare("user@@host/resource"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
68 assert.are.equal(jid.bare("user@host/"), nil, "invalid JID is nil"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
69 end); |
12190
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
70 it("should reject invalid arguments", function () |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
71 assert.has_error(function () jid.bare(false) end) |
3616128cd2e3
util.jid: Explicitly check for nil rather than falsy
Kim Alvefur <zash@zash.se>
parents:
11055
diff
changeset
|
72 end) |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
73 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
74 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
75 describe("#compare()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 assert.are.equal(jid.compare("host", "host"), true, "host should match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 assert.are.equal(jid.compare("host", "other-host"), false, "host should not match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 assert.are.equal(jid.compare("other-user@host/resource", "host"), true, "host should match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 assert.are.equal(jid.compare("other-user@host", "user@host"), false, "user should not match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 assert.are.equal(jid.compare("user@host", "host"), true, "host should match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 assert.are.equal(jid.compare("user@host/resource", "host"), true, "host should match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 assert.are.equal(jid.compare("user@host/resource", "user@host"), true, "user and host should match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 assert.are.equal(jid.compare("user@other-host", "host"), false, "host should not match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 assert.are.equal(jid.compare("user@other-host", "user@host"), false, "host should not match"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 |
11055
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
89 local jid_escaping_test_vectors = { |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
90 -- From https://xmpp.org/extensions/xep-0106.xml#examples sans @example.com |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
91 [[space cadet]], [[space\20cadet]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
92 [[call me "ishmael"]], [[call\20me\20\22ishmael\22]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
93 [[at&t guy]], [[at\26t\20guy]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
94 [[d'artagnan]], [[d\27artagnan]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
95 [[/.fanboy]], [[\2f.fanboy]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
96 [[::foo::]], [[\3a\3afoo\3a\3a]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
97 [[<foo>]], [[\3cfoo\3e]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
98 [[user@host]], [[user\40host]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
99 [[c:\net]], [[c\3a\net]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
100 [[c:\\net]], [[c\3a\\net]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
101 [[c:\cool stuff]], [[c\3a\cool\20stuff]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
102 [[c:\5commas]], [[c\3a\5c5commas]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
103 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
104 -- Section 4.2 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
105 [[\3and\2is\5cool]], [[\5c3and\2is\5c5cool]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
106 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
107 -- From aioxmpp |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
108 [[\5c]], [[\5c5c]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
109 -- [[\5C]], [[\5C]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
110 [[\2plus\2is\4]], [[\2plus\2is\4]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
111 [[foo\bar]], [[foo\bar]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
112 [[foo\41r]], [[foo\41r]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
113 -- additional test vectors |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
114 [[call\20me]], [[call\5c20me]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
115 }; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
116 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
117 describe("#escape()", function () |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
118 it("should work", function () |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
119 for i = 1, #jid_escaping_test_vectors, 2 do |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
120 local original = jid_escaping_test_vectors[i]; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
121 local escaped = jid_escaping_test_vectors[i+1]; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
122 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
123 assert.are.equal(escaped, jid.escape(original), ("Escapes '%s' -> '%s'"):format(original, escaped)); |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
124 end |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
125 end); |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
126 end) |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
127 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
128 describe("#unescape()", function () |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
129 it("should work", function () |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
130 for i = 1, #jid_escaping_test_vectors, 2 do |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
131 local original = jid_escaping_test_vectors[i]; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
132 local escaped = jid_escaping_test_vectors[i+1]; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
133 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
134 assert.are.equal(original, jid.unescape(escaped), ("Unescapes '%s' -> '%s'"):format(escaped, original)); |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
135 end |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
136 end); |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
137 end) |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
138 |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 it("should work with nodes", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 local function test(_jid, expected_node) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 assert.are.equal(jid.node(_jid), expected_node, "Unexpected node for "..tostring(_jid)); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 test("example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 test("foo.example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 test("foo.example.com/resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 test("foo.example.com/some resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 test("foo.example.com/some@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
149 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 test("foo@foo.example.com/some@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 test("foo@example/some@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 test("foo@example/@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 test("foo@example", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 test("foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 test(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 it("should work with hosts", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 local function test(_jid, expected_host) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 assert.are.equal(jid.host(_jid), expected_host, "Unexpected host for "..tostring(_jid)); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 test("example.com", "example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 test("foo.example.com", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 test("foo.example.com/resource", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 test("foo.example.com/some resource", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 test("foo.example.com/some@resource", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 test("foo@foo.example.com/some@resource", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 test("foo@example/some@resource", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
175 test("foo@example/@resource", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
176 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 test("foo@example", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 test("foo", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 test(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
182 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
183 it("should work with resources", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
184 local function test(_jid, expected_resource) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 assert.are.equal(jid.resource(_jid), expected_resource, "Unexpected resource for "..tostring(_jid)); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 test("example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
189 test("foo.example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 test("foo.example.com/resource", "resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 test("foo.example.com/some resource", "some resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
192 test("foo.example.com/some@resource", "some@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
193 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
194 test("foo@foo.example.com/some@resource", "some@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
195 test("foo@example/some@resource", "some@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
197 test("foo@example/@resource", "@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
198 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
199 test("foo@example", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
200 test("foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
201 test("/foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
202 test("@x/foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
203 test("@/foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
204 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
205 test(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
206 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
207 end); |