Annotate

spec/util_dataforms_spec.lua @ 12468:353836684009

net.connect: Fix accumulation of connection attempt references Connection attempts that failed the Happy Eyeballs race were not unreferenced and would accumulate. Tested by inspecting the 'pending_connections_map' after establishing s2s with a s2s target where the IPv6 port has a -j DROP rule causing it to time out and the IPv4 attempt wins the race. Expected is that the losing connection stays around until net.server timeouts kick in where it should be removed. The map table should tend towards being empty during idle times.
author Kim Alvefur <zash@zash.se>
date Wed, 20 Apr 2022 22:41:54 +0200
parent 12387:05c250fa335a
child 12636:e8934ce6ea0f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
1 local dataforms = require "util.dataforms";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
2 local st = require "util.stanza";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
3 local jid = require "util.jid";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
4 local iter = require "util.iterators";
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
5
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
6 describe("util.dataforms", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
7 local some_form, xform;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
8 setup(function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
9 some_form = dataforms.new({
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 title = "form-title",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
11 instructions = "form-instructions",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
12 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
13 type = "hidden",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
14 name = "FORM_TYPE",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
15 value = "xmpp:prosody.im/spec/util.dataforms#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 };
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 {
9046
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
18 type = "fixed";
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
19 value = "Fixed field";
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
20 },
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
21 {
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
22 type = "boolean",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 label = "boolean-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 name = "boolean-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
25 value = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
26 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
27 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
28 type = "fixed",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
29 label = "fixed-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 name = "fixed-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 value = "fixed-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
32 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
33 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
34 type = "hidden",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
35 label = "hidden-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
36 name = "hidden-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 value = "hidden-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
40 type = "jid-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
41 label = "jid-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
42 name = "jid-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
43 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
44 "jid@multi/value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
45 "jid@multi/value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
46 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
47 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
48 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
49 type = "jid-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
50 label = "jid-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
51 name = "jid-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
52 value = "jid@single/value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
53 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
54 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
55 type = "list-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
56 label = "list-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
57 name = "list-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
58 value = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
59 "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
60 "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
61 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
62 options = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
63 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
64 label = "list-multi-option-label#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
65 value = "list-multi-option-value#1",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
66 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
67 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
68 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
69 label = "list-multi-option-label#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
70 value = "list-multi-option-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
71 default = false,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
72 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
73 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
74 label = "list-multi-option-label#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
75 value = "list-multi-option-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
76 default = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
77 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
78 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
79 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
80 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
81 type = "list-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
82 label = "list-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
83 name = "list-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
84 value = "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
85 options = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
86 "list-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
87 "list-single-value#2",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
88 "list-single-value#3",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
89 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
90 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
91 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
92 type = "text-multi",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
93 label = "text-multi-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
94 name = "text-multi-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
95 value = "text\nmulti\nvalue",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
96 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
97 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
98 type = "text-private",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
99 label = "text-private-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
100 name = "text-private-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
101 value = "text-private-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
102 },
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
103 {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
104 type = "text-single",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
105 label = "text-single-label",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
106 name = "text-single-field",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
107 value = "text-single-value",
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
108 },
11026
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
109 {
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
110 -- XEP-0221
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
111 -- TODO Validate the XML produced by this.
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
112 type = "text-single",
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
113 label = "text-single-with-media-label",
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
114 name = "text-single-with-media-field",
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
115 media = {
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
116 height = 24,
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
117 width = 32,
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
118 {
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
119 type = "image/png",
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
120 uri = "data:",
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
121 },
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
122 },
a086825ed73a util.dataforms: Convert media element sizes to avoid error on Lua 5.3
Kim Alvefur <zash@zash.se>
parents: 10512
diff changeset
123 },
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
124 });
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
125 xform = some_form:form();
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
126 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
127
10512
3089086d31fa util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents: 9243
diff changeset
128 it("XML serialization looks like it should", function ()
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
129 assert.truthy(xform);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
130 assert.truthy(st.is_stanza(xform));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
131 assert.equal("x", xform.name);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
132 assert.equal("jabber:x:data", xform.attr.xmlns);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
133 assert.equal("FORM_TYPE", xform:find("field@var"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
134 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", xform:find("field/value#"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
135 local allowed_direct_children = {
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
136 title = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
137 instructions = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
138 field = true,
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
139 }
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
140 for tag in xform:childtags() do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
141 assert.truthy(allowed_direct_children[tag.name], "unknown direct child");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
142 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
143 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
144
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
145 it("produced boolean field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
146 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
147 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
148 if field.attr.var == "boolean-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
149 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
150 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
151 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
152 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
153
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
154 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
155 assert.equal("boolean-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
156 assert.equal("boolean", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
157 assert.equal("boolean-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
158 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
159 local val = f:get_child_text("value");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
160 assert.truthy(val == "true" or val == "1");
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
161 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
162
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
163 it("produced fixed field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
164 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
165 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
166 if field.attr.var == "fixed-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
167 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
168 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
169 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
170 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
171
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
172 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
173 assert.equal("fixed-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
174 assert.equal("fixed", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
175 assert.equal("fixed-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
176 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
177 assert.equal("fixed-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
178 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
179
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
180 it("produced hidden field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
181 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
182 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
183 if field.attr.var == "hidden-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
184 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
185 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
186 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
187 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
188
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
189 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
190 assert.equal("hidden-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
191 assert.equal("hidden", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
192 assert.equal("hidden-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
193 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
194 assert.equal("hidden-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
195 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
196
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
197 it("produced jid-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
198 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
199 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
200 if field.attr.var == "jid-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
201 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
202 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
203 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
204 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
205
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
206 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
207 assert.equal("jid-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
208 assert.equal("jid-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
209 assert.equal("jid-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
210 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
211
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
212 local i = 0;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
213 for value in f:childtags("value") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
214 i = i + 1;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
215 assert.equal(("jid@multi/value#%d"):format(i), value:get_text());
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
216 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
217 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
218
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
219 it("produced jid-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
220 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
221 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
222 if field.attr.var == "jid-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
223 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
224 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
225 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
226 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
227
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
228 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
229 assert.equal("jid-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
230 assert.equal("jid-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
231 assert.equal("jid-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
232 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
233 assert.equal("jid@single/value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
234 assert.truthy(jid.prep(f:get_child_text("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
235 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
236
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
237 it("produced list-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
238 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
239 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
240 if field.attr.var == "list-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
241 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
242 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
243 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
244 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
245
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
246 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
247 assert.equal("list-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
248 assert.equal("list-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
249 assert.equal("list-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
250 assert.equal(2, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
251 assert.equal("list-multi-option-value#1", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
252 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
253 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
254
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
255 it("produced list-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
256 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
257 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
258 if field.attr.var == "list-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
259 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
260 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
261 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
262 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
263
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
264 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
265 assert.equal("list-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
266 assert.equal("list-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
267 assert.equal("list-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
268 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
269 assert.equal("list-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
270 assert.equal(3, iter.count(f:childtags("option")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
271 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
272
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
273 it("produced text-multi field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
274 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
275 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
276 if field.attr.var == "text-multi-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
277 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
278 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
279 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
280 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
281
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
282 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
283 assert.equal("text-multi-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
284 assert.equal("text-multi", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
285 assert.equal("text-multi-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
286 assert.equal(3, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
287 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
288
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
289 it("produced text-private field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
290 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
291 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
292 if field.attr.var == "text-private-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
293 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
294 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
295 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
296 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
297
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
298 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
299 assert.equal("text-private-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
300 assert.equal("text-private", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
301 assert.equal("text-private-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
302 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
303 assert.equal("text-private-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
304 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
305
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
306 it("produced text-single field correctly", function ()
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
307 local f;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
308 for field in xform:childtags("field") do
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
309 if field.attr.var == "text-single-field" then
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
310 f = field;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
311 break;
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
312 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
313 end
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
314
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
315 assert.truthy(st.is_stanza(f));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
316 assert.equal("text-single-field", f.attr.var);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
317 assert.equal("text-single", f.attr.type);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
318 assert.equal("text-single-label", f.attr.label);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
319 assert.equal(1, iter.count(f:childtags("value")));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
320 assert.equal("text-single-value", f:get_child_text("value"));
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
321 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
322
8864
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
323 describe("get_type()", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
324 it("identifes dataforms", function ()
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
325 assert.equal(nil, dataforms.get_type(nil));
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
326 assert.equal(nil, dataforms.get_type(""));
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
327 assert.equal(nil, dataforms.get_type({}));
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
328 assert.equal(nil, dataforms.get_type(st.stanza("no-a-form")));
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
329 assert.equal("xmpp:prosody.im/spec/util.dataforms#1", dataforms.get_type(xform));
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
330 end);
cf2f66b233d1 util.dataforms: Add a simple function for identifying form types
Kim Alvefur <zash@zash.se>
parents: 8862
diff changeset
331 end);
9046
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
332
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
333 describe(":data", function ()
10512
3089086d31fa util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents: 9243
diff changeset
334 it("returns something", function ()
9046
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
335 assert.truthy(some_form:data(xform));
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
336 end);
7cdc718312c8 util.dataforms: Include a fixed field in test
Kim Alvefur <zash@zash.se>
parents: 8864
diff changeset
337 end);
9083
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
338
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
339 describe("issue1177", function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
340 local form_with_stuff;
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
341 setup(function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
342 form_with_stuff = dataforms.new({
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
343 {
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
344 type = "list-single";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
345 name = "abtest";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
346 label = "A or B?";
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
347 options = {
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
348 { label = "A", value = "a", default = true },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
349 { label = "B", value = "b" },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
350 };
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
351 },
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
352 });
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
353 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
354
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
355 it("includes options when value is included", function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
356 local f = form_with_stuff:form({ abtest = "a" });
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
357 assert.truthy(f:find("field/option"));
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
358 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
359
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
360 it("includes options when value is excluded", function ()
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
361 local f = form_with_stuff:form({});
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
362 assert.truthy(f:find("field/option"));
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
363 end);
5d3639e415bd util.dataforms: Add failing test for #1177
Kim Alvefur <zash@zash.se>
parents: 9046
diff changeset
364 end);
9121
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
365
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
366 describe("using current values in place of missing fields", function ()
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
367 it("gets back the previous values when given an empty form", function ()
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
368 local current = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
369 ["list-multi-field"] = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
370 "list-multi-option-value#2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
371 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
372 ["list-single-field"] = "list-single-value#2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
373 ["hidden-field"] = "hidden-value";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
374 ["boolean-field"] = false;
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
375 ["text-multi-field"] = "words\ngo\nhere";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
376 ["jid-single-field"] = "alice@example.com";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
377 ["text-private-field"] = "hunter2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
378 ["text-single-field"] = "text-single-value";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
379 ["jid-multi-field"] = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
380 "bob@example.net";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
381 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
382 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
383 local expect = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
384 -- FORM_TYPE = "xmpp:prosody.im/spec/util.dataforms#1"; -- does this need to be included?
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
385 ["list-multi-field"] = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
386 "list-multi-option-value#2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
387 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
388 ["list-single-field"] = "list-single-value#2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
389 ["hidden-field"] = "hidden-value";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
390 ["boolean-field"] = false;
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
391 ["text-multi-field"] = "words\ngo\nhere";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
392 ["jid-single-field"] = "alice@example.com";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
393 ["text-private-field"] = "hunter2";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
394 ["text-single-field"] = "text-single-value";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
395 ["jid-multi-field"] = {
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
396 "bob@example.net";
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
397 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
398 };
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
399 local data, err = some_form:data(st.stanza("x", {xmlns="jabber:x:data"}), current);
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
400 assert.is.table(data, err);
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
401 assert.same(expect, data, "got back the same data");
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
402 end);
e5eb36ee07a2 util.dataforms: Allow passing the current values to be used in stead of omitted fields
Kim Alvefur <zash@zash.se>
parents: 9083
diff changeset
403 end);
9242
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
404
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
405 describe("field 'var' property", function ()
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
406 it("works as expected", function ()
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
407 local f = dataforms.new {
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
408 {
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
409 var = "someprefix#the-field",
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
410 name = "the_field",
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
411 type = "text-single",
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
412 }
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
413 };
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
414 local x = f:form({the_field = "hello"});
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
415 assert.equal("someprefix#the-field", x:find"field@var");
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
416 assert.equal("hello", x:find"field/value#");
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
417 end);
68694c1bd960 util.dataforms: Allow field names to be different from the 'var' attribute
Kim Alvefur <zash@zash.se>
parents: 9121
diff changeset
418 end);
9243
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
419
11877
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
420 describe("number handling", function()
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
421 it("handles numbers as booleans", function()
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
422 local f = dataforms.new { { name = "boolean"; type = "boolean" } };
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
423 local x = f:form({ boolean = 0 });
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
424 assert.equal("0", x:find "field/value#");
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
425 x = f:form({ boolean = 1 });
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
426 assert.equal("1", x:find "field/value#");
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
427 end);
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
428 end)
593b141ba01c util.dataforms: Coerce number values for boolean fields
Kim Alvefur <zash@zash.se>
parents: 11874
diff changeset
429
10512
3089086d31fa util.dataforms: Improve descriptions in tests
Kim Alvefur <zash@zash.se>
parents: 9243
diff changeset
430 describe("datatype validation", function ()
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
431 describe("integer", function ()
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
432
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
433 local f = dataforms.new {
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
434 {
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
435 name = "number",
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
436 type = "text-single",
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
437 datatype = "xs:integer",
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
438 range_min = -10,
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
439 range_max = 10,
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
440 },
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
441 };
9243
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
442
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
443 it("roundtrip works", function ()
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
444 local d = f:data(f:form({number = 1}));
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
445 assert.equal(1, d.number);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
446 end);
9243
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
447
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
448 it("error handling works", function ()
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
449 local d,e = f:data(f:form({number = "nan"}));
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
450 assert.not_equal(1, d.number);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
451 assert.table(e);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
452 assert.string(e.number);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
453 end);
11070
f7f30a3464fe util.dataforms: Add support for validating (integer) ranges
Kim Alvefur <zash@zash.se>
parents: 11027
diff changeset
454
12387
05c250fa335a Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents: 11880
diff changeset
455 it("bounds-checking work works", function ()
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
456 local d,e = f:data(f:form({number = 100}));
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
457 assert.not_equal(100, d.number);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
458 assert.table(e);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
459 assert.string(e.number);
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
460 end);
11880
d30c81b875f2 util.dataforms: Ensure larger integers are serialized as such
Kim Alvefur <zash@zash.se>
parents: 11879
diff changeset
461
12387
05c250fa335a Spelling: Fix various spelling mistakes (thanks timeless)
Kim Alvefur <zash@zash.se>
parents: 11880
diff changeset
462 it("serializes larger ints okay", function ()
11880
d30c81b875f2 util.dataforms: Ensure larger integers are serialized as such
Kim Alvefur <zash@zash.se>
parents: 11879
diff changeset
463 local x = f:form{number=1125899906842624}
d30c81b875f2 util.dataforms: Ensure larger integers are serialized as such
Kim Alvefur <zash@zash.se>
parents: 11879
diff changeset
464 assert.equal("1125899906842624", x:find("field/value#"))
d30c81b875f2 util.dataforms: Ensure larger integers are serialized as such
Kim Alvefur <zash@zash.se>
parents: 11879
diff changeset
465 end);
d30c81b875f2 util.dataforms: Ensure larger integers are serialized as such
Kim Alvefur <zash@zash.se>
parents: 11879
diff changeset
466
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
467 end)
11874
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
468
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
469 describe("datetime", function ()
11879
b8b889ba8d27 util.dataforms: Scope integer handling tests
Kim Alvefur <zash@zash.se>
parents: 11878
diff changeset
470 local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } }
11874
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
471
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
472 it("works", function ()
11878
bf6706057283 util.dataforms: Turn number values into timestamps for datetime fields
Kim Alvefur <zash@zash.se>
parents: 11877
diff changeset
473 local x = f:form({ when = 1219439340 });
11874
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
474 assert.equal("2008-08-22T21:09:00Z", x:find("field/value#"))
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
475 local d, e = f:data(x);
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
476 assert.is_nil(e);
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
477 assert.same({ when = 1219439340 }, d);
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
478 end);
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
479
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
480 end)
84f4c6957d62 util.dataforms: Add support for datetime field types via XEP-0122
Kim Alvefur <zash@zash.se>
parents: 11070
diff changeset
481
9243
a4c52e304e6f util.dataforms: Add support for XEP-0122: Data Forms Validation
Kim Alvefur <zash@zash.se>
parents: 9242
diff changeset
482 end);
11027
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
483 describe("media element", function ()
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
484 it("produced media element correctly", function ()
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
485 local f;
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
486 for field in xform:childtags("field") do
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
487 if field.attr.var == "text-single-with-media-field" then
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
488 f = field;
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
489 break;
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
490 end
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
491 end
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
492
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
493 assert.truthy(st.is_stanza(f));
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
494 assert.equal("text-single-with-media-field", f.attr.var);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
495 assert.equal("text-single", f.attr.type);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
496 assert.equal("text-single-with-media-label", f.attr.label);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
497 assert.equal(0, iter.count(f:childtags("value")));
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
498
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
499 local m = f:get_child("media", "urn:xmpp:media-element");
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
500 assert.truthy(st.is_stanza(m));
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
501 assert.equal("24", m.attr.height);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
502 assert.equal("32", m.attr.width);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
503 assert.equal(1, iter.count(m:childtags("uri")));
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
504
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
505 local u = m:get_child("uri");
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
506 assert.truthy(st.is_stanza(u));
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
507 assert.equal("image/png", u.attr.type);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
508 assert.equal("data:", u:get_text());
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
509 end);
8ed6c5bdbb21 util.dataforms: Add more XEP-0211 media element test coverage
Kim Alvefur <zash@zash.se>
parents: 11026
diff changeset
510 end);
8862
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
511 end);
900dff5ef498 util.dataforms: Add initial tests
Kim Alvefur <zash@zash.se>
parents:
diff changeset
512