Skip to content

Commit 21e3358

Browse files
authored
chores: update markdown expectations, regenerate ruby symbols, enable nvim-treesitter main testing (#323)
* chore: Fix markdown tests Recent update to nvim-treesitter breaks aerial.nvim tests. Specifically: - nvim-treesitter/nvim-treesitter@96f55f30433 - tree-sitter-grammars/tree-sitter-markdown@cd705f15912 Manually poking around, the behaviour remains the same * chore: Regenerate ruby symbol snapshots Prior version held a bunch of data written by hand. This commit updates it to avoid false alarms when generating symbols for new or updated queries. Expectations are not changed, only the order of keys in individual tables was updated. * chore: Option to run tests on nvim-treesitter main While nvim-treesitter is not a strict requirement for aerial.nvim, it is used to install parsers and it updates nvim default language to parser assignments with practical values. This commit adds an ability to run tests against `main` branch by providing `--test-main` option to `run_tests.sh`. * chore: Add neorg parser config to main branch Use C++14 compatible compiler when running tests with `--test-main`, otherwise parser compilation will fail.
1 parent 8e4090b commit 21e3358

File tree

5 files changed

+174
-120
lines changed

5 files changed

+174
-120
lines changed

run_tests.sh

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
#!/bin/bash
22
set -e
33

4-
if [ "$1" = "--update" ]; then
4+
NVIM_TREESITTER_BRANCH='master'
5+
6+
for arg in "$@"; do
57
shift
6-
export UPDATE_SYMBOLS=1
7-
if ! command -v jq >/dev/null; then
8-
echo "jq is required for --update. Please install jq"
9-
exit 1
10-
fi
11-
fi
8+
case "$arg" in
9+
'--update')
10+
export UPDATE_SYMBOLS=1
11+
if ! command -v jq >/dev/null; then
12+
echo "jq is required for --update. Please install jq"
13+
exit 1
14+
fi
15+
;;
16+
'--test-main')
17+
NVIM_TREESITTER_BRANCH='main'
18+
;;
19+
*)
20+
set -- "$@" "$arg"
21+
;;
22+
esac
23+
done
1224

1325
mkdir -p ".testenv/config/nvim"
1426
mkdir -p ".testenv/data/nvim"
@@ -19,21 +31,20 @@ PLUGINS=".testenv/data/nvim/site/pack/plugins/start"
1931

2032
if [ ! -e "$PLUGINS/plenary.nvim" ]; then
2133
git clone --depth=1 https://github.com/nvim-lua/plenary.nvim.git "$PLUGINS/plenary.nvim"
22-
else
23-
(cd "$PLUGINS/plenary.nvim" && git pull)
2434
fi
2535
if [ ! -e "$PLUGINS/nvim-treesitter" ]; then
26-
git clone --depth=1 https://github.com/nvim-treesitter/nvim-treesitter.git "$PLUGINS/nvim-treesitter"
27-
else
28-
(cd "$PLUGINS/nvim-treesitter" && git pull)
36+
git clone --depth=1 --no-single-branch https://github.com/nvim-treesitter/nvim-treesitter.git "$PLUGINS/nvim-treesitter"
2937
fi
3038

31-
XDG_CONFIG_HOME=".testenv/config" \
32-
XDG_DATA_HOME=".testenv/data" \
33-
XDG_STATE_HOME=".testenv/state" \
34-
XDG_RUNTIME_DIR=".testenv/run" \
35-
XDG_CACHE_HOME=".testenv/cache" \
36-
nvim --headless -u tests/minimal_init.lua \
37-
-c "TSUpdateSync" \
38-
-c "PlenaryBustedDirectory ${1-tests} { minimal_init = './tests/minimal_init.lua' }"
39+
(cd "$PLUGINS/plenary.nvim" && git pull)
40+
(cd "$PLUGINS/nvim-treesitter" && git checkout ${NVIM_TREESITTER_BRANCH} && git pull)
41+
42+
export XDG_CONFIG_HOME=".testenv/config"
43+
export XDG_DATA_HOME=".testenv/data"
44+
export XDG_STATE_HOME=".testenv/state"
45+
export XDG_RUNTIME_DIR=".testenv/run"
46+
export XDG_CACHE_HOME=".testenv/cache"
47+
48+
nvim --headless -u tests/minimal_init.lua \
49+
-c "RunTests ${1-tests}"
3950
echo "Success"

