spec/stanzacmp_spec.lua

changeset 153
f83ea6e5c3d8
parent 151
8191f165b9dd
child 170
db73c4c317ce
--- a/spec/stanzacmp_spec.lua	Thu Sep 13 16:05:45 2018 +0100
+++ b/spec/stanzacmp_spec.lua	Fri Sep 14 12:56:19 2018 +0100
@@ -45,13 +45,24 @@
 		yes(s1, s2);
 		yes(s2, s1);
 
-		s1.attr.to = nil;
+	end);
+
+	it("should allow additional top-level attributes by default", function ()
+		local s1 = [[<message to="foo" />]];
+		local s2 = [[<message to="foo" from="bar" />]];
 
 		yes(s1, s2);
 		no(s2, s1);
+		
+	end);
 
-		s1.attr.to = "foo";
+	it("should work", function ()
+		-- Legacy tests, need to be broken up (pain to debug when it goes wrong)
+		local s1 = st.message({ to = "foo", from = "bar"});
+		local s2 = st.message({ to = "foo", from = "bar"});
+
 		yes(s1, s2);
+		yes(s2, s1);
 
 		s2:tag("blah", { xmlns = "foobar" });
 
@@ -115,14 +126,32 @@
 		yes("<foo><one/><two/></foo>", "<foo><two/><one/></foo>");
 	end);
 
-	it("should not match unordered children", function ()
-		no("<foo><one><a/><b/></one></foo>", "<foo><one><b/><a/></one></foo>");
+	describe("unordered children", function ()
+		it("in the default namespace should match by default", function ()
+			yes("<foo><one><a/><b/></one></foo>", "<foo><one><b/><a/></one></foo>");
+		end)
+
+		it("in the default namespace should not match in strict mode", function ()
+			no("<foo><one scansion:strict='true'><a/><b/></one></foo>", "<foo><one><b/><a/></one></foo>");
+		end)
+
+		it("in a different namespace should not match", function ()
+			no("<foo><one xmlns='foo'><a/><b/></one></foo>", "<foo><one xmlns='foo'><b/><a/></one></foo>");
+		end)
+	end);
+
+	it("should match unordered children within the same namespace by default", function ()
+		yes("<foo><one><a/><b/></one></foo>", "<foo><one><b/><a/></one></foo>");
 	end);
 
 	it("should be possible to disable ordered matching", function ()
 		yes("<foo><one scansion:strict='no'><a/><b/></one></foo>", "<foo><one><b/><a/></one></foo>");
 	end);
 
+	it("should be possible to disable ordered matching at the top level", function ()
+		no("<foo scansion:strict='yes'><one/></foo>", "<foo><one/><two/></foo>");
+	end);
+
 	it("should match when there are many children", function ()
 		yes([[<s>
 			<x>
@@ -151,4 +180,21 @@
 			</query>
 		</iq>]]);
 	end);
+
+	it("should match", function ()
+		yes([[<presence 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>]],
+		[[<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>]]);
+	end);
 end);

mercurial