spec/xml_spec.lua

Sun, 30 Dec 2018 09:43:36 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sun, 30 Dec 2018 09:43:36 +0000
changeset 164
14500a149b31
parent 97
bc4c2d9765f1
permissions
-rw-r--r--

client: Ignore timeout timer if we received a stanza

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)
		print("literal", tostring(s1) == tostring(s2));
		assert(false, "No match, but they should.");
	end
end

local function no(s1, s2)
	s1, s2 = parse(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("scansion.xml", function ()
	it("should work", function ()
		local s = parse("<test foo='bar'/>");
		assert.equal("test", s.name);
		assert.equal("bar", s.attr.foo);
		yes(s, st.stanza("test", { foo = "bar" }));
	end);
	it("should add a scansion namespace", function ()
		local s = parse("<scansion:test/>");
		assert.equal("test", s.name);
		assert.equal(xml.xmlns_scansion, s.attr.xmlns);

		local s = parse("<test scansion:test='foo'/>");
		assert.equal("test", s.name);
		assert.equal("foo", s.attr["scansion:test"]);
	end);
end);

mercurial