diff options
author | Lewis Russell <lewis6991@gmail.com> | 2024-08-11 09:27:48 +0100 |
---|---|---|
committer | Lewis Russell <me@lewisr.dev> | 2024-09-21 16:04:09 +0100 |
commit | e5c174421df3872df0dd3a676609d1e74dfef6a9 (patch) | |
tree | 39354b9db7b9f3ccb9145f52d11574baa4508951 /test/functional/lua/diagnostic_spec.lua | |
parent | a19e89022d8b72ee92bb974100b497f1c79b7765 (diff) | |
download | rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.gz rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.tar.bz2 rneovim-e5c174421df3872df0dd3a676609d1e74dfef6a9.zip |
test: support upvalues in exec_lua
Diffstat (limited to 'test/functional/lua/diagnostic_spec.lua')
-rw-r--r-- | test/functional/lua/diagnostic_spec.lua | 127 |
1 files changed, 69 insertions, 58 deletions
diff --git a/test/functional/lua/diagnostic_spec.lua b/test/functional/lua/diagnostic_spec.lua index 718b9469a3..4ae1146703 100644 --- a/test/functional/lua/diagnostic_spec.lua +++ b/test/functional/lua/diagnostic_spec.lua @@ -1,7 +1,6 @@ local t = require('test.testutil') local n = require('test.functional.testnvim')() -local NIL = vim.NIL local command = n.command local clear = n.clear local exec_lua = n.exec_lua @@ -175,11 +174,11 @@ describe('vim.diagnostic', function() eq(3, #result) eq( 2, - exec_lua(function(result0) + exec_lua(function() return #vim.tbl_filter(function(d) return d.bufnr == _G.diagnostic_bufnr - end, result0) - end, result) + end, result) + end) ) eq('Diagnostic #1', result[1].message) end) @@ -792,7 +791,7 @@ describe('vim.diagnostic', function() --- @return table local function test_enable(legacy) - local result = exec_lua(function(legacy0) + return exec_lua(function() local other_bufnr = vim.api.nvim_create_buf(true, false) vim.api.nvim_win_set_buf(0, _G.diagnostic_bufnr) @@ -823,7 +822,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.disable(_G.diagnostic_bufnr, _G.diagnostic_ns) else vim.diagnostic.enable(false, { bufnr = _G.diagnostic_bufnr, ns_id = _G.diagnostic_ns }) @@ -836,7 +835,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.disable(_G.diagnostic_bufnr, _G.other_ns) else vim.diagnostic.enable(false, { bufnr = _G.diagnostic_bufnr, ns_id = _G.other_ns }) @@ -849,7 +848,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then vim.diagnostic.enable(_G.diagnostic_bufnr, _G.diagnostic_ns) else vim.diagnostic.enable(true, { bufnr = _G.diagnostic_bufnr, ns_id = _G.diagnostic_ns }) @@ -862,7 +861,7 @@ describe('vim.diagnostic', function() + _G.count_extmarks(other_bufnr, _G.diagnostic_ns) ) - if legacy0 then + if legacy then -- Should have no effect vim.diagnostic.disable(other_bufnr, _G.other_ns) else @@ -878,9 +877,7 @@ describe('vim.diagnostic', function() ) return result - end, legacy) - - return result + end) end it('with both buffer and namespace arguments', function() @@ -1052,7 +1049,7 @@ describe('vim.diagnostic', function() it('will not cycle when wrap is off', function() eq( - vim.NIL, + nil, exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Diagnostic #1', 1, 1, 1, 1), @@ -1261,7 +1258,7 @@ describe('vim.diagnostic', function() it('respects wrap parameter', function() eq( - vim.NIL, + nil, exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Diagnostic #2', 4, 4, 4, 4), @@ -1514,12 +1511,14 @@ describe('vim.diagnostic', function() describe('count', function() it('returns actually present severity counts', function() eq( - exec_lua [[return { - [vim.diagnostic.severity.ERROR] = 4, - [vim.diagnostic.severity.WARN] = 3, - [vim.diagnostic.severity.INFO] = 2, - [vim.diagnostic.severity.HINT] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.ERROR] = 4, + [vim.diagnostic.severity.WARN] = 3, + [vim.diagnostic.severity.INFO] = 2, + [vim.diagnostic.severity.HINT] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 2), @@ -1537,10 +1536,12 @@ describe('vim.diagnostic', function() end) ) eq( - exec_lua [[return { - [vim.diagnostic.severity.ERROR] = 2, - [vim.diagnostic.severity.INFO] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.ERROR] = 2, + [vim.diagnostic.severity.INFO] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 2), @@ -1554,11 +1555,17 @@ describe('vim.diagnostic', function() it('returns only requested diagnostics count when severity range is supplied', function() eq( - exec_lua [[return { - { [vim.diagnostic.severity.ERROR] = 1, [vim.diagnostic.severity.WARN] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1, [vim.diagnostic.severity.HINT] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, - }]], + exec_lua(function() + return { + { [vim.diagnostic.severity.ERROR] = 1, [vim.diagnostic.severity.WARN] = 1 }, + { + [vim.diagnostic.severity.WARN] = 1, + [vim.diagnostic.severity.INFO] = 1, + [vim.diagnostic.severity.HINT] = 1, + }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1589,11 +1596,13 @@ describe('vim.diagnostic', function() it('returns only requested diagnostics when severities are supplied', function() eq( - exec_lua [[return { - { [vim.diagnostic.severity.WARN] = 1 }, - { [vim.diagnostic.severity.ERROR] = 1 }, - { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, - }]], + exec_lua(function() + return { + { [vim.diagnostic.severity.WARN] = 1 }, + { [vim.diagnostic.severity.ERROR] = 1 }, + { [vim.diagnostic.severity.WARN] = 1, [vim.diagnostic.severity.INFO] = 1 }, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1624,10 +1633,12 @@ describe('vim.diagnostic', function() it('allows filtering by line', function() eq( - exec_lua [[return { - [vim.diagnostic.severity.WARN] = 1, - [vim.diagnostic.severity.INFO] = 1, - }]], + exec_lua(function() + return { + [vim.diagnostic.severity.WARN] = 1, + [vim.diagnostic.severity.INFO] = 1, + } + end), exec_lua(function() vim.diagnostic.set(_G.diagnostic_ns, _G.diagnostic_bufnr, { _G.make_error('Error 1', 1, 1, 1, 5), @@ -1764,11 +1775,11 @@ describe('vim.diagnostic', function() it('allows filtering by severity', function() local get_extmark_count_with_severity = function(min_severity) - return exec_lua(function(min_severity0) + return exec_lua(function() vim.diagnostic.config({ underline = false, virtual_text = { - severity = { min = min_severity0 }, + severity = { min = min_severity }, }, }) @@ -1777,7 +1788,7 @@ describe('vim.diagnostic', function() }) return _G.count_extmarks(_G.diagnostic_bufnr, _G.diagnostic_ns) - end, min_severity) + end) end -- No messages with Error or higher @@ -2512,7 +2523,7 @@ describe('vim.diagnostic', function() -- End position is exclusive eq( - vim.NIL, + nil, exec_lua(function() local diagnostics = { _G.make_error('Syntax error', 1, 1, 2, 0), @@ -2606,7 +2617,7 @@ describe('vim.diagnostic', function() -- End position is exclusive eq( - vim.NIL, + nil, exec_lua(function() local diagnostics = { _G.make_error('Syntax error', 1, 1, 1, 3), @@ -2851,10 +2862,10 @@ describe('vim.diagnostic', function() it('can filter by severity', function() local count_diagnostics_with_severity = function(min_severity, max_severity) - return exec_lua(function(min_severity0, max_severity0) + return exec_lua(function() vim.diagnostic.config({ float = { - severity = { min = min_severity0, max = max_severity0 }, + severity = { min = min_severity, max = max_severity }, }, }) @@ -2874,7 +2885,7 @@ describe('vim.diagnostic', function() local lines = vim.api.nvim_buf_get_lines(float_bufnr, 0, -1, false) vim.api.nvim_win_close(winnr, true) return #lines - end, min_severity, max_severity) + end) end eq(2, count_diagnostics_with_severity('ERROR')) @@ -3060,7 +3071,7 @@ describe('vim.diagnostic', function() -- open float failed non diagnostic lnum eq( - vim.NIL, + nil, exec_lua(function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) local _, winnr = vim.diagnostic.open_float(0, { header = false }) @@ -3068,7 +3079,7 @@ describe('vim.diagnostic', function() end) ) eq( - vim.NIL, + nil, exec_lua(function() vim.api.nvim_win_set_cursor(0, { 1, 0 }) local _, winnr = vim.diagnostic.open_float(0, { header = false, scope = 'cursor' }) @@ -3180,19 +3191,19 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^(%w+): [^:]+:(%d+):(%d+):(.+)$', { 'severity', 'lnum', 'col', 'message' } ) - end, msg) + end) ) end) it('returns nil if the pattern fails to match', function() eq( - NIL, + nil, exec_lua(function() local msg = 'The answer to life, the universe, and everything is' return vim.diagnostic.match(msg, 'This definitely will not match', {}) @@ -3212,15 +3223,15 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^[^:]+:(%d+):(.+)$', { 'lnum', 'message' }, nil, { severity = vim.diagnostic.severity.INFO } ) - end, msg) + end) ) end) @@ -3236,14 +3247,14 @@ describe('vim.diagnostic', function() } eq( diagnostic, - exec_lua(function(msg0) + exec_lua(function() return vim.diagnostic.match( - msg0, + msg, '^(%d+):(%w+):(.+)$', { 'lnum', 'severity', 'message' }, { FATAL = vim.diagnostic.severity.ERROR } ) - end, msg) + end) ) end) end) |