Files
ale/test/lua/ale_var_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

52 lines
1.2 KiB
Lua

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)