spec/stanzacmp_spec.lua

changeset 170
db73c4c317ce
parent 153
f83ea6e5c3d8
--- a/spec/stanzacmp_spec.lua	Sat May 08 13:21:56 2021 +0200
+++ b/spec/stanzacmp_spec.lua	Thu Mar 23 11:43:25 2023 +0000
@@ -18,9 +18,9 @@
 	return table.unpack(out, 1, n);
 end
 
-local function yes(s1, s2)
+local function yes(s1, s2, captures)
 	s1, s2 = parse(s1, s2);
-	if not stanzacmp.stanzas_match(s1, s2) then
+	if not stanzacmp.stanzas_match(s1, s2, captures) then
 		print("s1", s1)
 		print("s2", s2)
 		print("literal", tostring(s1) == tostring(s2));
@@ -28,9 +28,9 @@
 	end
 end
 
-local function no(s1, s2)
+local function no(s1, s2, captures)
 	s1, s2 = parse(s1, s2);
-	if stanzacmp.stanzas_match(s1, s2) then
+	if stanzacmp.stanzas_match(s1, s2, captures) then
 		print("s1", s1)
 		print("s2", s2)
 		assert(false, "Match, but they should not.");
@@ -197,4 +197,28 @@
 			</x>
 		</presence>]]);
 	end);
+
+	it("supports captures", function ()
+		local captures = {};
+		yes([[<presence from='room@conference.localhost/Romeo'>
+			<x xmlns='http://jabber.org/protocol/muc#user'>
+				<status code='{scansion:capture:code1}' xmlns='http://jabber.org/protocol/muc#user'/>
+				<item jid='{scansion:any}' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='{scansion:any}'/>
+				<status code='{scansion:capture:code2}' xmlns='http://jabber.org/protocol/muc#user'/>
+			</x>
+		</presence>]],
+		[[<presence to='user@localhost/KeoGLEr3' from='room@conference.localhost/Romeo'>
+			<x xmlns='http://jabber.org/protocol/muc#user'>
+				<status code='201' xmlns='http://jabber.org/protocol/muc#user'/>
+				<item jid='user@localhost/KeoGLEr3' role='moderator' xmlns='http://jabber.org/protocol/muc#user' affiliation='owner'/>
+				<status code='110' xmlns='http://jabber.org/protocol/muc#user'/>
+			</x>
+		</presence>]], captures);
+		assert.same({
+			["attr:jid"] = 'user@localhost/KeoGLEr3';
+			["attr:affiliation"] = "owner";
+			["code1"] = "201";
+			["code2"] = "110";
+		}, captures);
+	end);
 end);

mercurial