diff options
| author | lucario387 <hoangtun0810@gmail.com> | 2023-01-07 19:22:20 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-07 11:22:20 +0100 |
| commit | 85d953449125702c7c11f4a2242c328f7a65fd5b (patch) | |
| tree | 11c2d7a83fd9d267227690622e3eec6a1b01527a /tests/query/injection_spec.lua | |
| parent | fix(utils): swap_nodes calculates correct char_delta (#4110) (diff) | |
| download | nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar.gz nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar.bz2 nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar.lz nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar.xz nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.tar.zst nvim-treesitter-85d953449125702c7c11f4a2242c328f7a65fd5b.zip | |
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
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 |
