match lowercase true/false

This commit is contained in:
Karol Wypchlo 2022-04-08 13:20:05 +02:00
parent decb62d15a
commit 4e64ddd798
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
2 changed files with 14 additions and 2 deletions

View File

@ -61,11 +61,11 @@ function _M.getenv(name, parse)
-- try to parse as boolean -- try to parse as boolean
if parse == "boolean" then if parse == "boolean" then
if value == "true" or value == "1" then if string.lower(value) == "true" or value == "1" then
return true return true
end end
if value == "false" or value == "0" then if string.lower(value) == "false" or value == "0" then
return false return false
end end

View File

@ -135,6 +135,12 @@ describe("getenv", function()
assert.is_true(utils.getenv("foo", "boolean")) assert.is_true(utils.getenv("foo", "boolean"))
end) end)
it("should parse 'True' string as true", function()
os.getenv.on_call_with("foo").returns("True")
assert.is_true(utils.getenv("foo", "boolean"))
end)
it("should parse '1' string as true", function() it("should parse '1' string as true", function()
os.getenv.on_call_with("foo").returns("1") os.getenv.on_call_with("foo").returns("1")
@ -147,6 +153,12 @@ describe("getenv", function()
assert.is_false(utils.getenv("foo", "boolean")) assert.is_false(utils.getenv("foo", "boolean"))
end) end)
it("should parse 'False' string as false", function()
os.getenv.on_call_with("foo").returns("False")
assert.is_false(utils.getenv("foo", "boolean"))
end)
it("should parse '0' string as false", function() it("should parse '0' string as false", function()
os.getenv.on_call_with("foo").returns("0") os.getenv.on_call_with("foo").returns("0")