aboutsummaryrefslogtreecommitdiff
path: root/test/functional/treesitter/query_spec.lua
diff options
context:
space:
mode:
authorbfredl <bjorn.linse@gmail.com>2024-04-29 19:31:59 +0200
committerGitHub <noreply@github.com>2024-04-29 19:31:59 +0200
commita1c9da2d5af002ec5e9eb5ac1c0c61fc12ec4190 (patch)
tree782be8ed4e68780c14edd9912692e1bba192545b /test/functional/treesitter/query_spec.lua
parentca432069eb6f5453acab896acdb8e0363c232629 (diff)
parent0df681a91d6b86395609e6fc40efb4d8623d72c9 (diff)
downloadrneovim-a1c9da2d5af002ec5e9eb5ac1c0c61fc12ec4190.tar.gz
rneovim-a1c9da2d5af002ec5e9eb5ac1c0c61fc12ec4190.tar.bz2
rneovim-a1c9da2d5af002ec5e9eb5ac1c0c61fc12ec4190.zip
Merge pull request #28566 from bfredl/memoize
fix(treesitter): make tests for memoize more robust, also fix memoize to work
Diffstat (limited to 'test/functional/treesitter/query_spec.lua')
-rw-r--r--test/functional/treesitter/query_spec.lua20
1 files changed, 8 insertions, 12 deletions
diff --git a/test/functional/treesitter/query_spec.lua b/test/functional/treesitter/query_spec.lua
index 3dad61d79e..96665ee2e7 100644
--- a/test/functional/treesitter/query_spec.lua
+++ b/test/functional/treesitter/query_spec.lua
@@ -7,7 +7,6 @@ local eq = t.eq
local insert = n.insert
local exec_lua = n.exec_lua
local pcall_err = t.pcall_err
-local is_os = t.is_os
local api = n.api
local fn = n.fn
@@ -72,11 +71,14 @@ void ui_refresh(void)
return exec_lua(
[[
local query, n = ...
- local before = vim.uv.hrtime()
+ local before = vim.api.nvim__stats().ts_query_parse_count
+ collectgarbage("stop")
for i=1, n, 1 do
cquery = vim.treesitter.query.parse("c", ...)
end
- local after = vim.uv.hrtime()
+ collectgarbage("restart")
+ collectgarbage("collect")
+ local after = vim.api.nvim__stats().ts_query_parse_count
return after - before
]],
long_query,
@@ -84,15 +86,9 @@ void ui_refresh(void)
)
end
- local firstrun = q(1)
- local manyruns = q(100)
-
- -- First run should be at least 200x slower than an 100 subsequent runs.
- local factor = is_os('win') and 100 or 200
- assert(
- factor * manyruns < firstrun,
- ('firstrun: %f ms, manyruns: %f ms'):format(firstrun / 1e6, manyruns / 1e6)
- )
+ eq(1, q(1))
+ -- cache is cleared by garbage collection even if valid "cquery" reference is kept around
+ eq(1, q(100))
end)
it('supports query and iter by capture (iter_captures)', function()