spec/stanzacmp_spec.lua

Tue, 10 Jul 2018 11:14:34 +0100

author
Matthew Wild <mwild1@gmail.com>
date
Tue, 10 Jul 2018 11:14:34 +0100
changeset 95
a1e7ad9336db
parent 93
3f9bda0887d5
child 98
88a3e03f4b9f
permissions
-rw-r--r--

tests: Add test for scansion:any

93
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
1 local stanzacmp = require "scansion.stanzacmp";
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 local verse = require "verse";
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 local st = require "util.stanza";
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 local function yes(s1, s2)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 if not stanzacmp.stanzas_match(s1, s2) then
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 print("s1", s1)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8 print("s2", s2)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 print("literal", tostring(s1) == tostring(s2));
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10 assert(false, "No match, but they should.");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 end
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12 end
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
13
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14 local function no(s1, s2)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 if stanzacmp.stanzas_match(s1, s2) then
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16 print("s1", s1)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 print("s2", s2)
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 assert(false, "Match, but they should not.");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 end
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 end
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 describe("stanzacmp", function ()
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23 it("should work", function ()
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24 local s1 = st.message({ to = "foo", from = "bar"});
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 local s2 = st.message({ to = "foo", from = "bar"});
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28 yes(s2, s1);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 s1.attr.to = nil;
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 no(s2, s1);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 s1.attr.to = "foo";
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 s2:tag("blah", { xmlns = "foobar" });
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41 no(s2, s1);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 s1:tag("blah", { xmlns = "foobar" });
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 yes(s2, s1);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 s1:tag("a");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 no(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 s2:tag("a");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 s2:up():up();
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 s2:tag("extension", { xmlns = "blah" });
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 s2:tag("b");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 s1:up():up();
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 s1:tag("extension", { xmlns = "blah" });
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 no(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 s1:tag("b");
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 yes(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 s1:tag("c", { n = "1" });
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62 no(s1, s2);
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 end);
95
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
64 it("should allow matching any attribute value with {scansion:any}", function ()
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
65 --[[
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
66 <message from="user@localhost/71652fc8-93cb-40c7-8220-47ce80cc417b" type="chat">
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
67 <body>Hello Juliet, are you there?</body>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
68 <delay xmlns="urn:xmpp:delay" from="localhost"/>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
69 </message>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
70 ]]
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
71
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
72 local s01 = st.message({ from = "user@localhost/71652fc8-93cb-40c7-8220-47ce80cc417b", type = "chat" })
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
73 :tag("body"):text("Hello Juliet, are you there?"):up()
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
74 :tag("delay", { xmlns = "urn:xmpp:delay", from = "localhost", stamp = "{scansion:any}" }):up();
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
75
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
76 --[[
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
77 <message to="juliet@localhost" type="chat" from="user@localhost/71652fc8-93cb-40c7-8220-47ce80cc417b">
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
78 <body>Hello Juliet, are you there?</body>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
79 <stanza-id xmlns="urn:xmpp:sid:0" by="user@localhost" id="eb9eaf13-384e-47d1-a6c0-303ef4f1ac70"/>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
80 <stanza-id xmlns="urn:xmpp:sid:0" by="juliet@localhost" id="f6c6f61d-0b15-46d6-9f69-bca1640401d1"/>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
81 <delay xmlns="urn:xmpp:delay" stamp="2017-05-07T09:46:21Z" from="localhost"/>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
82 </message>
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
83 ]]
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
84
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
85 local s02 = st.message({ to = "juliet@localhost", from = "user@localhost/71652fc8-93cb-40c7-8220-47ce80cc417b", type = "chat" })
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
86 :tag("body"):text("Hello Juliet, are you there?"):up()
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
87 :tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = "user@localhost", id = "eb9eaf13-384e-47d1-a6c0-303ef4f1ac70" }):up()
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
88 :tag("stanza-id", { xmlns = "urn:xmpp:sid:0", by = "juliet@localhost", id = "f6c6f61d-0b15-46d6-9f69-bca1640401d1" }):up()
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
89 :tag("delay", { xmlns = "urn:xmpp:delay", stamp = "2017-05-07T09:46:21Z", from = "localhost" }):up();
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
90
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
91
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
92
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
93 yes(s01, s02);
a1e7ad9336db tests: Add test for scansion:any
Matthew Wild <mwild1@gmail.com>
parents: 93
diff changeset
94 end);
93
3f9bda0887d5 Add tests for stanzacmp
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end);

mercurial