All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
1 local eq = assert.are.same
4 describe("ale.diagnostics.send", function()
7 local diagnostic_set_calls
12 nvim_buf_get_var = function(buffer, key)
13 local buffer_table = buffer_map[buffer] or {}
14 local value = buffer_table[key]
17 error(key .. " is missing")
22 nvim_create_namespace = function()
27 severity = {ERROR = 1, WARN = 2, INFO = 3},
29 return {signs = signs_config}
31 set = function(namespace, bufnr, _diagnostics, opts)
32 table.insert(diagnostic_set_calls, {
33 namespace = namespace,
35 diagnostics = _diagnostics,
40 tbl_extend = function(behavior, ...)
41 assert(behavior == "force", "We should only use `force`")
45 for _, arg in ipairs({...}) do
46 for key, value in pairs(arg) do
56 diagnostics = require("ale.diagnostics")
63 before_each(function()
65 diagnostic_set_calls = {}
70 it("should set an empty list of diagnostics correctly", function()
71 diagnostics.send(7, {})
79 opts = {virtual_text = false}
86 it("should handle basic case with all fields", function()
96 text = "Warning message",
97 linter_name = "eslint",
106 severity = vim.diagnostic.severity.WARN,
108 message = "Warning message",
111 }, diagnostic_set_calls[1].diagnostics)
114 it("should default end_lnum to lnum when missing", function()
115 diagnostics.send(1, {
122 text = "Error message",
123 linter_name = "mylinter",
132 severity = vim.diagnostic.severity.ERROR,
134 message = "Error message",
137 }, diagnostic_set_calls[1].diagnostics)
140 it("should default col to 0 when missing", function()
141 diagnostics.send(1, {
148 text = "Info message",
157 severity = vim.diagnostic.severity.INFO,
159 message = "Info message",
162 }, diagnostic_set_calls[1].diagnostics)
165 it("should ignore non-matching buffers", function()
166 diagnostics.send(1, {
177 eq({}, diagnostic_set_calls[1].diagnostics)
180 for _, set_signs_value in ipairs {1, true} do
181 describe("signs with setting set_signs = " .. tostring(set_signs_value), function()
182 before_each(function()
183 _G.vim.g.ale_set_signs = set_signs_value
184 _G.vim.g.ale_sign_priority = 10
187 it("and global config as `false` should enable signs with the given priority", function()
188 diagnostics.send(7, {})
189 eq({priority = 10}, diagnostic_set_calls[1].opts.signs)
192 it("and global config as a table should enable signs with the given priority", function()
193 signs_config = {foo = "bar", priority = 5}
194 diagnostics.send(7, {})
196 {foo = "bar", priority = 10},
197 diagnostic_set_calls[1].opts.signs
201 it("and global config as a function should enable signs with the given priority", function()
202 signs_config = function()
203 return {foo = "bar", priority = 5}
205 diagnostics.send(7, {})
207 local local_signs = diagnostic_set_calls[1].opts.signs
209 eq("function", type(local_signs))
210 eq({foo = "bar", priority = 10}, local_signs())
215 it("should toggle virtual_text correctly", function()
216 for _, value in ipairs({"all", "2", 2, "current", "1", 1, true}) do
217 diagnostic_set_calls = {}
218 _G.vim.g.ale_virtualtext_cursor = value
219 diagnostics.send(7, {})
221 eq({virtual_text = true}, diagnostic_set_calls[1].opts)
224 for _, value in ipairs({"disabled", "0", 0, false, nil}) do
225 diagnostic_set_calls = {}
226 _G.vim.g.ale_virtualtext_cursor = value
227 diagnostics.send(7, {})
229 eq({virtual_text = false}, diagnostic_set_calls[1].opts)