From fc677f515fd0fe5c45d54e51f5646f37e204929a Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Tue, 26 Oct 2021 15:15:57 +0200 Subject: util.dataforms: Coerce number values for boolean fields Makes more sense than coercing to a string, which would always be truthy. --- spec/util_dataforms_spec.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'spec') diff --git a/spec/util_dataforms_spec.lua b/spec/util_dataforms_spec.lua index f796b30d..a76a9565 100644 --- a/spec/util_dataforms_spec.lua +++ b/spec/util_dataforms_spec.lua @@ -417,6 +417,16 @@ describe("util.dataforms", function () end); end); + describe("number handling", function() + it("handles numbers as booleans", function() + local f = dataforms.new { { name = "boolean"; type = "boolean" } }; + local x = f:form({ boolean = 0 }); + assert.equal("0", x:find "field/value#"); + x = f:form({ boolean = 1 }); + assert.equal("1", x:find "field/value#"); + end); + end) + describe("datatype validation", function () local f = dataforms.new { { -- cgit v1.2.3