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:
lucario387 2023-01-07 19:22:20 +09:00 committed by GitHub
parent 0922634d37
commit 85d9534491
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 135 deletions

View file

@ -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