tests/minimal_init.lua

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,52 @@ for lang, _ in vim.fs.dir("queries") do
2020
table.insert(langs, lang)
2121
end
2222
end
23-
require("nvim-treesitter.configs").setup({
24-
ensure_installed = langs,
25-
sync_install = true,
26-
})
27-
-- this needs to be run a second time to make tests behave
28-
require("nvim-treesitter").setup()
23+
local master_nvim_ts, configs = pcall(require, "nvim-treesitter.configs")
24+
if master_nvim_ts then
25+
configs.setup({
26+
ensure_installed = langs,
27+
sync_install = true,
28+
})
29+
-- this needs to be run a second time to make tests behave
30+
require("nvim-treesitter").setup()
31+
32+
vim.api.nvim_create_user_command("RunTests", function(opts)
33+
local path = opts.fargs[1] or "tests"
34+
require("plenary.test_harness").test_directory(
35+
path,
36+
{ minimal_init = "./tests/minimal_init.lua" }
37+
)
38+
end, { nargs = "?" })
39+
else
40+
-- Use compiler that includes c++14 features by default
41+
-- If `cc` doesn't implement those, override it for tests run with
42+
-- `CC=gcc-13 ./run_tests.sh`
43+
local parser_config = require("nvim-treesitter.parsers").configs
44+
parser_config.norg = {
45+
install_info = {
46+
url = "https://github.com/nvim-neorg/tree-sitter-norg",
47+
files = { "src/parser.c", "src/scanner.cc" },
48+
branch = "main",
49+
},
50+
tier = 3,
51+
}
52+
53+
vim.api.nvim_create_user_command("RunTests", function(opts)
54+
local path = opts.fargs[1] or "tests"
55+
require("nvim-treesitter.install").install(langs, { skip = { installed = true } }, function()
56+
vim.schedule(function()
57+
require("plenary.test_harness").test_directory(
58+
path,
59+
-- nvim-treesitter `main` sets up some useful filetype mappings
60+
-- as a plugin, which doesn't get executed by plenary buster
61+
-- when running with `minimal_init`
62+
--
63+
-- While this can be circumvented by setting all the associations
64+
-- in the init, for some reason they don't get picked up by the
65+
-- time a spec gets executed, leading to false negatives
66+
{ init = "./tests/minimal_init.lua" }
67+
)
68+
end)
69+
end)
70+
end, { nargs = "?" })
71+
end

tests/navigation_spec.lua

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ a.describe("navigation", function()
5353
vim.api.nvim_win_set_cursor(0, { 1, 0 })
5454
aerial.select({ index = 2 })
5555
local cursor = vim.api.nvim_win_get_cursor(0)
56-
assert.are.same({ 3, 1 }, cursor)
56+
assert.are.same({ 3, 2 }, cursor)
5757
end)
5858

