Files
ale/test/lua/ale_env_spec.lua
w0rp bd591d47f2 Add basic Lua ALE functions and test coverage
Ensure that basic ALE functions `ale.var`, `ale.escape`, and `ale.env`
are available in Lua. Cover all Lua code so far with busted tests,
fixing bugs where ALE variables can be set with Boolean values instead
of numbers. Document all functionality so far.
2025-03-27 12:40:11 +00:00

57 lines
1.5 KiB
Lua

local eq = assert.are.same
local ale = require("ale")
describe("ale.env", function()
local is_win32 = false
setup(function()
_G.vim = {
o = setmetatable({}, {
__index = function(_, key)
if key == "shell" then
if is_win32 then
return "cmd.exe"
end
return "bash"
end
return nil
end
}),
fn = {
has = function(feature)
return feature == "win32" and is_win32
end,
-- Mock a very poor version of shellescape() for Unix
-- This shouldn't be called for Windows
shellescape = function(str)
return "'" .. str .. "'"
end,
fnamemodify = function(shell, _)
return shell
end
}
}
end)
teardown(function()
_G.vim = nil
end)
before_each(function()
is_win32 = false
end)
it("should escape values correctly on Unix", function()
eq("name='xxx' ", ale.env('name', 'xxx'))
eq("name='foo bar' ", ale.env('name', 'foo bar'))
end)
it("should escape values correctly on Windows", function()
is_win32 = true
eq('set name=xxx && ', ale.env('name', 'xxx'))
eq('set "name=foo bar" && ', ale.env('name', 'foo bar'))
end)
end)