Annotate

tests/test_util_stanza.lua @ 8016:9546c629289b

util.id: New util for producing random identifiers of varying sizes
author Kim Alvefur <zash@zash.se>
date Wed, 29 Mar 2017 22:38:31 +0200
parent 7961:ff556d010225
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 682
diff changeset
1 -- Prosody IM
2923
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
2 -- Copyright (C) 2008-2010 Matthew Wild
b7049746bd29 Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents: 1522
diff changeset
3 -- Copyright (C) 2008-2010 Waqas Hussain
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 3639
diff changeset
4 --
1522
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 682
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 682
diff changeset
6 -- COPYING file in the source package for more information.
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 682
diff changeset
7 --
569d58d21612 Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents: 682
diff changeset
8
682
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
9
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
10 function preserialize(preserialize, st)
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
11 local stanza = st.stanza("message", { a = "a" });
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
12 local stanza2 = preserialize(stanza);
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
13 assert_is(stanza2 and stanza.name, "preserialize returns a stanza");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
14 assert_is_not(stanza2.tags, "Preserialized stanza has no tag list");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
15 assert_is_not(stanza2.last_add, "Preserialized stanza has no last_add marker");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
16 assert_is_not(getmetatable(stanza2), "Preserialized stanza has no metatable");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
17 end
681
686b73503ce8 Add test for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18
686b73503ce8 Add test for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 function deserialize(deserialize, st)
686b73503ce8 Add test for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20 local stanza = st.stanza("message", { a = "a" });
5776
bd0ff8ae98a8 Remove all trailing whitespace
Florian Zeitz <florob@babelmonkeys.de>
parents: 3639
diff changeset
21
681
686b73503ce8 Add test for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local stanza2 = deserialize(st.preserialize(stanza));
682
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
23 assert_is(stanza2 and stanza.name, "deserialize returns a stanza");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
24 assert_table(stanza2.attr, "Deserialized stanza has attributes");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
25 assert_equal(stanza2.attr.a, "a", "Deserialized stanza retains attributes");
dedd19e9d4b3 Add more tests for util/stanza.lua serialization routines
Matthew Wild <mwild1@gmail.com>
parents: 681
diff changeset
26 assert_table(getmetatable(stanza2), "Deserialized stanza has metatable");
681
686b73503ce8 Add test for previous commit
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 end
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
28
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
29 function stanza(stanza)
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
30 local s = stanza("foo", { xmlns = "myxmlns", a = "attr-a" });
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
31 assert_equal(s.name, "foo");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
32 assert_equal(s.attr.xmlns, "myxmlns");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
33 assert_equal(s.attr.a, "attr-a");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
34
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
35 local s1 = stanza("s1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
36 assert_equal(s1.name, "s1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
37 assert_equal(s1.attr.xmlns, nil);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
38 assert_equal(#s1, 0);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
39 assert_equal(#s1.tags, 0);
7961
ff556d010225 tests: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 7503
diff changeset
40
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
41 s1:tag("child1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
42 assert_equal(#s1.tags, 1);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
43 assert_equal(s1.tags[1].name, "child1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
44
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
45 s1:tag("grandchild1"):up();
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
46 assert_equal(#s1.tags, 1);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
47 assert_equal(s1.tags[1].name, "child1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
48 assert_equal(#s1.tags[1], 1);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
49 assert_equal(s1.tags[1][1].name, "grandchild1");
7961
ff556d010225 tests: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents: 7503
diff changeset
50
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
51 s1:up():tag("child2");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
52 assert_equal(#s1.tags, 2, tostring(s1));
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
53 assert_equal(s1.tags[1].name, "child1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
54 assert_equal(s1.tags[2].name, "child2");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
55 assert_equal(#s1.tags[1], 1);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
56 assert_equal(s1.tags[1][1].name, "grandchild1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
57
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
58 s1:up():text("Hello world");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
59 assert_equal(#s1.tags, 2);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
60 assert_equal(#s1, 3);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
61 assert_equal(s1.tags[1].name, "child1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
62 assert_equal(s1.tags[2].name, "child2");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
63 assert_equal(#s1.tags[1], 1);
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
64 assert_equal(s1.tags[1][1].name, "grandchild1");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
65 end
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
66
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
67 function message(message)
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
68 local m = message();
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
69 assert_equal(m.name, "message");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
70 end
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
71
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
72 function iq(iq)
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
73 local i = iq();
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
74 assert_equal(i.name, "iq");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
75 end
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
76
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
77 function presence(presence)
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
78 local p = presence();
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
79 assert_equal(p.name, "presence");
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
80 end
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
81
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
82 function reply(reply, _M)
7503
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
83 do
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
84 -- Test stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
85 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
86 :tag("child1");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
87 -- Make reply stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
88 local r = reply(s);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
89 assert_equal(r.name, s.name);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
90 assert_equal(r.id, s.id);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
91 assert_equal(r.attr.to, s.attr.from);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
92 assert_equal(r.attr.from, s.attr.to);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
93 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
94 end
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
95
7503
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
96 do
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
97 -- Test stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
98 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
99 :tag("child1");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
100 -- Make reply stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
101 local r = reply(s);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
102 assert_equal(r.name, s.name);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
103 assert_equal(r.id, s.id);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
104 assert_equal(r.attr.to, s.attr.from);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
105 assert_equal(r.attr.from, s.attr.to);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
106 assert_equal(r.attr.type, "result");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
107 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
108 end
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
109
7503
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
110 do
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
111 -- Test stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
112 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "set" })
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
113 :tag("child1");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
114 -- Make reply stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
115 local r = reply(s);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
116 assert_equal(r.name, s.name);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
117 assert_equal(r.id, s.id);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
118 assert_equal(r.attr.to, s.attr.from);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
119 assert_equal(r.attr.from, s.attr.to);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
120 assert_equal(r.attr.type, "result");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
121 assert_equal(#r.tags, 0, "A reply should not include children of the original stanza");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
122 end
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
123 end
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
124
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
125 function error_reply(error_reply, _M)
7503
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
126 do
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
127 -- Test stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
128 local s = _M.stanza("s", { to = "touser", from = "fromuser", id = "123" })
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
129 :tag("child1");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
130 -- Make reply stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
131 local r = error_reply(s);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
132 assert_equal(r.name, s.name);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
133 assert_equal(r.id, s.id);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
134 assert_equal(r.attr.to, s.attr.from);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
135 assert_equal(r.attr.from, s.attr.to);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
136 assert_equal(#r.tags, 1);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
137 end
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
138
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
139 do
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
140 -- Test stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
141 local s = _M.stanza("iq", { to = "touser", from = "fromuser", id = "123", type = "get" })
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
142 :tag("child1");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
143 -- Make reply stanza
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
144 local r = error_reply(s);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
145 assert_equal(r.name, s.name);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
146 assert_equal(r.id, s.id);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
147 assert_equal(r.attr.to, s.attr.from);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
148 assert_equal(r.attr.from, s.attr.to);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
149 assert_equal(r.attr.type, "error");
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
150 assert_equal(#r.tags, 1);
1810f1a4ff05 test_util_stanza: wrap individual test blocks in do-end [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents: 7254
diff changeset
151 end
7254
8aaae816cc7e tests: Expand util.stanza tests
Matthew Wild <mwild1@gmail.com>
parents: 5776
diff changeset
152 end