spec/stanzacmp_spec.lua

changeset 170
db73c4c317ce
parent 153
f83ea6e5c3d8
equal deleted inserted replaced
169:ecae87f5aaba 170:db73c4c317ce
16 end 16 end
17 end 17 end
18 return table.unpack(out, 1, n); 18 return table.unpack(out, 1, n);
19 end 19 end
20 20
21 local function yes(s1, s2) 21 local function yes(s1, s2, captures)
22 s1, s2 = parse(s1, s2); 22 s1, s2 = parse(s1, s2);
23 if not stanzacmp.stanzas_match(s1, s2) then 23 if not stanzacmp.stanzas_match(s1, s2, captures) then
24 print("s1", s1) 24 print("s1", s1)
25 print("s2", s2) 25 print("s2", s2)
26 print("literal", tostring(s1) == tostring(s2)); 26 print("literal", tostring(s1) == tostring(s2));
27 assert(false, "No match, but they should."); 27 assert(false, "No match, but they should.");
28 end 28 end
29 end 29 end
30 30
31 local function no(s1, s2) 31 local function no(s1, s2, captures)
32 s1, s2 = parse(s1, s2); 32 s1, s2 = parse(s1, s2);
33 if stanzacmp.stanzas_match(s1, s2) then 33 if stanzacmp.stanzas_match(s1, s2, captures) then
34 print("s1", s1) 34 print("s1", s1)
35 print("s2", s2) 35 print("s2", s2)
36 assert(false, "Match, but they should not."); 36 assert(false, "Match, but they should not.");
37 end 37 end
38 end 38 end
195 <item jid='user@localhost/KeoGLEr3' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='owner'/> 195 <item jid='user@localhost/KeoGLEr3' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='owner'/>
196 <status code='110' xmlns='http://jabber.org/protocol/muc#user'/> 196 <status code='110' xmlns='http://jabber.org/protocol/muc#user'/>
197 </x> 197 </x>
198 </presence>]]); 198 </presence>]]);
199 end); 199 end);
200
201 it("supports captures", function ()
202 local captures = {};
203 yes([[<presence from='room@conference.localhost/Romeo'>
204 <x xmlns='http://jabber.org/protocol/muc#user'>
205 <status code='{scansion:capture:code1}' xmlns='http://jabber.org/protocol/muc#user'/>
206 <item jid='{scansion:any}' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='{scansion:any}'/>
207 <status code='{scansion:capture:code2}' xmlns='http://jabber.org/protocol/muc#user'/>
208 </x>
209 </presence>]],
210 [[<presence to='user@localhost/KeoGLEr3' from='room@conference.localhost/Romeo'>
211 <x xmlns='http://jabber.org/protocol/muc#user'>
212 <status code='201' xmlns='http://jabber.org/protocol/muc#user'/>
213 <item jid='user@localhost/KeoGLEr3' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='owner'/>
214 <status code='110' xmlns='http://jabber.org/protocol/muc#user'/>
215 </x>
216 </presence>]], captures);
217 assert.same({
218 ["attr:jid"] = 'user@localhost/KeoGLEr3';
219 ["attr:affiliation"] = "owner";
220 ["code1"] = "201";
221 ["code2"] = "110";
222 }, captures);
223 end);
200 end); 224 end);

mercurial