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 7f43666fb3
commit f4af0dc84b
16 changed files with 944 additions and 105 deletions

51
test/lua/ale_var_spec.lua Normal file
View File

@@ -0,0 +1,51 @@
local eq = assert.are.same
local ale = require("ale")
describe("ale.var", function()
local buffer_map
setup(function()
_G.vim = {
api = {
nvim_buf_get_var = function(buffer, key)
local buffer_table = buffer_map[buffer] or {}
local value = buffer_table[key]
if value == nil then
error(key .. " is missing")
end
return value
end,
},
g = {
},
}
end)
teardown(function()
_G.vim = nil
end)
before_each(function()
buffer_map = {}
_G.vim.g = {}
end)
it("should return nil for undefined variables", function()
eq(nil, ale.var(1, "foo"))
end)
it("should return buffer-local values, if set", function()
_G.vim.g.ale_foo = "global-value"
buffer_map[1] = {ale_foo = "buffer-value"}
eq("buffer-value", ale.var(1, "foo"))
end)
it("should return global values, if set", function()
_G.vim.g.ale_foo = "global-value"
eq("global-value", ale.var(1, "foo"))
end)
end)