mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
ci: add injection tests
This commit is contained in:
parent
c3f73e4b63
commit
a3862c9802
2 changed files with 95 additions and 0 deletions
63
tests/query/injection_spec.lua
Normal file
63
tests/query/injection_spec.lua
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
require "nvim-treesitter.highlight" -- yes, this is necessary to set the hlmap
|
||||
local highlighter = require "vim.treesitter.highlighter"
|
||||
local utils = require "nvim-treesitter.utils"
|
||||
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||
local parsers = require "nvim-treesitter.parsers"
|
||||
|
||||
local function check_assertions(file)
|
||||
local buf = vim.fn.bufadd(file)
|
||||
vim.fn.bufload(file)
|
||||
local lang = parsers.get_buf_lang(buf)
|
||||
assert.same(
|
||||
1,
|
||||
vim.fn.executable "highlight-assertions",
|
||||
'"highlight-assertions" not executable!'
|
||||
.. ' Get it via "cargo install --git https://github.com/theHamsta/highlight-assertions"'
|
||||
)
|
||||
local assertions = vim.fn.json_decode(
|
||||
vim.fn.system(
|
||||
"highlight-assertions -p '" .. utils.get_parser_install_dir() .. "/" .. lang .. ".so'" .. " -s '" .. file .. "'"
|
||||
)
|
||||
)
|
||||
local parser = parsers.get_parser(buf, lang)
|
||||
|
||||
local self = highlighter.new(parser, {})
|
||||
|
||||
for _, assertion in ipairs(assertions) do
|
||||
local row = assertion.position.row
|
||||
local col = assertion.position.column
|
||||
|
||||
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() 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!'
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
describe("injections", function()
|
||||
local files = vim.fn.split(vim.fn.glob "tests/query/injections/**/*.*")
|
||||
for _, file in ipairs(files) do
|
||||
it(file, function()
|
||||
check_assertions(file)
|
||||
end)
|
||||
end
|
||||
end)
|
||||
32
tests/query/injections/yaml/bash-on-github-actions.yml
Normal file
32
tests/query/injections/yaml/bash-on-github-actions.yml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
name: CI
|
||||
on:
|
||||
push:
|
||||
branches: [master]
|
||||
pull_request:
|
||||
branches: [master]
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '16'
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
# ^ bash
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
# ^ bash
|
||||
- name: Parse Petalisp
|
||||
run: |
|
||||
git submodule init
|
||||
git submodule update
|
||||
if (( $(node_modules/tree-sitter-cli/tree-sitter parse test/Petalisp/**/*.lisp -q | wc -l) > 2 )); then # There are 2 known failures (strings that are not format strings but use ~X syntax)
|
||||
exit 1
|
||||
else
|
||||
echo "Successfully parsed Petalisp"
|
||||
fi
|
||||
# ^ bash
|
||||
- name: Run tests
|
||||
run: npm test
|
||||
Loading…
Add table
Add a link
Reference in a new issue