diff options
Diffstat (limited to 'tests/query/injection_spec.lua')
| -rw-r--r-- | tests/query/injection_spec.lua | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/tests/query/injection_spec.lua b/tests/query/injection_spec.lua index b10b7450f..28e6c727f 100644 --- a/tests/query/injection_spec.lua +++ b/tests/query/injection_spec.lua @@ -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 |
