aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua/diagnostic_spec.lua
diff options
context:
space:
mode:
authorJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
committerJosh Rahm <joshuarahm@gmail.com>2023-11-30 20:35:25 +0000
commit1b7b916b7631ddf73c38e3a0070d64e4636cb2f3 (patch)
treecd08258054db80bb9a11b1061bb091c70b76926a /test/functional/lua/diagnostic_spec.lua
parenteaa89c11d0f8aefbb512de769c6c82f61a8baca3 (diff)
parent4a8bf24ac690004aedf5540fa440e788459e5e34 (diff)
downloadrneovim-aucmd_textputpost.tar.gz
rneovim-aucmd_textputpost.tar.bz2
rneovim-aucmd_textputpost.zip
Merge remote-tracking branch 'upstream/master' into aucmd_textputpostaucmd_textputpost
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r--test/functional/lua/diagnostic_spec.lua102
1 files changed, 87 insertions, 15 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua
index d364986ad7..f061fac50a 100644
--- a/test/functional/lua/diagnostic_spec.lua
+++ b/test/functional/lua/diagnostic_spec.lua
@@ -79,13 +79,10 @@ describe('vim.diagnostic', function()
]])
end)
- after_each(function()
- clear()
- end)
-
it('creates highlight groups', function()
command('runtime plugin/diagnostic.vim')
eq({
+ 'DiagnosticDeprecated',
'DiagnosticError',
'DiagnosticFloatingError',
'DiagnosticFloatingHint',
@@ -105,6 +102,7 @@ describe('vim.diagnostic', function()
'DiagnosticUnderlineInfo',
'DiagnosticUnderlineOk',
'DiagnosticUnderlineWarn',
+ 'DiagnosticUnnecessary',
'DiagnosticVirtualTextError',
'DiagnosticVirtualTextHint',
'DiagnosticVirtualTextInfo',
@@ -183,6 +181,18 @@ describe('vim.diagnostic', function()
eq(0, #diagnostics)
end)
+ it('always returns a copy of diagnostic tables', function()
+ local result = exec_lua [[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error('Diagnostic #1', 1, 1, 1, 1),
+ })
+ local diag = vim.diagnostic.get()
+ diag[1].col = 10000
+ return vim.diagnostic.get()[1].col == 10000
+ ]]
+ eq(result, false)
+ end)
+
it('resolves buffer number 0 to the current buffer', function()
eq(2, exec_lua [[
vim.api.nvim_set_current_buf(diagnostic_bufnr)
@@ -862,7 +872,7 @@ end)
]])
end)
- it('returns only requested diagnostics when severity is supplied', function()
+ it('returns only requested diagnostics when severity range is supplied', function()
eq({2, 3, 2}, exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
make_error("Error 1", 1, 1, 1, 5),
@@ -884,6 +894,28 @@ end)
]])
end)
+ it('returns only requested diagnostics when severities are supplied', function()
+ eq({1, 1, 2}, exec_lua [[
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
+ make_error("Error 1", 1, 1, 1, 5),
+ make_warning("Warning on Server 1", 1, 1, 2, 3),
+ make_info("Ignored information", 1, 1, 2, 3),
+ make_hint("Here's a hint", 1, 1, 2, 3),
+ })
+
+ return {
+ #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.WARN} }),
+ #vim.diagnostic.get(diagnostic_bufnr, { severity = {vim.diagnostic.severity.ERROR} }),
+ #vim.diagnostic.get(diagnostic_bufnr, {
+ severity = {
+ vim.diagnostic.severity.INFO,
+ vim.diagnostic.severity.WARN,
+ }
+ }),
+ }
+ ]])
+ end)
+
it('allows filtering by line', function()
eq(1, exec_lua [[
vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, {
@@ -1044,7 +1076,7 @@ end)
local virt_text = get_virt_text_extmarks(diagnostic_ns)[1][4].virt_text
local virt_texts = {}
- for i = 2, #virt_text do
+ for i = 2, #virt_text - 1 do
table.insert(virt_texts, (string.gsub(virt_text[i][2], "DiagnosticVirtualText", "")))
end
@@ -1088,7 +1120,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]]
eq(' source x: Some error', result)
@@ -1103,7 +1135,7 @@ end)
}, diagnostic_ns)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]]
eq(' Some error', result)
@@ -1123,7 +1155,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = {extmarks[1][4].virt_text[2][1], extmarks[2][4].virt_text[2][1]}
+ local virt_text = {extmarks[1][4].virt_text[3][1], extmarks[2][4].virt_text[3][1]}
return virt_text
]]
eq(' source x: Some error', result[1])
@@ -1153,8 +1185,8 @@ end)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
- eq(" 👀 Warning", result[1][2][1])
- eq(" 🔥 Error", result[2][2][1])
+ eq(" 👀 Warning", result[1][3][1])
+ eq(" 🔥 Error", result[2][3][1])
end)
it('includes source for formatted diagnostics', function()
@@ -1181,8 +1213,48 @@ end)
local extmarks = get_virt_text_extmarks(diagnostic_ns)
return {extmarks[1][4].virt_text, extmarks[2][4].virt_text}
]]
- eq(" some_linter: 👀 Warning", result[1][2][1])
- eq(" another_linter: 🔥 Error", result[2][2][1])
+ eq(" some_linter: 👀 Warning", result[1][3][1])
+ eq(" another_linter: 🔥 Error", result[2][3][1])
+ end)
+
+ it('can add a prefix to virtual text', function()
+ eq('E Some error', exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = 'E',
+ suffix = '',
+ }
+ })
+
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
+ local prefix = extmarks[1][4].virt_text[2][1]
+ local message = extmarks[1][4].virt_text[3][1]
+ return prefix .. message
+ ]])
+
+ eq('[(1/1) err-code] Some error', exec_lua [[
+ local diagnostics = {
+ make_error('Some error', 0, 0, 0, 0, nil, 'err-code'),
+ }
+
+ vim.diagnostic.set(diagnostic_ns, diagnostic_bufnr, diagnostics, {
+ underline = false,
+ virtual_text = {
+ prefix = function(diag, i, total) return string.format('[(%d/%d) %s]', i, total, diag.code) end,
+ suffix = '',
+ }
+ })
+
+ local extmarks = get_virt_text_extmarks(diagnostic_ns)
+ local prefix = extmarks[1][4].virt_text[2][1]
+ local message = extmarks[1][4].virt_text[3][1]
+ return prefix .. message
+ ]])
end)
it('can add a suffix to virtual text', function()
@@ -1200,7 +1272,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]])
@@ -1218,7 +1290,7 @@ end)
})
local extmarks = get_virt_text_extmarks(diagnostic_ns)
- local virt_text = extmarks[1][4].virt_text[2][1]
+ local virt_text = extmarks[1][4].virt_text[3][1]
return virt_text
]])
end)