|
1 local stanzacmp = require "scansion.stanzacmp"; |
|
2 local verse = require "verse"; |
|
3 local st = require "util.stanza"; |
|
4 local xml = require "scansion.xml"; |
|
5 |
|
6 local function parse(...) |
|
7 local n = select("#", ...); |
|
8 local out = {}; |
|
9 for i = 1, n do |
|
10 local v = (select(i, ...)); |
|
11 if type(v) == "string" then |
|
12 out[i] = xml.parse(v); |
|
13 else |
|
14 out[i] = v; |
|
15 end |
|
16 end |
|
17 return table.unpack(out, 1, n); |
|
18 end |
|
19 |
|
20 local function yes(s1, s2) |
|
21 s1, s2 = parse(s1, s2); |
|
22 if not stanzacmp.stanzas_match(s1, s2) then |
|
23 print("s1", s1) |
|
24 print("s2", s2) |
|
25 print("literal", tostring(s1) == tostring(s2)); |
|
26 assert(false, "No match, but they should."); |
|
27 end |
|
28 end |
|
29 |
|
30 local function no(s1, s2) |
|
31 s1, s2 = parse(s1, s2); |
|
32 if stanzacmp.stanzas_match(s1, s2) then |
|
33 print("s1", s1) |
|
34 print("s2", s2) |
|
35 assert(false, "Match, but they should not."); |
|
36 end |
|
37 end |
|
38 |
|
39 describe("scansion.xml", function () |
|
40 it("should work", function () |
|
41 local s = parse("<test foo='bar'/>"); |
|
42 assert.equal("test", s.name); |
|
43 assert.equal("bar", s.attr.foo); |
|
44 yes(s, st.stanza("test", { foo = "bar" })); |
|
45 end); |
|
46 it("should add a scansion namespace", function () |
|
47 local s = parse("<scansion:test/>"); |
|
48 assert.equal("test", s.name); |
|
49 assert.equal(xml.xmlns_scansion, s.attr.xmlns); |
|
50 |
|
51 local s = parse("<test scansion:test='foo'/>"); |
|
52 assert.equal("test", s.name); |
|
53 assert.equal("foo", s.attr["scansion:test"]); |
|
54 end); |
|
55 end); |