spec/stanzacmp: Allow passing XML strings to yes()/no() to avoid manual stanza building

Thu, 06 Sep 2018 18:23:56 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Thu, 06 Sep 2018 18:23:56 +0100
changeset 98
88a3e03f4b9f
parent 97
bc4c2d9765f1
child 99
dc56d434e406

spec/stanzacmp: Allow passing XML strings to yes()/no() to avoid manual stanza building

spec/stanzacmp_spec.lua file | annotate | diff | comparison | revisions
--- a/spec/stanzacmp_spec.lua	Thu Sep 06 18:11:16 2018 +0100
+++ b/spec/stanzacmp_spec.lua	Thu Sep 06 18:23:56 2018 +0100
@@ -1,8 +1,24 @@
 local stanzacmp = require "scansion.stanzacmp";
 local verse = require "verse";
 local st = require "util.stanza";
+local xml = require "scansion.xml";
+
+local function parse(...)
+	local n = select("#", ...);
+	local out = {};
+	for i = 1, n do
+		local v = (select(i, ...));
+		if type(v) == "string" then
+			out[i] = xml.parse(v);
+		else
+			out[i] = v;
+		end
+	end
+	return table.unpack(out, 1, n);
+end
 
 local function yes(s1, s2)
+	s1, s2 = parse(s1, s2);
 	if not stanzacmp.stanzas_match(s1, s2) then
 		print("s1", s1)
 		print("s2", s2)
@@ -12,6 +28,7 @@
 end
 
 local function no(s1, s2)
+	s1, s2 = parse(s1, s2);
 	if stanzacmp.stanzas_match(s1, s2) then
 		print("s1", s1)
 		print("s2", s2)

mercurial