Skip to content

test: support injected query tests#586

Merged
lewis6991 merged 3 commits intonvim-treesitter:masterfrom
PeterCardenas:support-injected-query-tests
Apr 17, 2025
Merged

test: support injected query tests#586
lewis6991 merged 3 commits intonvim-treesitter:masterfrom
PeterCardenas:support-injected-query-tests

Conversation

@PeterCardenas
Copy link
Copy Markdown
Contributor

@PeterCardenas PeterCardenas commented Apr 13, 2025

The context_spec.lua tests do not cover test files that have injected queries. To cover these, we recursively parse the file to get the injected languages parsed, which then can be used later for the context tests. This PR also includes updating the html test file to take advantage of this capability. I also wanted to update the markdown one, but it appears to break in 0.9.5 and pass in 0.10.2. I would fix it, but I see that we're dropping 0.9.5 support in favor of 0.11.0, so leaving a TODO for now.

Followup to #568

@PeterCardenas PeterCardenas force-pushed the support-injected-query-tests branch from 0102c43 to 53858c4 Compare April 13, 2025 05:39
install_langs(lang)
cmd('edit ' .. test_file)
local bufnr = api.nvim_get_current_buf()
exec_lua(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add some comments around this. At a glance, I have no idea what this code is trying to do.

Also, you should be able to replace the string in exec_lua with a function.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced with a function, a decent chunk stayed in exec_lua but definitely easier to read

@PeterCardenas PeterCardenas force-pushed the support-injected-query-tests branch from 53858c4 to d146548 Compare April 16, 2025 16:16
install_langs(current_lang)

-- Query for injections in the current language, and queue them for installation.
langs_to_check = exec_lua([[
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant you should be able to do:

exec_lua(function()
   ...
end)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@PeterCardenas PeterCardenas force-pushed the support-injected-query-tests branch from d146548 to 496e56e Compare April 16, 2025 16:38
Before we had snapshots to cover injected query tests, but now we can
use the cursor and context markers to test these as well. This will mean
that we might be installing more parsers and parsing more than we should
be, but the higher test coverage is worth it.
@PeterCardenas PeterCardenas force-pushed the support-injected-query-tests branch from 496e56e to bcec2de Compare April 16, 2025 16:46
@PeterCardenas PeterCardenas requested a review from lewis6991 April 17, 2025 09:37
end

setup(function()
lazy_setup(function()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would running busted with --lazy be an option?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

theoretically, but doesn't seem to work for me :/

@lewis6991 lewis6991 merged commit 6daca3a into nvim-treesitter:master Apr 17, 2025
5 checks passed
jugarpeupv pushed a commit to jugarpeupv/nvim-treesitter-context that referenced this pull request Jul 23, 2025
* test: support injected query tests

Before we had snapshots to cover injected query tests, but now we can
use the cursor and context markers to test these as well. This will mean
that we might be installing more parsers and parsing more than we should
be, but the higher test coverage is worth it.

* test: add injected query tests

* chore: support goto for stylua
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants