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