aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/glob_spec.lua8
-rw-r--r--test/functional/lua/version_spec.lua34
-rw-r--r--test/functional/lua/vim_spec.lua112
3 files changed, 123 insertions, 31 deletions
diff --git a/test/functional/lua/glob_spec.lua b/test/functional/lua/glob_spec.lua
index c7ef498008..1eac037575 100644
--- a/test/functional/lua/glob_spec.lua
+++ b/test/functional/lua/glob_spec.lua
@@ -67,18 +67,16 @@ describe('glob', function()
eq(true, match('dir/*/file.txt', 'dir/subdir/file.txt'))
eq(false, match('dir/*/file.txt', 'dir/subdir/subdir/file.txt'))
- -- TODO: The spec does not describe this, but VSCode only interprets ** when it's by
+ -- The spec does not describe this, but VSCode only interprets ** when it's by
-- itself in a path segment, and otherwise interprets ** as consecutive * directives.
- -- The following tests show how this behavior should work, but is not yet fully implemented.
- -- Currently, "a**" parses incorrectly as "a" "**" and "**a" parses correctly as "*" "*" "a".
-- see: https://github.com/microsoft/vscode/blob/eef30e7165e19b33daa1e15e92fa34ff4a5df0d3/src/vs/base/common/glob.ts#L112
eq(true, match('a**', 'abc')) -- '**' should parse as two '*'s when not by itself in a path segment
eq(true, match('**c', 'abc'))
- -- eq(false, match('a**', 'ab')) -- each '*' should still represent at least one character
+ eq(false, match('a**', 'ab')) -- each '*' should still represent at least one character
eq(false, match('**c', 'bc'))
eq(true, match('a**', 'abcd'))
eq(true, match('**d', 'abcd'))
- -- eq(false, match('a**', 'abc/d'))
+ eq(false, match('a**', 'abc/d'))
eq(false, match('**d', 'abc/d'))
end)
diff --git a/test/functional/lua/version_spec.lua b/test/functional/lua/version_spec.lua
index c321421ad0..3bc9e26d41 100644
--- a/test/functional/lua/version_spec.lua
+++ b/test/functional/lua/version_spec.lua
@@ -288,21 +288,55 @@ describe('version', function()
eq(vim.version.last({ v('2.0.0'), v('1.2.3') }), v('2.0.0'))
end)
+ it('le()', function()
+ eq(true, vim.version.le('1', '1'))
+ eq(true, vim.version.le({ 3, 1, 4 }, '3.1.4'))
+ eq(true, vim.version.le('1', '2'))
+ eq(true, vim.version.le({ 0, 7, 4 }, { 3 }))
+ eq(false, vim.version.le({ 3 }, { 0, 7, 4 }))
+ eq(false, vim.version.le({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
+ eq(false, vim.version.le('2', '1'))
+ end)
+
it('lt()', function()
+ eq(false, vim.version.lt('1', '1'))
+ eq(false, vim.version.lt({ 3, 1, 4 }, '3.1.4'))
eq(true, vim.version.lt('1', '2'))
+ eq(true, vim.version.lt({ 0, 7, 4 }, { 3 }))
eq(false, vim.version.lt({ 3 }, { 0, 7, 4 }))
eq(false, vim.version.lt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
+ eq(false, vim.version.lt('2', '1'))
+ end)
+
+ it('ge()', function()
+ eq(true, vim.version.ge('1', '1'))
+ eq(true, vim.version.ge({ 3, 1, 4 }, '3.1.4'))
+ eq(true, vim.version.ge('2', '1'))
+ eq(true, vim.version.ge({ 3 }, { 0, 7, 4 }))
+ eq(true, vim.version.ge({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
+ eq(false, vim.version.ge('1', '2'))
+ eq(false, vim.version.ge({ 0, 7, 4 }, { 3 }))
end)
it('gt()', function()
+ eq(false, vim.version.gt('1', '1'))
+ eq(false, vim.version.gt({ 3, 1, 4 }, '3.1.4'))
eq(true, vim.version.gt('2', '1'))
eq(true, vim.version.gt({ 3 }, { 0, 7, 4 }))
eq(true, vim.version.gt({ major = 3, minor = 3, patch = 0 }, { 3, 2, 0 }))
+ eq(false, vim.version.gt('1', '2'))
+ eq(false, vim.version.gt({ 0, 7, 4 }, { 3 }))
end)
it('eq()', function()
eq(true, vim.version.eq('2', '2'))
eq(true, vim.version.eq({ 3, 1, 0 }, '3.1.0'))
eq(true, vim.version.eq({ major = 3, minor = 3, patch = 0 }, { 3, 3, 0 }))
+ eq(false, vim.version.eq('2', '3'))
+
+ -- semver: v3 == v3.0 == v3.0.0
+ eq(true, vim.version.eq('3', { 3, 0, 0 }))
+ eq(true, vim.version.eq({ 3, 0 }, { 3 }))
+ eq(true, vim.version.eq({ 3, 0, 0 }, { 3 }))
end)
end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 98968f3695..6e05728b0c 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -128,33 +128,93 @@ describe('lua stdlib', function()
eq(1, fn.luaeval('vim.stricmp("\\0C\\0", "\\0B\\0")'))
end)
- it('vim.deprecate', function()
+ local function test_vim_deprecate(current_version)
-- vim.deprecate(name, alternative, version, plugin, backtrace)
- eq(
- dedent [[
- foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated
- This feature will be removed in Nvim version 0.10]],
- exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')
- )
- -- Same message, skipped.
- eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10'))
- -- Don't show error if not hard deprecated
- eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'nil', '5000.0.0'))
- -- When `plugin` is specified, don't show ":help deprecated". #22235
- eq(
- dedent [[
- foo.bar() is deprecated, use zub.wooo{ok=yay} instead.
- This feature will be removed in my-plugin.nvim version 0.3.0]],
- exec_lua(
- 'return vim.deprecate(...)',
- 'foo.bar()',
- 'zub.wooo{ok=yay}',
- '0.3.0',
- 'my-plugin.nvim',
- false
- )
- )
- end)
+ -- See MAINTAIN.md for the soft/hard deprecation policy
+
+ describe(('vim.deprecate [current_version = %s]'):format(current_version), function()
+ before_each(function()
+ -- mock vim.version() behavior, should be pinned for consistent testing
+ exec_lua(
+ [[
+ local current_version_mock = vim.version.parse(...)
+ getmetatable(vim.version).__call = function()
+ return current_version_mock
+ end
+ ]],
+ current_version
+ )
+ end)
+
+ it('when plugin = nil', function()
+ eq(
+ dedent [[
+ foo.bar() is deprecated, use zub.wooo{ok=yay} instead. :help deprecated
+ This feature will be removed in Nvim version 0.10]],
+ exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10')
+ )
+ -- Same message, skipped.
+ eq(vim.NIL, exec_lua('return vim.deprecate(...)', 'foo.bar()', 'zub.wooo{ok=yay}', '0.10'))
+
+ -- Don't show error if not hard-deprecated (only soft-deprecated)
+ eq(
+ vim.NIL,
+ exec_lua('return vim.deprecate(...)', 'foo.baz()', 'foo.better_baz()', '0.12.0')
+ )
+
+ -- Show error if hard-deprecated
+ eq(
+ dedent [[
+ foo.hard_dep() is deprecated, use vim.new_api() instead. :help deprecated
+ This feature will be removed in Nvim version 0.11]],
+ exec_lua('return vim.deprecate(...)', 'foo.hard_dep()', 'vim.new_api()', '0.11')
+ )
+
+ -- To be deleted in the next major version (1.0)
+ eq(
+ dedent [[
+ foo.baz() is deprecated. :help deprecated
+ This feature will be removed in Nvim version 1.0]],
+ exec_lua [[ return vim.deprecate('foo.baz()', nil, '1.0') ]]
+ )
+ end)
+
+ it('when plugin is specified', function()
+ -- When `plugin` is specified, don't show ":help deprecated". #22235
+ eq(
+ dedent [[
+ foo.bar() is deprecated, use zub.wooo{ok=yay} instead.
+ This feature will be removed in my-plugin.nvim version 0.3.0]],
+ exec_lua(
+ 'return vim.deprecate(...)',
+ 'foo.bar()',
+ 'zub.wooo{ok=yay}',
+ '0.3.0',
+ 'my-plugin.nvim',
+ false
+ )
+ )
+
+ -- plugins: no soft deprecation period
+ eq(
+ dedent [[
+ foo.bar() is deprecated, use zub.wooo{ok=yay} instead.
+ This feature will be removed in my-plugin.nvim version 0.11.0]],
+ exec_lua(
+ 'return vim.deprecate(...)',
+ 'foo.bar()',
+ 'zub.wooo{ok=yay}',
+ '0.11.0',
+ 'my-plugin.nvim',
+ false
+ )
+ )
+ end)
+ end)
+ end
+
+ test_vim_deprecate('0.10')
+ test_vim_deprecate('0.10-dev+g0000000')
it('vim.startswith', function()
eq(true, fn.luaeval('vim.startswith("123", "1")'))