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 diff --git a/tests/query/injections/html/test-html-injections.html b/tests/query/injections/html/test-html-injections.html index 536ec8734..4449923c6 100644 --- a/tests/query/injections/html/test-html-injections.html +++ b/tests/query/injections/html/test-html-injections.html @@ -5,38 +5,20 @@ - - - + + + + + + - - - + + + + + +
Test div to test css injections for style attributes diff --git a/tests/query/injections/svelte/test-svelte-injections.svelte b/tests/query/injections/svelte/test-svelte-injections.svelte index a821dd080..5a9a03300 100644 --- a/tests/query/injections/svelte/test-svelte-injections.svelte +++ b/tests/query/injections/svelte/test-svelte-injections.svelte @@ -1,29 +1,14 @@ - - + + + + + - - + + + + +

Test file

diff --git a/tests/query/injections/vue/negative-assertions.vue b/tests/query/injections/vue/negative-assertions.vue new file mode 100644 index 000000000..fdc871919 --- /dev/null +++ b/tests/query/injections/vue/negative-assertions.vue @@ -0,0 +1,4 @@ + + + + diff --git a/tests/query/injections/vue/test-vue-injections.vue b/tests/query/injections/vue/test-vue-injections.vue index c7442a027..4cb4ae215 100644 --- a/tests/query/injections/vue/test-vue-injections.vue +++ b/tests/query/injections/vue/test-vue-injections.vue @@ -1,68 +1,28 @@ - - - - - - - - + + + + + + + + + + + + + + + + + +