Software /
code /
prosody
Comparison
spec/util_dataforms_spec.lua @ 11070:f7f30a3464fe
util.dataforms: Add support for validating (integer) ranges
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 21 Nov 2019 18:56:43 +0100 |
parent | 11027:8ed6c5bdbb21 |
child | 11874:84f4c6957d62 |
comparison
equal
deleted
inserted
replaced
11069:770a5923e959 | 11070:f7f30a3464fe |
---|---|
421 local f = dataforms.new { | 421 local f = dataforms.new { |
422 { | 422 { |
423 name = "number", | 423 name = "number", |
424 type = "text-single", | 424 type = "text-single", |
425 datatype = "xs:integer", | 425 datatype = "xs:integer", |
426 range_min = -10, | |
427 range_max = 10, | |
426 }, | 428 }, |
427 }; | 429 }; |
428 | 430 |
429 it("integer roundtrip works", function () | 431 it("integer roundtrip works", function () |
430 local d = f:data(f:form({number = 1})); | 432 local d = f:data(f:form({number = 1})); |
432 end); | 434 end); |
433 | 435 |
434 it("integer error handling works", function () | 436 it("integer error handling works", function () |
435 local d,e = f:data(f:form({number = "nan"})); | 437 local d,e = f:data(f:form({number = "nan"})); |
436 assert.not_equal(1, d.number); | 438 assert.not_equal(1, d.number); |
439 assert.table(e); | |
440 assert.string(e.number); | |
441 end); | |
442 | |
443 it("works", function () | |
444 local d,e = f:data(f:form({number = 100})); | |
445 assert.not_equal(100, d.number); | |
437 assert.table(e); | 446 assert.table(e); |
438 assert.string(e.number); | 447 assert.string(e.number); |
439 end); | 448 end); |
440 end); | 449 end); |
441 describe("media element", function () | 450 describe("media element", function () |