Software /
code /
prosody
Diff
spec/util_dataforms_spec.lua @ 9243:a4c52e304e6f
util.dataforms: Add support for XEP-0122: Data Forms Validation
Initially only basic validation of xs:integer
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 01 Sep 2018 03:10:09 +0200 |
parent | 9242:68694c1bd960 |
child | 10512:3089086d31fa |
line wrap: on
line diff
--- a/spec/util_dataforms_spec.lua Sat Sep 01 01:24:46 2018 +0200 +++ b/spec/util_dataforms_spec.lua Sat Sep 01 03:10:09 2018 +0200 @@ -401,5 +401,27 @@ 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);