Software /
code /
prosody
Annotate
spec/util_jid_spec.lua @ 11055:5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 28 Aug 2020 18:43:37 +0200 |
parent | 8236:4878e4159e12 |
child | 12190:3616128cd2e3 |
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); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 describe("#split()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 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
|
20 local rnode, rserver, rresource = jid.split(input_jid); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 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
|
22 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
|
23 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
|
24 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 -- Valid JIDs |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 test("node@server", "node", "server", nil ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 test("node@server/resource", "node", "server", "resource" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 test("server", nil, "server", nil ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 test("server/resource", nil, "server", "resource" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 test("server/resource@foo", nil, "server", "resource@foo" ); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 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
|
33 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 -- Always invalid JIDs |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 test(nil, nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 test("node@/server", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 test("@server", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 test("@server/resource", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 test("@/resource", nil, nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 describe("#bare()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 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
|
47 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
|
48 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
|
49 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
|
50 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
|
51 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
|
52 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
|
53 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
|
54 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
|
55 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
|
56 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
|
57 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
|
58 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
|
59 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
|
60 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
|
61 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 describe("#compare()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
65 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
66 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
|
67 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 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
|
75 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
76 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 |
11055
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
78 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
|
79 -- 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
|
80 [[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
|
81 [[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
|
82 [[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
|
83 [[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
|
84 [[/.fanboy]], [[\2f.fanboy]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
85 [[::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
|
86 [[<foo>]], [[\3cfoo\3e]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
87 [[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
|
88 [[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
|
89 [[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
|
90 [[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
|
91 [[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
|
92 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
93 -- Section 4.2 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
94 [[\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
|
95 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
96 -- From aioxmpp |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
97 [[\5c]], [[\5c5c]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
98 -- [[\5C]], [[\5C]], |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
99 [[\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
|
100 [[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
|
101 [[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
|
102 -- additional test vectors |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
103 [[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
|
104 }; |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
105 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
106 describe("#escape()", function () |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
107 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
|
108 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
|
109 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
|
110 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
|
111 |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
112 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
|
113 end |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
114 end); |
5fb95410f89c
util.jid: Add test coverage for XEP-0106: JID Escaping functions
Kim Alvefur <zash@zash.se>
parents:
8236
diff
changeset
|
115 end) |
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("#unescape()", 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(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
|
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 |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 it("should work with nodes", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 local function test(_jid, expected_node) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 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
|
131 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 test("example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 test("foo.example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 test("foo.example.com/resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 test("foo.example.com/some resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 test("foo.example.com/some@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 test("foo@foo.example.com/some@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 test("foo@example/some@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 test("foo@example/@resource", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 test("foo@example", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 test("foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 test(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 end); |
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 it("should work with hosts", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 local function test(_jid, expected_host) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 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
|
153 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
155 test("example.com", "example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 test("foo.example.com", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 test("foo.example.com/resource", "foo.example.com"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 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
|
159 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
|
160 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 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
|
162 test("foo@example/some@resource", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
163 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 test("foo@example/@resource", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 test("foo@example", "example"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 test("foo", "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 test(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
170 end); |
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 it("should work with resources", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
173 local function test(_jid, expected_resource) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
174 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
|
175 end |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
176 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
177 test("example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
178 test("foo.example.com", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
179 test("foo.example.com/resource", "resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
180 test("foo.example.com/some resource", "some resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
181 test("foo.example.com/some@resource", "some@resource"); |
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 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
|
184 test("foo@example/some@resource", "some@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
185 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
186 test("foo@example/@resource", "@resource"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
187 test("foo@example@resource", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
188 test("foo@example", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
189 test("foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
190 test("/foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
191 test("@x/foo", nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
192 test("@/foo", nil); |
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(nil, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
195 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
196 end); |