Software /
code /
prosody
Comparison
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 |
comparison
equal
deleted
inserted
replaced
9242:68694c1bd960 | 9243:a4c52e304e6f |
---|---|
399 local x = f:form({the_field = "hello"}); | 399 local x = f:form({the_field = "hello"}); |
400 assert.equal("someprefix#the-field", x:find"field@var"); | 400 assert.equal("someprefix#the-field", x:find"field@var"); |
401 assert.equal("hello", x:find"field/value#"); | 401 assert.equal("hello", x:find"field/value#"); |
402 end); | 402 end); |
403 end); | 403 end); |
404 | |
405 describe("validation", function () | |
406 local f = dataforms.new { | |
407 { | |
408 name = "number", | |
409 type = "text-single", | |
410 datatype = "xs:integer", | |
411 }, | |
412 }; | |
413 | |
414 it("works", function () | |
415 local d = f:data(f:form({number = 1})); | |
416 assert.equal(1, d.number); | |
417 end); | |
418 | |
419 it("works", function () | |
420 local d,e = f:data(f:form({number = "nan"})); | |
421 assert.not_equal(1, d.number); | |
422 assert.table(e); | |
423 assert.string(e.number); | |
424 end); | |
425 end); | |
404 end); | 426 end); |
405 | 427 |