From 9c1528bf2e103e50476f6a3dde68f58135240b79 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 1 Sep 2018 03:10:09 +0200 Subject: util.dataforms: Add support for XEP-0122: Data Forms Validation Initially only basic validation of xs:integer --- spec/util_dataforms_spec.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'spec/util_dataforms_spec.lua') 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); -- cgit v1.2.3