mirror of
https://github.com/dense-analysis/ale.git
synced 2025-12-22 03:51:26 +08:00
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:
51
test/lua/ale_var_spec.lua
Normal file
51
test/lua/ale_var_spec.lua
Normal 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)
|
||||
Reference in New Issue
Block a user