Software /
code /
prosody
Comparison
spec/util_dataforms_spec.lua @ 11879:b8b889ba8d27
util.dataforms: Scope integer handling tests
So they're separate from the datetime tests, and any future validation
tests
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Tue, 26 Oct 2021 15:41:54 +0200 |
parent | 11878:bf6706057283 |
child | 11880:d30c81b875f2 |
comparison
equal
deleted
inserted
replaced
11878:bf6706057283 | 11879:b8b889ba8d27 |
---|---|
426 assert.equal("1", x:find "field/value#"); | 426 assert.equal("1", x:find "field/value#"); |
427 end); | 427 end); |
428 end) | 428 end) |
429 | 429 |
430 describe("datatype validation", function () | 430 describe("datatype validation", function () |
431 local f = dataforms.new { | 431 describe("integer", function () |
432 { | 432 |
433 name = "number", | 433 local f = dataforms.new { |
434 type = "text-single", | 434 { |
435 datatype = "xs:integer", | 435 name = "number", |
436 range_min = -10, | 436 type = "text-single", |
437 range_max = 10, | 437 datatype = "xs:integer", |
438 }, | 438 range_min = -10, |
439 }; | 439 range_max = 10, |
440 | 440 }, |
441 it("integer roundtrip works", function () | 441 }; |
442 local d = f:data(f:form({number = 1})); | 442 |
443 assert.equal(1, d.number); | 443 it("roundtrip works", function () |
444 end); | 444 local d = f:data(f:form({number = 1})); |
445 | 445 assert.equal(1, d.number); |
446 it("integer error handling works", function () | 446 end); |
447 local d,e = f:data(f:form({number = "nan"})); | 447 |
448 assert.not_equal(1, d.number); | 448 it("error handling works", function () |
449 assert.table(e); | 449 local d,e = f:data(f:form({number = "nan"})); |
450 assert.string(e.number); | 450 assert.not_equal(1, d.number); |
451 end); | 451 assert.table(e); |
452 | 452 assert.string(e.number); |
453 it("works", function () | 453 end); |
454 local d,e = f:data(f:form({number = 100})); | 454 |
455 assert.not_equal(100, d.number); | 455 it("bounds-cheking work works", function () |
456 assert.table(e); | 456 local d,e = f:data(f:form({number = 100})); |
457 assert.string(e.number); | 457 assert.not_equal(100, d.number); |
458 end); | 458 assert.table(e); |
459 assert.string(e.number); | |
460 end); | |
461 end) | |
459 | 462 |
460 describe("datetime", function () | 463 describe("datetime", function () |
461 local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } } -- luacheck: ignore 431 | 464 local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } } |
462 | 465 |
463 it("works", function () | 466 it("works", function () |
464 local x = f:form({ when = 1219439340 }); | 467 local x = f:form({ when = 1219439340 }); |
465 assert.equal("2008-08-22T21:09:00Z", x:find("field/value#")) | 468 assert.equal("2008-08-22T21:09:00Z", x:find("field/value#")) |
466 local d, e = f:data(x); | 469 local d, e = f:data(x); |