aboutsummaryrefslogtreecommitdiff
path: root/test/functional/lua
diff options
context:
space:
mode:
authorJustin M. Keyes <justinkz@gmail.com>2025-01-09 09:26:45 -0800
committerGitHub <noreply@github.com>2025-01-09 09:26:45 -0800
commit7c00e0efbb18e8627ac59eaadf564a9f1b2bafcd (patch)
tree3bd51ffc188db702035a3eec647fa70b3367317c /test/functional/lua
parent0c296ab22484b4c009d119908d1614a6c6d96b2c (diff)
downloadrneovim-7c00e0efbb18e8627ac59eaadf564a9f1b2bafcd.tar.gz
rneovim-7c00e0efbb18e8627ac59eaadf564a9f1b2bafcd.tar.bz2
rneovim-7c00e0efbb18e8627ac59eaadf564a9f1b2bafcd.zip
docs: misc #31867
Diffstat (limited to 'test/functional/lua')
-rw-r--r--test/functional/lua/fs_spec.lua5
-rw-r--r--test/functional/lua/func_memoize_spec.lua142
-rw-r--r--test/functional/lua/vim_spec.lua2
3 files changed, 143 insertions, 6 deletions
diff --git a/test/functional/lua/fs_spec.lua b/test/functional/lua/fs_spec.lua
index 218f9bbc46..6bc1ddbff6 100644
--- a/test/functional/lua/fs_spec.lua
+++ b/test/functional/lua/fs_spec.lua
@@ -340,9 +340,6 @@ describe('vim.fs', function()
end)
describe('normalize()', function()
- -- local function vim.fs.normalize(path, opts)
- -- return exec_lua([[return vim.fs.vim.fs.normalize(...)]], path, opts)
- -- end
it('removes trailing /', function()
eq('/home/user', vim.fs.normalize('/home/user/'))
end)
@@ -389,7 +386,7 @@ describe('vim.fs', function()
eq('D:foo/test', vim.fs.normalize('d:foo/test/', win_opts))
end)
- it('does not change case on paths, see #31833', function()
+ it('always treats paths as case-sensitive #31833', function()
eq('TEST', vim.fs.normalize('TEST', win_opts))
eq('test', vim.fs.normalize('test', win_opts))
eq('C:/FOO/test', vim.fs.normalize('C:/FOO/test', win_opts))
diff --git a/test/functional/lua/func_memoize_spec.lua b/test/functional/lua/func_memoize_spec.lua
new file mode 100644
index 0000000000..ca518ab88d
--- /dev/null
+++ b/test/functional/lua/func_memoize_spec.lua
@@ -0,0 +1,142 @@
+local t = require('test.testutil')
+local n = require('test.functional.testnvim')()
+local clear = n.clear
+local exec_lua = n.exec_lua
+local eq = t.eq
+
+describe('vim.func._memoize', function()
+ before_each(clear)
+
+ it('caches function results based on their parameters', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(1, exec_lua([[return _G.count]]))
+ end)
+
+ it('caches function results using a weak table by default', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat-2', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ ]])
+
+ eq(3, exec_lua([[return _G.count]]))
+ end)
+
+ it('can cache using a strong table', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat-2', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end, false)
+
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ collectgarbage()
+ adder(3, -4)
+ ]])
+
+ eq(1, exec_lua([[return _G.count]]))
+ end)
+
+ it('can clear a single cache entry', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize(function(arg1, arg2)
+ return tostring(arg1) .. '%%' .. tostring(arg2)
+ end, function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder(3, -4)
+ adder:clear(3, -4)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(2, exec_lua([[return _G.count]]))
+ end)
+
+ it('can clear the entire cache', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize(function(arg1, arg2)
+ return tostring(arg1) .. '%%' .. tostring(arg2)
+ end, function(arg1, arg2)
+ _G.count = _G.count + 1
+ return arg1 + arg2
+ end)
+
+ collectgarbage('stop')
+ adder(1, 2)
+ adder(3, -4)
+ adder(1, 2)
+ adder(3, -4)
+ adder(1, 2)
+ adder(3, -4)
+ adder:clear()
+ adder(1, 2)
+ adder(3, -4)
+ collectgarbage('restart')
+ ]])
+
+ eq(4, exec_lua([[return _G.count]]))
+ end)
+
+ it('can cache functions that return nil', function()
+ exec_lua([[
+ _G.count = 0
+
+ local adder = vim.func._memoize('concat', function(arg1, arg2)
+ _G.count = _G.count + 1
+ return nil
+ end)
+
+ collectgarbage('stop')
+ adder(1, 2)
+ adder(1, 2)
+ adder(1, 2)
+ adder(1, 2)
+ adder:clear()
+ adder(1, 2)
+ collectgarbage('restart')
+ ]])
+
+ eq(2, exec_lua([[return _G.count]]))
+ end)
+end)
diff --git a/test/functional/lua/vim_spec.lua b/test/functional/lua/vim_spec.lua
index 9e75861aa0..55e5158596 100644
--- a/test/functional/lua/vim_spec.lua
+++ b/test/functional/lua/vim_spec.lua
@@ -3435,7 +3435,6 @@ stack traceback:
end)
it('can discard input', function()
- clear()
-- discard every other normal 'x' command
exec_lua [[
n_key = 0
@@ -3461,7 +3460,6 @@ stack traceback:
end)
it('callback invalid return', function()
- clear()
-- second key produces an error which removes the callback
exec_lua [[
n_call = 0