Comparison

spec/util_dataforms_spec.lua @ 11877:593b141ba01c

util.dataforms: Coerce number values for boolean fields Makes more sense than coercing to a string, which would always be truthy.
author Kim Alvefur <zash@zash.se>
date Tue, 26 Oct 2021 15:15:57 +0200
parent 11874:84f4c6957d62
child 11878:bf6706057283
comparison
equal deleted inserted replaced
11876:52a1b885044e 11877:593b141ba01c
415 assert.equal("someprefix#the-field", x:find"field@var"); 415 assert.equal("someprefix#the-field", x:find"field@var");
416 assert.equal("hello", x:find"field/value#"); 416 assert.equal("hello", x:find"field/value#");
417 end); 417 end);
418 end); 418 end);
419 419
420 describe("number handling", function()
421 it("handles numbers as booleans", function()
422 local f = dataforms.new { { name = "boolean"; type = "boolean" } };
423 local x = f:form({ boolean = 0 });
424 assert.equal("0", x:find "field/value#");
425 x = f:form({ boolean = 1 });
426 assert.equal("1", x:find "field/value#");
427 end);
428 end)
429
420 describe("datatype validation", function () 430 describe("datatype validation", function ()
421 local f = dataforms.new { 431 local f = dataforms.new {
422 { 432 {
423 name = "number", 433 name = "number",
424 type = "text-single", 434 type = "text-single",