aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-10-26 15:41:54 +0200
committerKim Alvefur <zash@zash.se>2021-10-26 15:41:54 +0200
commit9a080dc12e5692dcfceaf427a33013085e6f4b72 (patch)
tree266c1d16464ee31f9172152dcff653ab9c61c519
parentf956b07ca0480883c7a050d190b8bc6b1a509d85 (diff)
downloadprosody-9a080dc12e5692dcfceaf427a33013085e6f4b72.tar.gz
prosody-9a080dc12e5692dcfceaf427a33013085e6f4b72.zip
util.dataforms: Scope integer handling tests
So they're separate from the datetime tests, and any future validation tests
-rw-r--r--spec/util_dataforms_spec.lua55
1 files changed, 29 insertions, 26 deletions
diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua
index 16fffb42..426dce33 100644
--- a/spec/util_dataforms_spec.lua
+++ b/spec/util_dataforms_spec.lua
@@ -428,37 +428,40 @@ describe("util.dataforms", function ()
end)
describe("datatype validation", function ()
- local f = dataforms.new {
- {
- name = "number",
- type = "text-single",
- datatype = "xs:integer",
- range_min = -10,
- range_max = 10,
- },
- };
+ describe("integer", function ()
- it("integer roundtrip works", function ()
- local d = f:data(f:form({number = 1}));
- assert.equal(1, d.number);
- end);
+ local f = dataforms.new {
+ {
+ name = "number",
+ type = "text-single",
+ datatype = "xs:integer",
+ range_min = -10,
+ range_max = 10,
+ },
+ };
- it("integer error handling 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);
+ it("roundtrip 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 = 100}));
- assert.not_equal(100, d.number);
- assert.table(e);
- assert.string(e.number);
- end);
+ it("error handling 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);
+
+ it("bounds-cheking work works", function ()
+ local d,e = f:data(f:form({number = 100}));
+ assert.not_equal(100, d.number);
+ assert.table(e);
+ assert.string(e.number);
+ end);
+ end)
describe("datetime", function ()
- local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } } -- luacheck: ignore 431
+ local f = dataforms.new { { name = "when"; type = "text-single"; datatype = "xs:dateTime" } }
it("works", function ()
local x = f:form({ when = 1219439340 });