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.
This commit is contained in:
w0rp
2025-03-21 23:37:35 +00:00
parent 06f4b6fe25
commit bd591d47f2
16 changed files with 944 additions and 105 deletions

56
test/lua/ale_env_spec.lua Normal file
View File

@@ -0,0 +1,56 @@
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)