5959
a.it("in aerial window jumps to location", function()
@@ -63,7 +63,7 @@ a.describe("navigation", function()
6363
assert.equals("aerial", vim.bo.filetype)
6464
aerial.select({ index = 2 })
6565
local cursor = vim.api.nvim_win_get_cursor(0)
66-
assert.are.same({ 3, 1 }, cursor)
66+
assert.are.same({ 3, 2 }, cursor)
6767
end)
6868

6969
a.it("in aerial window uses cursor position as index", function()
@@ -75,7 +75,7 @@ a.describe("navigation", function()
7575
vim.api.nvim_win_set_cursor(0, { 3, 0 })
7676
aerial.select()
7777
local cursor = vim.api.nvim_win_get_cursor(0)
78-
assert.are.same({ 5, 1 }, cursor)
78+
assert.are.same({ 5, 2 }, cursor)
7979
end)
8080

8181
a.it("doesn't have to jump", function()
@@ -92,7 +92,7 @@ a.describe("navigation", function()
9292
assert.equals("aerial", vim.bo.filetype)
9393
-- The source window cursor should be updated
9494
local cursor = vim.api.nvim_win_get_cursor(winid)
95-
assert.are.same({ 5, 1 }, cursor)
95+
assert.are.same({ 5, 2 }, cursor)
9696
end)
9797

9898
a.it("can open a new split when jumping", function()
@@ -111,7 +111,7 @@ a.describe("navigation", function()
111111
-- Source window cursor should be the same
112112
assert.are.same({ 1, 0 }, vim.api.nvim_win_get_cursor(winid))
113113
-- Split window cursor should be updated
114-
assert.are.same({ 5, 1 }, vim.api.nvim_win_get_cursor(0))
114+
assert.are.same({ 5, 2 }, vim.api.nvim_win_get_cursor(0))
115115
end)
116116
end)
117117

@@ -121,47 +121,47 @@ a.describe("navigation", function()
121121
vim.api.nvim_win_set_cursor(0, { 1, 2 })
122122
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
123123
aerial.next()
124-
assert.are.same({ 3, 2 }, vim.api.nvim_win_get_cursor(0))
124+
assert.are.same({ 3, 3 }, vim.api.nvim_win_get_cursor(0))
125125
end)
126126

127127
a.it("can go to next N symbol", function()
128128
create_md_buf(markdown_nested_content)
129129
vim.api.nvim_win_set_cursor(0, { 1, 2 })
130130
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
131131
aerial.next(2)
132-
assert.are.same({ 5, 2 }, vim.api.nvim_win_get_cursor(0))
132+
assert.are.same({ 5, 3 }, vim.api.nvim_win_get_cursor(0))
133133
end)
134134

135135
a.it("can go to prev symbol", function()
136136
create_md_buf(markdown_nested_content)
137137
vim.api.nvim_win_set_cursor(0, { 3, 2 })
138138
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
139139
aerial.prev()
140-
assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
140+
assert.are.same({ 1, 2 }, vim.api.nvim_win_get_cursor(0))
141141
end)
142142

143143
a.it("can go to prev N symbol", function()
144144
create_md_buf(markdown_nested_content)
145145
vim.api.nvim_win_set_cursor(0, { 5, 2 })
146146
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
147147
aerial.prev(2)
148-
assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
148+
assert.are.same({ 1, 2 }, vim.api.nvim_win_get_cursor(0))
149149
end)
150150

151151
a.it("can go up and backwards in the tree", function()
152152
create_md_buf(markdown_nested_content)
153153
vim.api.nvim_win_set_cursor(0, { 5, 2 })
154154
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
155155
aerial.prev_up()
156-
assert.are.same({ 1, 1 }, vim.api.nvim_win_get_cursor(0))
156+
assert.are.same({ 1, 2 }, vim.api.nvim_win_get_cursor(0))
157157
end)
158158

159159
a.it("can go up and forwards in the tree", function()
160160
create_md_buf(markdown_nested_content)
161161
vim.api.nvim_win_set_cursor(0, { 3, 2 })
162162
window.update_position() -- Not sure why the CursorMoved autocmd doesn't fire
163163
aerial.next_up()
164-
assert.are.same({ 7, 1 }, vim.api.nvim_win_get_cursor(0))
164+
assert.are.same({ 7, 2 }, vim.api.nvim_win_get_cursor(0))
165165
end)
166166
end)
167167
end)

tests/symbols/markdown_test.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lnum": 3,
1111
"name": "Title 2",
1212
"selection_range": {
13-
"col": 2,
13+
"col": 3,
1414
"end_col": 10,
1515
"end_lnum": 3,
1616
"lnum": 3
@@ -25,7 +25,7 @@
2525
"lnum": 1,
2626
"name": "Title 1",
2727
"selection_range": {
28-
"col": 1,
28+
"col": 2,
2929
"end_col": 9,
3030
"end_lnum": 1,
3131
"lnum": 1
@@ -44,7 +44,7 @@
4444
"lnum": 13,
4545
"name": "Title 5",
4646
"selection_range": {
47-
"col": 4,
47+
"col": 5,
4848
"end_col": 12,
4949
"end_lnum": 13,
5050
"lnum": 13
@@ -59,7 +59,7 @@
5959
"lnum": 7,
6060
"name": "Title 4",
6161
"selection_range": {
62-
"col": 3,
62+
"col": 4,
6363
"end_col": 11,
6464
"end_lnum": 7,
6565
"lnum": 7
@@ -74,7 +74,7 @@
7474
"lnum": 5,
7575
"name": "Title 3",
7676
"selection_range": {
77-
"col": 1,
77+
"col": 2,
7878
"end_col": 9,
7979
"end_lnum": 5,
8080
"lnum": 5

0 commit comments

Comments
 (0)