Add tests for stanzacmp

Tue, 10 Jul 2018 11:08:59 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 10 Jul 2018 11:08:59 +0100
changeset 93
3f9bda0887d5
parent 92
9a58c8ee0757
child 94
1b3e848b4394

Add tests for stanzacmp

spec/stanzacmp_spec.lua file | annotate | diff | comparison | revisions
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/spec/stanzacmp_spec.lua	Tue Jul 10 11:08:59 2018 +0100
@@ -0,0 +1,64 @@
+local stanzacmp = require "scansion.stanzacmp";
+local verse = require "verse";
+local st = require "util.stanza";
+
+local function yes(s1, s2)
+	if not stanzacmp.stanzas_match(s1, s2) then
+		print("s1", s1)
+		print("s2", s2)
+		print("literal", tostring(s1) == tostring(s2));
+		assert(false, "No match, but they should.");
+	end
+end
+
+local function no(s1, s2)
+	if stanzacmp.stanzas_match(s1, s2) then
+		print("s1", s1)
+		print("s2", s2)
+		assert(false, "Match, but they should not.");
+	end
+end
+
+describe("stanzacmp", function ()
+	it("should work", function ()
+		local s1 = st.message({ to = "foo", from = "bar"});
+		local s2 = st.message({ to = "foo", from = "bar"});
+		
+		yes(s1, s2);
+		yes(s2, s1);
+		
+		s1.attr.to = nil;
+		
+		yes(s1, s2);
+		no(s2, s1);
+		
+		s1.attr.to = "foo";
+		yes(s1, s2);
+		
+		s2:tag("blah", { xmlns = "foobar" });
+		
+		yes(s1, s2);
+		no(s2, s1);
+		
+		s1:tag("blah", { xmlns = "foobar" });
+		yes(s1, s2);
+		yes(s2, s1);
+		
+		s1:tag("a");
+		no(s1, s2);
+		s2:tag("a");
+		yes(s1, s2);
+		s2:up():up();
+		s2:tag("extension", { xmlns = "blah" });
+		yes(s1, s2);
+		s2:tag("b");
+		yes(s1, s2);
+		s1:up():up();
+		s1:tag("extension", { xmlns = "blah" });
+		no(s1, s2);
+		s1:tag("b");
+		yes(s1, s2);
+		s1:tag("c", { n = "1" });
+		no(s1, s2);
+	end);
+end);

mercurial