Mon, 10 Sep 2018 13:52:35 +0100
Revamp console output to be driven by log_data()
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);