Software /
code /
prosody
Annotate
spec/util_stanza_spec.lua @ 9236:83375ec33619
util.pubsub: Expand comment on return type from get_items
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 01 Sep 2018 00:45:51 +0200 |
parent | 9217:7df29c5fbb9b |
child | 9302:57f8e41255fb |
rev | line source |
---|---|
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
1 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
2 local st = require "util.stanza"; |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
3 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
4 describe("util.stanza", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
5 describe("#preserialize()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
6 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
7 local stanza = st.stanza("message", { a = "a" }); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
8 local stanza2 = st.preserialize(stanza); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
9 assert.is_string(stanza2 and stanza.name, "preserialize returns a stanza"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
10 assert.is_nil(stanza2.tags, "Preserialized stanza has no tag list"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
11 assert.is_nil(stanza2.last_add, "Preserialized stanza has no last_add marker"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
12 assert.is_nil(getmetatable(stanza2), "Preserialized stanza has no metatable"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
13 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
14 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
15 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
16 describe("#preserialize()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
17 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
18 local stanza = st.stanza("message", { a = "a" }); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
19 local stanza2 = st.deserialize(st.preserialize(stanza)); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
20 assert.is_string(stanza2 and stanza.name, "deserialize returns a stanza"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
21 assert.is_table(stanza2.attr, "Deserialized stanza has attributes"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
22 assert.are.equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
23 assert.is_table(getmetatable(stanza2), "Deserialized stanza has metatable"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
24 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
25 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
26 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
27 describe("#stanza()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
28 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
29 local s = st.stanza("foo", { xmlns = "myxmlns", a = "attr-a" }); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
30 assert.are.equal(s.name, "foo"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
31 assert.are.equal(s.attr.xmlns, "myxmlns"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
32 assert.are.equal(s.attr.a, "attr-a"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
33 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
34 local s1 = st.stanza("s1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
35 assert.are.equal(s1.name, "s1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
36 assert.are.equal(s1.attr.xmlns, nil); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
37 assert.are.equal(#s1, 0); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
38 assert.are.equal(#s1.tags, 0); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
39 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
40 s1:tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
41 assert.are.equal(#s1.tags, 1); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
42 assert.are.equal(s1.tags[1].name, "child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
43 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
44 s1:tag("grandchild1"):up(); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
45 assert.are.equal(#s1.tags, 1); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
46 assert.are.equal(s1.tags[1].name, "child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
47 assert.are.equal(#s1.tags[1], 1); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
48 assert.are.equal(s1.tags[1][1].name, "grandchild1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
49 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
50 s1:up():tag("child2"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
51 assert.are.equal(#s1.tags, 2, tostring(s1)); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
52 assert.are.equal(s1.tags[1].name, "child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
53 assert.are.equal(s1.tags[2].name, "child2"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
54 assert.are.equal(#s1.tags[1], 1); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
55 assert.are.equal(s1.tags[1][1].name, "grandchild1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
56 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
57 s1:up():text("Hello world"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
58 assert.are.equal(#s1.tags, 2); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
59 assert.are.equal(#s1, 3); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
60 assert.are.equal(s1.tags[1].name, "child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
61 assert.are.equal(s1.tags[2].name, "child2"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
62 assert.are.equal(#s1.tags[1], 1); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
63 assert.are.equal(s1.tags[1][1].name, "grandchild1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
64 end); |
8598
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
65 it("should work with unicode values", function () |
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
66 local s = st.stanza("Объект", { xmlns = "myxmlns", ["Объект"] = "&" }); |
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
67 assert.are.equal(s.name, "Объект"); |
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
68 assert.are.equal(s.attr.xmlns, "myxmlns"); |
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
69 assert.are.equal(s.attr["Объект"], "&"); |
282d544d48f4
util.stanza: Add tests ensuring support for unicode in tag/attr names
Matthew Wild <mwild1@gmail.com>
parents:
8597
diff
changeset
|
70 end); |
8641
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
71 it("should allow :text() with nil and empty strings", function () |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
72 local s_control = st.stanza("foo"); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
73 assert.same(st.stanza("foo"):text(), s_control); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
74 assert.same(st.stanza("foo"):text(nil), s_control); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
75 assert.same(st.stanza("foo"):text(""), s_control); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
76 end); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
77 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
78 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
79 describe("#message()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
80 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
81 local m = st.message(); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
82 assert.are.equal(m.name, "message"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
83 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
84 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
85 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
86 describe("#iq()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
87 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
88 local i = st.iq(); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
89 assert.are.equal(i.name, "iq"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
90 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
91 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
92 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
93 describe("#iq()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
94 it("should work", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
95 local p = st.presence(); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
96 assert.are.equal(p.name, "presence"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
97 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
98 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
99 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
100 describe("#reply()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
101 it("should work for <s>", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
102 -- Test stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
103 local s = st.stanza("s", { to = "touser", from = "fromuser", id = "123" }) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
104 :tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
105 -- Make reply stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
106 local r = st.reply(s); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
107 assert.are.equal(r.name, s.name); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
108 assert.are.equal(r.id, s.id); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
109 assert.are.equal(r.attr.to, s.attr.from); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
110 assert.are.equal(r.attr.from, s.attr.to); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
111 assert.are.equal(#r.tags, 0, "A reply should not include children of the original stanza"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
112 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
113 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
114 it("should work for <iq get>", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
115 -- Test stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
116 local s = st.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
117 :tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
118 -- Make reply stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
119 local r = st.reply(s); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
120 assert.are.equal(r.name, s.name); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
121 assert.are.equal(r.id, s.id); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
122 assert.are.equal(r.attr.to, s.attr.from); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
123 assert.are.equal(r.attr.from, s.attr.to); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
124 assert.are.equal(r.attr.type, "result"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
125 assert.are.equal(#r.tags, 0, "A reply should not include children of the original stanza"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
126 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
127 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
128 it("should work for <iq set>", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
129 -- Test stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
130 local s = st.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" }) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
131 :tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
132 -- Make reply stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
133 local r = st.reply(s); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
134 assert.are.equal(r.name, s.name); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
135 assert.are.equal(r.id, s.id); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
136 assert.are.equal(r.attr.to, s.attr.from); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
137 assert.are.equal(r.attr.from, s.attr.to); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
138 assert.are.equal(r.attr.type, "result"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
139 assert.are.equal(#r.tags, 0, "A reply should not include children of the original stanza"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
140 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
141 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
142 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
143 describe("#error_reply()", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
144 it("should work for <s>", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
145 -- Test stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
146 local s = st.stanza("s", { to = "touser", from = "fromuser", id = "123" }) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
147 :tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
148 -- Make reply stanza |
8597
6e5fbeaca0f4
util.stanza: Fix tests to call error_reply() correctly, and add tests to ensure it vaguely works
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
149 local r = st.error_reply(s, "cancel", "service-unavailable"); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
150 assert.are.equal(r.name, s.name); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
151 assert.are.equal(r.id, s.id); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
152 assert.are.equal(r.attr.to, s.attr.from); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
153 assert.are.equal(r.attr.from, s.attr.to); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
154 assert.are.equal(#r.tags, 1); |
8597
6e5fbeaca0f4
util.stanza: Fix tests to call error_reply() correctly, and add tests to ensure it vaguely works
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
155 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
156 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
157 |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
158 it("should work for <iq get>", function() |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
159 -- Test stanza |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
160 local s = st.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" }) |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
161 :tag("child1"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
162 -- Make reply stanza |
8597
6e5fbeaca0f4
util.stanza: Fix tests to call error_reply() correctly, and add tests to ensure it vaguely works
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
163 local r = st.error_reply(s, "cancel", "service-unavailable"); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
164 assert.are.equal(r.name, s.name); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
165 assert.are.equal(r.id, s.id); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
166 assert.are.equal(r.attr.to, s.attr.from); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
167 assert.are.equal(r.attr.from, s.attr.to); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
168 assert.are.equal(r.attr.type, "error"); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
169 assert.are.equal(#r.tags, 1); |
8597
6e5fbeaca0f4
util.stanza: Fix tests to call error_reply() correctly, and add tests to ensure it vaguely works
Matthew Wild <mwild1@gmail.com>
parents:
8236
diff
changeset
|
170 assert.are.equal(r.tags[1].tags[1].name, "service-unavailable"); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
171 end); |
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
172 end); |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
173 |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
174 describe("should reject #invalid", function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
175 local invalid_names = { |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
176 ["empty string"] = "", ["characters"] = "<>"; |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
177 } |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
178 local invalid_data = { |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
179 ["number"] = 1234, ["table"] = {}; |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
180 ["utf8"] = string.char(0xF4, 0x90, 0x80, 0x80); |
8641
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
181 ["nil"] = "nil"; ["boolean"] = true; |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
182 }; |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
183 |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
184 for value_type, value in pairs(invalid_names) do |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
185 it(value_type.." in tag names", function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
186 assert.error_matches(function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
187 st.stanza(value); |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
188 end, value_type); |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
189 end); |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
190 it(value_type.." in attribute names", function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
191 assert.error_matches(function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
192 st.stanza("valid", { [value] = "valid" }); |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
193 end, value_type); |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
194 end); |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
195 end |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
196 for value_type, value in pairs(invalid_data) do |
8641
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
197 if value == "nil" then value = nil; end |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
198 it(value_type.." in tag names", function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
199 assert.error_matches(function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
200 st.stanza(value); |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
201 end, value_type); |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
202 end); |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
203 it(value_type.." in attribute names", function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
204 assert.error_matches(function () |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
205 st.stanza("valid", { [value] = "valid" }); |
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
206 end, value_type); |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
207 end); |
8641
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
208 if value ~= nil then |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
209 it(value_type.." in attribute values", function () |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
210 assert.error_matches(function () |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
211 st.stanza("valid", { valid = value }); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
212 end, value_type); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
213 end); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
214 it(value_type.." in text node", function () |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
215 assert.error_matches(function () |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
216 st.stanza("valid"):text(value); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
217 end, value_type); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
218 end); |
c7734b59506f
util.stanza: tests: Add more invalid data types and update for :text(nil) and :text("")
Matthew Wild <mwild1@gmail.com>
parents:
8626
diff
changeset
|
219 end |
8626
20532f191f8d
util.stanza: Switch from asserts to if's, improve performance, errors and tests
Matthew Wild <mwild1@gmail.com>
parents:
8621
diff
changeset
|
220 end |
8599
62bfc85a53c8
util.stanza: Add stricter validation for data passed to stanza builder API
Matthew Wild <mwild1@gmail.com>
parents:
8598
diff
changeset
|
221 end); |
8621
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
222 |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
223 describe("#is_stanza", function () |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
224 -- is_stanza(any) -> boolean |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
225 it("identifies stanzas as stanzas", function () |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
226 assert.truthy(st.is_stanza(st.stanza("x"))); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
227 end); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
228 it("identifies strings as not stanzas", function () |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
229 assert.falsy(st.is_stanza("")); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
230 end); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
231 it("identifies numbers as not stanzas", function () |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
232 assert.falsy(st.is_stanza(1)); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
233 end); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
234 it("identifies tables as not stanzas", function () |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
235 assert.falsy(st.is_stanza({})); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
236 end); |
e3e9479d526e
util.stanza: Test coverage of is_stanza()
Kim Alvefur <zash@zash.se>
parents:
8599
diff
changeset
|
237 end); |
9000
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
238 |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
239 describe("#remove_children", function () |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
240 it("should work", function () |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
241 local s = st.stanza("x", {xmlns="test"}) |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
242 :tag("y", {xmlns="test"}):up() |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
243 :tag("z", {xmlns="test2"}):up() |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
244 :tag("x", {xmlns="test2"}):up() |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
245 |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
246 s:remove_children("x"); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
247 assert.falsy(s:get_child("x")) |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
248 assert.truthy(s:get_child("z","test2")); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
249 assert.truthy(s:get_child("x","test2")); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
250 |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
251 s:remove_children(nil, "test2"); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
252 assert.truthy(s:get_child("y")) |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
253 assert.falsy(s:get_child(nil,"test2")); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
254 |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
255 s:remove_children(); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
256 assert.falsy(s.tags[1]); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
257 end); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
258 end); |
4d64ff0719a6
util.stanza: Brief tests for :remove_children
Kim Alvefur <zash@zash.se>
parents:
8641
diff
changeset
|
259 |
9216
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
260 describe("#maptags", function () |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
261 it("should work", function () |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
262 local s = st.stanza("test") |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
263 :tag("one"):up() |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
264 :tag("two"):up() |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
265 :tag("one"):up() |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
266 :tag("three"):up(); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
267 |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
268 local function one_filter(tag) |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
269 if tag.name == "one" then |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
270 return nil; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
271 end |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
272 return tag; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
273 end |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
274 assert.equal(4, #s.tags); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
275 s:maptags(one_filter); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
276 assert.equal(2, #s.tags); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
277 end); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
278 |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
279 it("should work with multiple consecutive text nodes", function () |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
280 local s = st.deserialize({ |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
281 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
282 { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
283 "away"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
284 name = "show"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
285 attr = {}; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
286 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
287 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
288 { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
289 "I am away"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
290 name = "status"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
291 attr = {}; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
292 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
293 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
294 { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
295 "0"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
296 name = "priority"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
297 attr = {}; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
298 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
299 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
300 { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
301 name = "c"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
302 attr = { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
303 xmlns = "http://jabber.org/protocol/caps"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
304 node = "http://psi-im.org"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
305 hash = "sha-1"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
306 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
307 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
308 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
309 "\n"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
310 name = "presence"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
311 attr = { |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
312 to = "user@example.com/jflsjfld"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
313 from = "room@chat.example.org/nick"; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
314 }; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
315 }); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
316 |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
317 assert.equal(4, #s.tags); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
318 |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
319 s:maptags(function (tag) return tag; end); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
320 assert.equal(4, #s.tags); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
321 |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
322 s:maptags(function (tag) |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
323 if tag.name == "c" then |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
324 return nil; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
325 end |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
326 return tag; |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
327 end); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
328 assert.equal(3, #s.tags); |
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
329 end); |
9217
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
330 it("errors on invalid data - #981", function () |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
331 local s = st.message({}, "Hello"); |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
332 s.tags[1] = st.clone(s.tags[1]); |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
333 assert.has_error_match(function () |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
334 s:maptags(function () end); |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
335 end, "Invalid stanza"); |
7df29c5fbb9b
util.stanza + tests: Bail out of loop if we are iterating too far, fixes #981
Matthew Wild <mwild1@gmail.com>
parents:
9216
diff
changeset
|
336 end); |
9216
ba38a947020e
util.stanza tests: Add tests for maptags() method
Matthew Wild <mwild1@gmail.com>
parents:
9000
diff
changeset
|
337 end); |
8236
4878e4159e12
Port tests to the `busted` test runner
Waqas Hussain <waqas20@gmail.com>
parents:
diff
changeset
|
338 end); |