aboutsummaryrefslogtreecommitdiffstats
path: root/spec
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2018-09-01 03:10:09 +0200
committerKim Alvefur <zash@zash.se>2018-09-01 03:10:09 +0200
commit080c294fe8e2c1ef03297284365636ba4a37d66b (patch)
treec3b5e65c45bcd1366d6e884ff5420c147a19b015 /spec
parent367e73a610e687ae01a6987023683d3ea9eac805 (diff)
downloadprosody-080c294fe8e2c1ef03297284365636ba4a37d66b.tar.gz
prosody-080c294fe8e2c1ef03297284365636ba4a37d66b.zip
util.dataforms: Add support for XEP-0122: Data Forms Validation
Initially only basic validation of xs:integer
Diffstat (limited to 'spec')
-rw-r--r--spec/util_dataforms_spec.lua22
1 files changed, 22 insertions, 0 deletions
diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua
index 123b9f8a..89759035 100644
--- a/spec/util_dataforms_spec.lua
+++ b/spec/util_dataforms_spec.lua
@@ -401,5 +401,27 @@ describe("util.dataforms", function ()
assert.equal("hello", x:find"field/value#");
end);
end);
+
+ describe("validation", function ()
+ local f = dataforms.new {
+ {
+ name = "number",
+ type = "text-single",
+ datatype = "xs:integer",
+ },
+ };
+
+ it("works", function ()
+ local d = f:data(f:form({number = 1}));
+ assert.equal(1, d.number);
+ end);
+
+ it("works", function ()
+ local d,e = f:data(f:form({number = "nan"}));
+ assert.not_equal(1, d.number);
+ assert.table(e);
+ assert.string(e.number);
+ end);
+ end);
end);