mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
allow negative assertion in injection tests (#4107)
* tests(vue, svelte): strengthen tests * fix(html, vue, svelte): fix wrong test format * allow negative assertions in injection tests
This commit is contained in:
parent
0922634d37
commit
85d9534491
5 changed files with 84 additions and 135 deletions
|
|
@ -28,33 +28,51 @@ local function check_assertions(file)
|
|||
local row = assertion.position.row
|
||||
local col = assertion.position.column
|
||||
|
||||
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
|
||||
self.tree:for_each_tree(function(tstree, tree)
|
||||
if not tstree then
|
||||
return
|
||||
end
|
||||
|
||||
local root = tstree:root()
|
||||
if
|
||||
ts_utils.is_in_node_range(root, row, col)
|
||||
and assertion.expected_capture_name == tree:lang()
|
||||
and root ~= top_level_root
|
||||
then
|
||||
--- If there are multiple tree with the smallest range possible
|
||||
--- Check all of them to see if they fit or not
|
||||
if not ts_utils.is_in_node_range(root, row, col) or root == top_level_root then
|
||||
return
|
||||
end
|
||||
if assertion.expected_capture_name == tree:lang() then
|
||||
found = true
|
||||
end
|
||||
end, true)
|
||||
assert.True(
|
||||
found,
|
||||
"Error in at "
|
||||
.. file
|
||||
.. ":"
|
||||
.. (row + 1)
|
||||
.. ":"
|
||||
.. (col + 1)
|
||||
.. ': expected "'
|
||||
.. assertion.expected_capture_name
|
||||
.. '" to be injected here!'
|
||||
)
|
||||
if neg_assert then
|
||||
assert.False(
|
||||
found,
|
||||
"Error in at "
|
||||
.. file
|
||||
.. ":"
|
||||
.. (row + 1)
|
||||
.. ":"
|
||||
.. (col + 1)
|
||||
.. ': expected "'
|
||||
.. assertion.expected_capture_name
|
||||
.. '" not to be injected here!'
|
||||
)
|
||||
else
|
||||
assert.True(
|
||||
found,
|
||||
"Error in at "
|
||||
.. file
|
||||
.. ":"
|
||||
.. (row + 1)
|
||||
.. ":"
|
||||
.. (col + 1)
|
||||
.. ': expected "'
|
||||
.. assertion.expected_capture_name
|
||||
.. '" to be injected here!'
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue