Comparison

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
comparison
equal deleted inserted replaced
11054:ad07152d7bde 11055:5fb95410f89c
73 assert.are.equal(jid.compare("user@other-host", "host"), false, "host should not match"); 73 assert.are.equal(jid.compare("user@other-host", "host"), false, "host should not match");
74 assert.are.equal(jid.compare("user@other-host", "user@host"), false, "host should not match"); 74 assert.are.equal(jid.compare("user@other-host", "user@host"), false, "host should not match");
75 end); 75 end);
76 end); 76 end);
77 77
78 local jid_escaping_test_vectors = {
79 -- From https://xmpp.org/extensions/xep-0106.xml#examples sans @example.com
80 [[space cadet]], [[space\20cadet]],
81 [[call me "ishmael"]], [[call\20me\20\22ishmael\22]],
82 [[at&t guy]], [[at\26t\20guy]],
83 [[d'artagnan]], [[d\27artagnan]],
84 [[/.fanboy]], [[\2f.fanboy]],
85 [[::foo::]], [[\3a\3afoo\3a\3a]],
86 [[<foo>]], [[\3cfoo\3e]],
87 [[user@host]], [[user\40host]],
88 [[c:\net]], [[c\3a\net]],
89 [[c:\\net]], [[c\3a\\net]],
90 [[c:\cool stuff]], [[c\3a\cool\20stuff]],
91 [[c:\5commas]], [[c\3a\5c5commas]],
92
93 -- Section 4.2
94 [[\3and\2is\5cool]], [[\5c3and\2is\5c5cool]],
95
96 -- From aioxmpp
97 [[\5c]], [[\5c5c]],
98 -- [[\5C]], [[\5C]],
99 [[\2plus\2is\4]], [[\2plus\2is\4]],
100 [[foo\bar]], [[foo\bar]],
101 [[foo\41r]], [[foo\41r]],
102 -- additional test vectors
103 [[call\20me]], [[call\5c20me]],
104 };
105
106 describe("#escape()", function ()
107 it("should work", function ()
108 for i = 1, #jid_escaping_test_vectors, 2 do
109 local original = jid_escaping_test_vectors[i];
110 local escaped = jid_escaping_test_vectors[i+1];
111
112 assert.are.equal(escaped, jid.escape(original), ("Escapes '%s' -> '%s'"):format(original, escaped));
113 end
114 end);
115 end)
116
117 describe("#unescape()", function ()
118 it("should work", function ()
119 for i = 1, #jid_escaping_test_vectors, 2 do
120 local original = jid_escaping_test_vectors[i];
121 local escaped = jid_escaping_test_vectors[i+1];
122
123 assert.are.equal(original, jid.unescape(escaped), ("Unescapes '%s' -> '%s'"):format(escaped, original));
124 end
125 end);
126 end)
127
78 it("should work with nodes", function() 128 it("should work with nodes", function()
79 local function test(_jid, expected_node) 129 local function test(_jid, expected_node)
80 assert.are.equal(jid.node(_jid), expected_node, "Unexpected node for "..tostring(_jid)); 130 assert.are.equal(jid.node(_jid), expected_node, "Unexpected node for "..tostring(_jid));
81 end 131 end
82 132