diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/functional/lua/fs_spec.lua | 2 | ||||
-rw-r--r-- | test/functional/lua/version_spec.lua | 339 | ||||
-rw-r--r-- | test/functional/plugin/lsp/semantic_tokens_spec.lua | 211 | ||||
-rw-r--r-- | test/functional/ui/mode_spec.lua | 22 | ||||
-rw-r--r-- | test/helpers.lua | 8 |
5 files changed, 493 insertions, 89 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua index 03de16c079..da60b5c13b 100644 --- a/test/functional/lua/fs_spec.lua +++ b/test/functional/lua/fs_spec.lua @@ -260,7 +260,7 @@ describe('vim.fs', function() ]], test_source_path), exec_lua([[ local dir = ... - local opts = { path = dir, limit = math.huge } + local opts = { path = dir .. "/contrib", limit = math.huge } return vim.tbl_map(vim.fs.basename, vim.fs.find(function(_, d) return d:match('[\\/]contrib$') end, opts)) ]], test_source_path)) end) diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua new file mode 100644 index 0000000000..b68727ca77 --- /dev/null +++ b/test/functional/lua/version_spec.lua @@ -0,0 +1,339 @@ +local helpers = require('test.functional.helpers')(after_each) +local clear = helpers.clear +local eq = helpers.eq +local exec_lua = helpers.exec_lua +local matches = helpers.matches +local pcall_err = helpers.pcall_err + +local version = require('vim.version') + +local function quote_empty(s) + return tostring(s) == '' and '""' or tostring(s) +end + +describe('version', function() + it('package', function() + clear() + eq({ major = 42, minor = 3, patch = 99 }, exec_lua("return vim.version.parse('v42.3.99')")) + end) + + describe('cmp()', function() + local testcases = { + { + desc = '(v1 < v2)', + v1 = 'v0.0.99', + v2 = 'v9.0.0', + want = -1, + }, + { + desc = '(v1 < v2)', + v1 = 'v0.4.0', + v2 = 'v0.9.99', + want = -1, + }, + { + desc = '(v1 < v2)', + v1 = 'v0.2.8', + v2 = 'v1.0.9', + want = -1, + }, + { + desc = '(v1 == v2)', + v1 = 'v0.0.0', + v2 = 'v0.0.0', + want = 0, + }, + { + desc = '(v1 > v2)', + v1 = 'v9.0.0', + v2 = 'v0.9.0', + want = 1, + }, + { + desc = '(v1 > v2)', + v1 = 'v0.9.0', + v2 = 'v0.0.0', + want = 1, + }, + { + desc = '(v1 > v2)', + v1 = 'v0.0.9', + v2 = 'v0.0.0', + want = 1, + }, + { + desc = '(v1 < v2) when v1 has prerelease', + v1 = 'v1.0.0-alpha', + v2 = 'v1.0.0', + want = -1, + }, + { + desc = '(v1 > v2) when v2 has prerelease', + v1 = '1.0.0', + v2 = '1.0.0-alpha', + want = 1, + }, + { + desc = '(v1 > v2) when v1 has a higher number identifier', + v1 = '1.0.0-2', + v2 = '1.0.0-1', + want = 1, + }, + { + desc = '(v1 < v2) when v2 has a higher number identifier', + v1 = '1.0.0-2', + v2 = '1.0.0-9', + want = -1, + }, + { + desc = '(v1 < v2) when v2 has more identifiers', + v1 = '1.0.0-2', + v2 = '1.0.0-2.0', + want = -1, + }, + { + desc = '(v1 > v2) when v1 has more identifiers', + v1 = '1.0.0-2.0', + v2 = '1.0.0-2', + want = 1, + }, + { + desc = '(v1 == v2) when v2 has same numeric identifiers', + v1 = '1.0.0-2.0', + v2 = '1.0.0-2.0', + want = 0, + }, + { + desc = '(v1 == v2) when v2 has same alphabet identifiers', + v1 = '1.0.0-alpha', + v2 = '1.0.0-alpha', + want = 0, + }, + { + desc = '(v1 < v2) when v2 has an alphabet identifier with higher ASCII sort order', + v1 = '1.0.0-alpha', + v2 = '1.0.0-beta', + want = -1, + }, + { + desc = '(v1 > v2) when v1 has an alphabet identifier with higher ASCII sort order', + v1 = '1.0.0-beta', + v2 = '1.0.0-alpha', + want = 1, + }, + { + desc = '(v1 < v2) when v2 has prerelease and number identifer', + v1 = '1.0.0-alpha', + v2 = '1.0.0-alpha.1', + want = -1, + }, + { + desc = '(v1 > v2) when v1 has prerelease and number identifer', + v1 = '1.0.0-alpha.1', + v2 = '1.0.0-alpha', + want = 1, + }, + { + desc = '(v1 > v2) when v1 has an additional alphabet identifier', + v1 = '1.0.0-alpha.beta', + v2 = '1.0.0-alpha', + want = 1, + }, + { + desc = '(v1 < v2) when v2 has an additional alphabet identifier', + v1 = '1.0.0-alpha', + v2 = '1.0.0-alpha.beta', + want = -1, + }, + { + desc = '(v1 < v2) when v2 has an a first alphabet identifier with higher precedence', + v1 = '1.0.0-alpha.beta', + v2 = '1.0.0-beta', + want = -1, + }, + { + desc = '(v1 > v2) when v1 has an a first alphabet identifier with higher precedence', + v1 = '1.0.0-beta', + v2 = '1.0.0-alpha.beta', + want = 1, + }, + { + desc = '(v1 < v2) when v2 has an additional number identifer', + v1 = '1.0.0-beta', + v2 = '1.0.0-beta.2', + want = -1, + }, + { + desc = '(v1 < v2) when v2 has same first alphabet identifier but has a higher number identifer', + v1 = '1.0.0-beta.2', + v2 = '1.0.0-beta.11', + want = -1, + }, + { + desc = '(v1 < v2) when v2 has higher alphabet precedence', + v1 = '1.0.0-beta.11', + v2 = '1.0.0-rc.1', + want = -1, + }, + } + for _, tc in ipairs(testcases) do + it( + string.format('%d %s (v1 = %s, v2 = %s)', tc.want, tc.desc, tc.v1, tc.v2), + function() + eq(tc.want, version.cmp(tc.v1, tc.v2, { strict = true })) + end + ) + end + end) + + describe('parse()', function() + describe('strict=true', function() + local testcases = { + { + desc = 'version without leading "v"', + version = '10.20.123', + want = { + major = 10, + minor = 20, + patch = 123, + prerelease = nil, + build = nil, + }, + }, + { + desc = 'valid version with leading "v"', + version = 'v1.2.3', + want = { major = 1, minor = 2, patch = 3 }, + }, + { + desc = 'valid version with leading "v" and whitespace', + version = ' v1.2.3', + want = { major = 1, minor = 2, patch = 3 }, + }, + { + desc = 'valid version with leading "v" and trailing whitespace', + version = 'v1.2.3 ', + want = { major = 1, minor = 2, patch = 3 }, + }, + { + desc = 'version with prerelease', + version = '1.2.3-alpha', + want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha' }, + }, + { + desc = 'version with prerelease with additional identifiers', + version = '1.2.3-alpha.1', + want = { major = 1, minor = 2, patch = 3, prerelease = 'alpha.1' }, + }, + { + desc = 'version with build', + version = '1.2.3+build.15', + want = { major = 1, minor = 2, patch = 3, build = 'build.15' }, + }, + { + desc = 'version with prerelease and build', + version = '1.2.3-rc1+build.15', + want = { + major = 1, + minor = 2, + patch = 3, + prerelease = 'rc1', + build = 'build.15', + }, + }, + } + for _, tc in ipairs(testcases) do + it( + string.format('for %q: version = %q', tc.desc, tc.version), + function() + eq(tc.want, version.parse(tc.version, { strict = true })) + end + ) + end + end) + + describe('strict=false', function() + local testcases = { + { + desc = 'version missing patch version', + version = '1.2', + want = { major = 1, minor = 2, patch = 0 }, + }, + { + desc = 'version missing minor and patch version', + version = '1', + want = { major = 1, minor = 0, patch = 0 }, + }, + { + desc = 'version missing patch version with prerelease', + version = '1.1-0', + want = { major = 1, minor = 1, patch = 0, prerelease = '0' }, + }, + { + desc = 'version missing minor and patch version with prerelease', + version = '1-1.0', + want = { major = 1, minor = 0, patch = 0, prerelease = '1.0' }, + }, + } + for _, tc in ipairs(testcases) do + it( + string.format('for %q: version = %q', tc.desc, tc.version), + function() + eq(tc.want, version.parse(tc.version, { strict = false })) + end + ) + end + end) + + describe('invalid semver', function() + local testcases = { + { desc = 'a word', version = 'foo' }, + { desc = 'empty string', version = '' }, + { desc = 'trailing period character', version = '0.0.0.' }, + { desc = 'leading period character', version = '.0.0.0' }, + { desc = 'negative major version', version = '-1.0.0' }, + { desc = 'negative minor version', version = '0.-1.0' }, + { desc = 'negative patch version', version = '0.0.-1' }, + { desc = 'leading invalid string', version = 'foobar1.2.3' }, + { desc = 'trailing invalid string', version = '1.2.3foobar' }, + { desc = 'an invalid prerelease', version = '1.2.3-%?' }, + { desc = 'an invalid build', version = '1.2.3+%?' }, + { desc = 'build metadata before prerelease', version = '1.2.3+build.0-rc1' }, + } + for _, tc in ipairs(testcases) do + it(string.format('(%s): %s', tc.desc, quote_empty(tc.version)), function() + eq(nil, version.parse(tc.version, { strict = true })) + end) + end + end) + + describe('invalid shape', function() + local testcases = { + { desc = 'no parameters' }, + { desc = 'nil', version = nil }, + { desc = 'number', version = 0 }, + { desc = 'float', version = 0.01 }, + { desc = 'table', version = {} }, + } + for _, tc in ipairs(testcases) do + it(string.format('(%s): %s', tc.desc, tostring(tc.version)), function() + local expected = string.format(type(tc.version) == 'string' + and 'invalid version: "%s"' or 'invalid version: %s', tostring(tc.version)) + matches(expected, pcall_err(version.parse, tc.version, { strict = true })) + end) + end + end) + end) + + it('lt()', function() + eq(true, version.lt('1', '2')) + end) + + it('gt()', function() + eq(true, version.gt('2', '1')) + end) + + it('eq()', function() + eq(true, version.eq('2', '2')) + end) +end) diff --git a/test/functional/plugin/lsp/semantic_tokens_spec.lua b/test/functional/plugin/lsp/semantic_tokens_spec.lua index 004fce4983..780d18fce9 100644 --- a/test/functional/plugin/lsp/semantic_tokens_spec.lua +++ b/test/functional/plugin/lsp/semantic_tokens_spec.lua @@ -37,10 +37,12 @@ describe('semantic token highlighting', function() [6] = { foreground = Screen.colors.Blue1 }; [7] = { bold = true, foreground = Screen.colors.DarkCyan }; [8] = { bold = true, foreground = Screen.colors.SlateBlue }; + [9] = { bold = true, foreground = tonumber('0x6a0dad') }; } - command([[ hi link @namespace Type ]]) - command([[ hi link @function Special ]]) - command([[ hi @declaration gui=bold ]]) + command([[ hi link @lsp.type.namespace Type ]]) + command([[ hi link @lsp.type.function Special ]]) + command([[ hi link @lsp.type.comment Comment ]]) + command([[ hi @lsp.mod.declaration gui=bold ]]) end) describe('general', function() @@ -129,6 +131,46 @@ describe('semantic token highlighting', function() ]] } end) + it('use LspTokenUpdate and highlight_token', function() + exec_lua([[ + vim.api.nvim_create_autocmd("LspTokenUpdate", { + callback = function(args) + local token = args.data.token + if token.type == "function" and token.modifiers.declaration then + vim.lsp.semantic_tokens.highlight_token( + token, args.buf, args.data.client_id, "Macro" + ) + end + end, + }) + bufnr = vim.api.nvim_get_current_buf() + vim.api.nvim_win_set_buf(0, bufnr) + client_id = vim.lsp.start({ name = 'dummy', cmd = server.cmd }) + ]]) + + insert(text) + + screen:expect { grid = [[ + #include <iostream> | + | + int {9:main}() | + { | + int {7:x}; | + #ifdef {5:__cplusplus} | + {4:std}::{2:cout} << {2:x} << "\n"; | + {6:#else} | + {6: printf("%d\n", x);} | + {6:#endif} | + } | + ^} | + {1:~ }| + {1:~ }| + {1:~ }| + | + ]] } + + end) + it('buffer is unhighlighted when client is detached', function() exec_lua([[ bufnr = vim.api.nvim_get_current_buf() @@ -580,14 +622,11 @@ describe('semantic token highlighting', function() expected = { { line = 0, - modifiers = { - 'declaration', - 'globalScope', - }, + modifiers = { declaration = true, globalScope = true }, start_col = 6, end_col = 9, type = 'variable', - extmark_added = true, + marked = true, }, }, }, @@ -615,67 +654,67 @@ int main() expected = { { -- main line = 1, - modifiers = { 'declaration', 'globalScope' }, + modifiers = { declaration = true, globalScope = true }, start_col = 4, end_col = 8, type = 'function', - extmark_added = true, + marked = true, }, { -- __cplusplus line = 3, - modifiers = { 'globalScope' }, + modifiers = { globalScope = true }, start_col = 9, end_col = 20, type = 'macro', - extmark_added = true, + marked = true, }, { -- x line = 4, - modifiers = { 'declaration', 'readonly', 'functionScope' }, + modifiers = { declaration = true, readonly = true, functionScope = true }, start_col = 12, end_col = 13, type = 'variable', - extmark_added = true, + marked = true, }, { -- std line = 5, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, start_col = 2, end_col = 5, type = 'namespace', - extmark_added = true, + marked = true, }, { -- cout line = 5, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, start_col = 7, end_col = 11, type = 'variable', - extmark_added = true, + marked = true, }, { -- x line = 5, - modifiers = { 'readonly', 'functionScope' }, + modifiers = { readonly = true, functionScope = true }, start_col = 15, end_col = 16, type = 'variable', - extmark_added = true, + marked = true, }, { -- std line = 5, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, start_col = 20, end_col = 23, type = 'namespace', - extmark_added = true, + marked = true, }, { -- endl line = 5, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, start_col = 25, end_col = 29, type = 'function', - extmark_added = true, + marked = true, }, { -- #else comment #endif line = 6, @@ -683,7 +722,7 @@ int main() start_col = 0, end_col = 7, type = 'comment', - extmark_added = true, + marked = true, }, { line = 7, @@ -691,7 +730,7 @@ int main() start_col = 0, end_col = 11, type = 'comment', - extmark_added = true, + marked = true, }, { line = 8, @@ -699,7 +738,7 @@ int main() start_col = 0, end_col = 8, type = 'comment', - extmark_added = true, + marked = true, }, }, }, @@ -724,23 +763,23 @@ b = "as"]], start_col = 0, end_col = 10, type = 'comment', -- comment - extmark_added = true, + marked = true, }, { line = 1, - modifiers = { 'declaration' }, -- a + modifiers = { declaration = true }, -- a start_col = 6, end_col = 7, type = 'variable', - extmark_added = true, + marked = true, }, { line = 2, - modifiers = { 'static' }, -- b (global) + modifiers = { static = true }, -- b (global) start_col = 0, end_col = 1, type = 'variable', - extmark_added = true, + marked = true, }, }, }, @@ -770,7 +809,7 @@ b = "as"]], start_col = 0, end_col = 3, -- pub type = 'keyword', - extmark_added = true, + marked = true, }, { line = 0, @@ -778,15 +817,15 @@ b = "as"]], start_col = 4, end_col = 6, -- fn type = 'keyword', - extmark_added = true, + marked = true, }, { line = 0, - modifiers = { 'declaration', 'public' }, + modifiers = { declaration = true, public = true }, start_col = 7, end_col = 11, -- main type = 'function', - extmark_added = true, + marked = true, }, { line = 0, @@ -794,7 +833,7 @@ b = "as"]], start_col = 11, end_col = 12, type = 'parenthesis', - extmark_added = true, + marked = true, }, { line = 0, @@ -802,7 +841,7 @@ b = "as"]], start_col = 12, end_col = 13, type = 'parenthesis', - extmark_added = true, + marked = true, }, { line = 0, @@ -810,15 +849,15 @@ b = "as"]], start_col = 14, end_col = 15, type = 'brace', - extmark_added = true, + marked = true, }, { line = 1, - modifiers = { 'controlFlow' }, + modifiers = { controlFlow = true }, start_col = 4, end_col = 9, -- break type = 'keyword', - extmark_added = true, + marked = true, }, { line = 1, @@ -826,7 +865,7 @@ b = "as"]], start_col = 10, end_col = 13, -- rust type = 'unresolvedReference', - extmark_added = true, + marked = true, }, { line = 1, @@ -834,15 +873,15 @@ b = "as"]], start_col = 13, end_col = 13, type = 'semicolon', - extmark_added = true, + marked = true, }, { line = 2, - modifiers = { 'documentation' }, + modifiers = { documentation = true }, start_col = 4, end_col = 11, type = 'comment', -- /// what? - extmark_added = true, + marked = true, }, { line = 3, @@ -850,7 +889,7 @@ b = "as"]], start_col = 0, end_col = 1, type = 'brace', - extmark_added = true, + marked = true, }, }, }, @@ -908,26 +947,26 @@ b = "as"]], { line = 0, modifiers = { - 'declaration', - 'globalScope', + declaration = true, + globalScope = true, }, start_col = 6, end_col = 9, type = 'variable', - extmark_added = true, + marked = true, } }, expected2 = { { line = 1, modifiers = { - 'declaration', - 'globalScope', + declaration = true, + globalScope = true, }, start_col = 6, end_col = 9, type = 'variable', - extmark_added = true, + marked = true, } }, expected_screen1 = function() @@ -1018,55 +1057,55 @@ int main() line = 2, start_col = 4, end_col = 8, - modifiers = { 'declaration', 'globalScope' }, + modifiers = { declaration = true, globalScope = true }, type = 'function', - extmark_added = true, + marked = true, }, { line = 4, start_col = 8, end_col = 9, - modifiers = { 'declaration', 'functionScope' }, + modifiers = { declaration = true, functionScope = true }, type = 'variable', - extmark_added = true, + marked = true, }, { line = 5, start_col = 7, end_col = 18, - modifiers = { 'globalScope' }, + modifiers = { globalScope = true }, type = 'macro', - extmark_added = true, + marked = true, }, { line = 6, start_col = 4, end_col = 7, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, type = 'namespace', - extmark_added = true, + marked = true, }, { line = 6, start_col = 9, end_col = 13, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, type = 'variable', - extmark_added = true, + marked = true, }, { line = 6, start_col = 17, end_col = 18, - extmark_added = true, - modifiers = { 'functionScope' }, + marked = true, + modifiers = { functionScope = true }, type = 'variable', }, { line = 7, start_col = 0, end_col = 5, - extmark_added = true, + marked = true, modifiers = {}, type = 'comment', }, @@ -1076,7 +1115,7 @@ int main() modifiers = {}, start_col = 0, type = 'comment', - extmark_added = true, + marked = true, }, { line = 9, @@ -1084,7 +1123,7 @@ int main() end_col = 6, modifiers = {}, type = 'comment', - extmark_added = true, + marked = true, } }, expected2 = { @@ -1092,63 +1131,63 @@ int main() line = 2, start_col = 4, end_col = 8, - modifiers = { 'declaration', 'globalScope' }, + modifiers = { declaration = true, globalScope = true }, type = 'function', - extmark_added = true, + marked = true, }, { line = 4, start_col = 8, end_col = 9, - modifiers = { 'declaration', 'globalScope' }, + modifiers = { declaration = true, globalScope = true }, type = 'function', - extmark_added = true, + marked = true, }, { line = 5, end_col = 12, start_col = 11, - modifiers = { 'declaration', 'functionScope' }, + modifiers = { declaration = true, functionScope = true }, type = 'variable', - extmark_added = true, + marked = true, }, { line = 6, start_col = 7, end_col = 18, - modifiers = { 'globalScope' }, + modifiers = { globalScope = true }, type = 'macro', - extmark_added = true, + marked = true, }, { line = 7, start_col = 4, end_col = 7, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, type = 'namespace', - extmark_added = true, + marked = true, }, { line = 7, start_col = 9, end_col = 13, - modifiers = { 'defaultLibrary', 'globalScope' }, + modifiers = { defaultLibrary = true, globalScope = true }, type = 'variable', - extmark_added = true, + marked = true, }, { line = 7, start_col = 17, end_col = 18, - extmark_added = true, - modifiers = { 'globalScope' }, + marked = true, + modifiers = { globalScope = true }, type = 'function', }, { line = 8, start_col = 0, end_col = 5, - extmark_added = true, + marked = true, modifiers = {}, type = 'comment', }, @@ -1158,7 +1197,7 @@ int main() modifiers = {}, start_col = 0, type = 'comment', - extmark_added = true, + marked = true, }, { line = 10, @@ -1166,7 +1205,7 @@ int main() end_col = 6, modifiers = {}, type = 'comment', - extmark_added = true, + marked = true, } }, expected_screen1 = function() @@ -1228,12 +1267,12 @@ int main() { line = 0, modifiers = { - 'declaration', + declaration = true, }, start_col = 0, end_col = 6, type = 'variable', - extmark_added = true, + marked = true, } }, expected2 = { diff --git a/test/functional/ui/mode_spec.lua b/test/functional/ui/mode_spec.lua index cf4eb034e0..e870d6f25f 100644 --- a/test/functional/ui/mode_spec.lua +++ b/test/functional/ui/mode_spec.lua @@ -44,7 +44,10 @@ describe('ui mode_change event', function() {0:~ }| | ]], mode="normal"} + end) + -- oldtest: Test_mouse_shape_after_failed_change() + it('is restored to Normal mode after failed "c"', function() screen:try_resize(50, 4) command('set nomodifiable') @@ -65,6 +68,25 @@ describe('ui mode_change event', function() ]], mode="normal"} end) + -- oldtest: Test_mouse_shape_after_cancelling_gr() + it('is restored to Normal mode after cancelling "gr"', function() + feed('gr') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]], mode="replace"} + + feed('<Esc>') + screen:expect{grid=[[ + ^ | + {0:~ }| + {0:~ }| + | + ]], mode="normal"} + end) + it('works in insert mode', function() feed('i') screen:expect{grid=[[ diff --git a/test/helpers.lua b/test/helpers.lua index 117b6b4aaa..008b91073f 100644 --- a/test/helpers.lua +++ b/test/helpers.lua @@ -371,8 +371,12 @@ end local tests_skipped = 0 -function module.check_cores(app, force) - app = app or 'build/bin/nvim' +function module.check_cores(app, force) -- luacheck: ignore + -- Temporary workaround: skip core check as it interferes with CI. + if true then + return + end + app = app or 'build/bin/nvim' -- luacheck: ignore local initial_path, re, exc_re local gdb_db_cmd = 'gdb -n -batch -ex "thread apply all bt full" "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' local lldb_db_cmd = 'lldb -Q -o "bt all" -f "$_NVIM_TEST_APP" -c "$_NVIM_TEST_CORE"' |