Mercurial > prosody-hg
comparison spec/util_jid_spec.lua @ 11200:bf8f2da84007
Merge 0.11->trunk
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Thu, 05 Nov 2020 22:31:25 +0100 |
| parents | 5fb95410f89c |
| children | 3616128cd2e3 |
comparison
equal
deleted
inserted
replaced
| 11199:6c7c50a4de32 | 11200:bf8f2da84007 |
|---|---|
| 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 |
