aboutsummaryrefslogtreecommitdiffstats
path: root/tests/query
diff options
context:
space:
mode:
authorChristian Clason <c.clason@uni-graz.at>2023-06-12 09:54:30 -0600
committerChristian Clason <c.clason@uni-graz.at>2025-05-12 18:43:40 +0200
commit692b051b09935653befdb8f7ba8afdb640adf17b (patch)
tree167162b6b129ae04f68c5735078521a72917c742 /tests/query
parentfeat(c-family): inherit injections (diff)
downloadnvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst
nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'tests/query')
-rw-r--r--tests/query/highlights/lua/test.lua4
-rw-r--r--tests/query/highlights_spec.lua47
-rw-r--r--tests/query/injection_spec.lua38
3 files changed, 48 insertions, 41 deletions
diff --git a/tests/query/highlights/lua/test.lua b/tests/query/highlights/lua/test.lua
index 55818bb74..2261d2e4e 100644
--- a/tests/query/highlights/lua/test.lua
+++ b/tests/query/highlights/lua/test.lua
@@ -14,5 +14,5 @@ next(a)
-- ^ @function.builtin
-- Checking for incorrect hlgroup of injected luap
-string.match(s, "\0%d[^\n]+")
--- ^ @!constant
+string.match(s, '\0%d[^\n]+')
+-- ^ !constant
diff --git a/tests/query/highlights_spec.lua b/tests/query/highlights_spec.lua
index 3bb03d49d..b6a52124a 100644
--- a/tests/query/highlights_spec.lua
+++ b/tests/query/highlights_spec.lua
@@ -1,39 +1,39 @@
-local highlighter = require "vim.treesitter.highlighter"
-local parsers = require "nvim-treesitter.parsers"
+local highlighter = require('vim.treesitter.highlighter')
local ts = vim.treesitter
local COMMENT_NODES = {
- markdown = "html_block",
- haskell = "haddock",
+ markdown = 'html_block',
+ haskell = 'haddock',
}
local function check_assertions(file)
local buf = vim.fn.bufadd(file)
vim.fn.bufload(file)
- local lang = parsers.get_buf_lang(buf)
+ local ft = vim.bo[buf].filetype
+ local lang = vim.treesitter.language.get_lang(ft) or ft
assert.same(
1,
- vim.fn.executable "highlight-assertions",
+ vim.fn.executable('highlight-assertions'),
'"highlight-assertions" not executable!'
.. ' Get it via "cargo install --git https://github.com/theHamsta/highlight-assertions"'
)
- local comment_node = COMMENT_NODES[lang] or "comment"
+ local comment_node = COMMENT_NODES[lang] or 'comment'
local assertions = vim.fn.json_decode(
vim.fn.system(
"highlight-assertions -p '"
- .. vim.api.nvim_get_runtime_file("parser/" .. lang .. ".so", false)[1]
+ .. vim.api.nvim_get_runtime_file('parser/' .. lang .. '.so', false)[1]
.. "' -s '"
.. file
.. "' -c "
.. comment_node
)
)
- local parser = parsers.get_parser(buf, lang)
+ local parser = ts.get_parser(buf, lang)
parser:parse(true)
local self = highlighter.new(parser, {})
- assert.True(#assertions > 0, "No assertions detected!")
+ assert.True(#assertions > 0, 'No assertions detected!')
for _, assertion in ipairs(assertions) do
local row = assertion.position.row
local col = assertion.position.column
@@ -46,7 +46,7 @@ local function check_assertions(file)
return
end
- local root = state.tstree:root()
+ local root = tstree:root()
local root_start_row, _, root_end_row, _ = root:range()
-- Only worry about trees within the line range
@@ -72,21 +72,22 @@ local function check_assertions(file)
assert.is.number(col)
if hl and ts.is_in_node_range(node, row, col) then
local c = query._query.captures[capture] -- name of the capture in the query
- if c ~= nil and c ~= "spell" and c ~= "conceal" then
+ if c ~= nil and c ~= 'spell' and c ~= 'conceal' then
captures[c] = true
highlights[c] = true
end
end
end
- end, true)
- if assertion.expected_capture_name:match "^!" then
+ end)
+ if assertion.expected_capture_name:match('^!') then
assert.Falsy(
- captures[assertion.expected_capture_name:sub(2)] or highlights[assertion.expected_capture_name:sub(2)],
- "Error in at "
+ captures[assertion.expected_capture_name:sub(2)]
+ or highlights[assertion.expected_capture_name:sub(2)],
+ 'Error in at '
.. file
- .. ":"
+ .. ':'
.. (row + 1)
- .. ":"
+ .. ':'
.. (col + 1)
.. ': expected "'
.. assertion.expected_capture_name
@@ -98,11 +99,11 @@ local function check_assertions(file)
else
assert.True(
captures[assertion.expected_capture_name] or highlights[assertion.expected_capture_name],
- "Error in at "
+ 'Error in at '
.. file
- .. ":"
+ .. ':'
.. (row + 1)
- .. ":"
+ .. ':'
.. (col + 1)
.. ': expected "'
.. assertion.expected_capture_name
@@ -115,8 +116,8 @@ local function check_assertions(file)
end
end
-describe("highlight queries", function()
- local files = vim.fn.split(vim.fn.glob "tests/query/highlights/**/*.*")
+describe('highlight queries', function()
+ local files = vim.fn.split(vim.fn.glob('tests/query/highlights/**/*.*'))
for _, file in ipairs(files) do
it(file, function()
check_assertions(file)
diff --git a/tests/query/injection_spec.lua b/tests/query/injection_spec.lua
index 95ad12eec..91096fee4 100644
--- a/tests/query/injection_spec.lua
+++ b/tests/query/injection_spec.lua
@@ -1,24 +1,30 @@
-require "nvim-treesitter.highlight" -- yes, this is necessary to set the hlmap
-local configs = require "nvim-treesitter.configs"
-local parsers = require "nvim-treesitter.parsers"
+local config = require('nvim-treesitter.config')
local ts = vim.treesitter
local function check_assertions(file)
local buf = vim.fn.bufadd(file)
vim.fn.bufload(file)
- local lang = parsers.get_buf_lang(buf)
+ local ft = vim.bo[buf].filetype
+ local lang = vim.treesitter.language.get_lang(ft) or ft
assert.same(
1,
- vim.fn.executable "highlight-assertions",
+ vim.fn.executable('highlight-assertions'),
'"highlight-assertions" not executable!'
.. ' Get it via "cargo install --git https://github.com/theHamsta/highlight-assertions"'
)
local assertions = vim.fn.json_decode(
vim.fn.system(
- "highlight-assertions -p '" .. configs.get_parser_install_dir() .. "/" .. lang .. ".so'" .. " -s '" .. file .. "'"
+ "highlight-assertions -p '"
+ .. config.get_install_dir('parser')
+ .. '/'
+ .. lang
+ .. ".so'"
+ .. " -s '"
+ .. file
+ .. "'"
)
)
- local parser = parsers.get_parser(buf, lang)
+ local parser = ts.get_parser(buf, lang)
local self = parser
local top_level_root = parser:parse(true)[1]:root()
@@ -27,7 +33,7 @@ local function check_assertions(file)
local row = assertion.position.row
local col = assertion.position.column
- local neg_assert = assertion.expected_capture_name:match "^!"
+ local neg_assert = assertion.expected_capture_name:match('^!')
assertion.expected_capture_name = neg_assert and assertion.expected_capture_name:sub(2)
or assertion.expected_capture_name
local found = false
@@ -48,11 +54,11 @@ local function check_assertions(file)
if neg_assert then
assert.False(
found,
- "Error in at "
+ 'Error in at '
.. file
- .. ":"
+ .. ':'
.. (row + 1)
- .. ":"
+ .. ':'
.. (col + 1)
.. ': expected "'
.. assertion.expected_capture_name
@@ -61,11 +67,11 @@ local function check_assertions(file)
else
assert.True(
found,
- "Error in at "
+ 'Error in at '
.. file
- .. ":"
+ .. ':'
.. (row + 1)
- .. ":"
+ .. ':'
.. (col + 1)
.. ': expected "'
.. assertion.expected_capture_name
@@ -75,8 +81,8 @@ local function check_assertions(file)
end
end
-describe("injections", function()
- local files = vim.fn.split(vim.fn.glob "tests/query/injections/**/*.*")
+describe('injections', function()
+ local files = vim.fn.split(vim.fn.glob('tests/query/injections/**/*.*'))
for _, file in ipairs(files) do
it(file, function()
check_assertions(file)