Skip to content

Commit c2dcac2

Browse files
authored
Merge pull request #2 from taigrr/cd/ci-and-test-coverage
test: re-enable CI tests and add coverage for highlight, locations, terminal, commands
2 parents 1ceb778 + ff073e2 commit c2dcac2

5 files changed

Lines changed: 380 additions & 33 deletions

File tree

.github/workflows/ci.yml

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,52 @@
1-
name: Tests
1+
name: CI
22

33
on: [push, pull_request]
44

55
jobs:
6-
# unit_tests:
7-
# name: unit tests
8-
# runs-on: ${{ matrix.os }}
9-
# strategy:
10-
# fail-fast: false
11-
# matrix:
12-
# os: [ubuntu-22.04]
13-
# rev: [nightly, v0.10.0]
14-
#
15-
# steps:
16-
# - uses: actions/checkout@v4
17-
#
18-
# - uses: rhysd/action-setup-vim@v1
19-
# with:
20-
# neovim: true
21-
# version: ${{ matrix.rev }}
22-
#
23-
# - name: Prepare plenary.nvim
24-
# run: |
25-
# git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ../plenary.nvim
26-
#
27-
# - name: Run tests
28-
# run: |
29-
# nvim --version
30-
# make test
6+
unit_tests:
7+
name: tests
8+
runs-on: ${{ matrix.os }}
9+
strategy:
10+
fail-fast: false
11+
matrix:
12+
os: [ubuntu-latest]
13+
rev: [stable, nightly]
3114

32-
lint:
33-
name: stylua
34-
runs-on: ubuntu-22.04
3515
steps:
3616
- uses: actions/checkout@v4
3717

38-
- name: Install stylua
18+
- uses: rhysd/action-setup-vim@v1
19+
with:
20+
neovim: true
21+
version: ${{ matrix.rev }}
22+
23+
- name: Prepare plenary.nvim
3924
run: |
40-
cargo install stylua
25+
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ../plenary.nvim
26+
27+
- name: Update minimal_init for CI
28+
run: |
29+
cat > scripts/minimal_init.vim <<'EOF'
30+
set rtp+=.
31+
set rtp+=../plenary.nvim/
32+
33+
runtime! plugin/plenary.vim
34+
runtime! plugin/neocrush.lua
35+
EOF
4136
42-
- name: Check formatting
37+
- name: Run tests
4338
run: |
44-
make lint
39+
nvim --version
40+
make test
41+
42+
lint:
43+
name: stylua
44+
runs-on: ubuntu-latest
45+
steps:
46+
- uses: actions/checkout@v4
47+
48+
- uses: JohnnyMorganz/stylua-action@v4
49+
with:
50+
token: ${{ secrets.GITHUB_TOKEN }}
51+
version: latest
52+
args: --check lua/ tests/

tests/commands_spec.lua

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---@diagnostic disable: undefined-field
2+
3+
local neocrush = require 'neocrush'
4+
5+
describe('neocrush.commands', function()
6+
before_each(function()
7+
neocrush.setup {}
8+
end)
9+
10+
describe('user commands', function()
11+
it('should register CrushToggle command', function()
12+
local cmds = vim.api.nvim_get_commands {}
13+
assert.is_not_nil(cmds.CrushToggle)
14+
end)
15+
16+
it('should register CrushOpen command', function()
17+
local cmds = vim.api.nvim_get_commands {}
18+
assert.is_not_nil(cmds.CrushOpen)
19+
end)
20+
21+
it('should register CrushClose command', function()
22+
local cmds = vim.api.nvim_get_commands {}
23+
assert.is_not_nil(cmds.CrushClose)
24+
end)
25+
26+
it('should register CrushFocus command', function()
27+
local cmds = vim.api.nvim_get_commands {}
28+
assert.is_not_nil(cmds.CrushFocus)
29+
end)
30+
31+
it('should register CrushWidth command', function()
32+
local cmds = vim.api.nvim_get_commands {}
33+
assert.is_not_nil(cmds.CrushWidth)
34+
end)
35+
36+
it('should register CrushFocusToggle command', function()
37+
local cmds = vim.api.nvim_get_commands {}
38+
assert.is_not_nil(cmds.CrushFocusToggle)
39+
end)
40+
41+
it('should register CrushLogs command', function()
42+
local cmds = vim.api.nvim_get_commands {}
43+
assert.is_not_nil(cmds.CrushLogs)
44+
end)
45+
46+
it('should register CrushCancel command', function()
47+
local cmds = vim.api.nvim_get_commands {}
48+
assert.is_not_nil(cmds.CrushCancel)
49+
end)
50+
51+
it('should register CrushRestart command', function()
52+
local cmds = vim.api.nvim_get_commands {}
53+
assert.is_not_nil(cmds.CrushRestart)
54+
end)
55+
56+
it('should register CrushPaste command', function()
57+
local cmds = vim.api.nvim_get_commands {}
58+
assert.is_not_nil(cmds.CrushPaste)
59+
end)
60+
61+
it('should register CrushCvmReleases command', function()
62+
local cmds = vim.api.nvim_get_commands {}
63+
assert.is_not_nil(cmds.CrushCvmReleases)
64+
end)
65+
66+
it('should register CrushCvmLocal command', function()
67+
local cmds = vim.api.nvim_get_commands {}
68+
assert.is_not_nil(cmds.CrushCvmLocal)
69+
end)
70+
end)
71+
end)

tests/highlight_spec.lua

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---@diagnostic disable: undefined-field
2+
3+
local highlight = require 'neocrush.highlight'
4+
5+
describe('neocrush.highlight', function()
6+
local test_buf
7+
8+
before_each(function()
9+
test_buf = vim.api.nvim_create_buf(false, true)
10+
vim.api.nvim_buf_set_lines(test_buf, 0, -1, false, {
11+
'line one',
12+
'line two',
13+
'line three',
14+
'line four',
15+
'line five',
16+
})
17+
18+
highlight.setup {
19+
highlight_group = 'IncSearch',
20+
highlight_duration = 100,
21+
auto_focus = true,
22+
terminal_width = 80,
23+
terminal_cmd = 'crush',
24+
}
25+
end)
26+
27+
after_each(function()
28+
if test_buf and vim.api.nvim_buf_is_valid(test_buf) then
29+
vim.api.nvim_buf_delete(test_buf, { force = true })
30+
end
31+
end)
32+
33+
describe('flash_range', function()
34+
it('should not error on valid range', function()
35+
assert.has_no.errors(function()
36+
highlight.flash_range(test_buf, 0, 3)
37+
end)
38+
end)
39+
40+
it('should not error on empty range', function()
41+
assert.has_no.errors(function()
42+
highlight.flash_range(test_buf, 2, 2)
43+
end)
44+
end)
45+
46+
it('should clamp end_line to buffer length', function()
47+
assert.has_no.errors(function()
48+
highlight.flash_range(test_buf, 0, 100)
49+
end)
50+
end)
51+
52+
it('should handle invalid buffer gracefully before setup', function()
53+
local h2 = require 'neocrush.highlight'
54+
-- flash_range checks config; with config set it should still not error on invalid buf
55+
assert.has_no.errors(function()
56+
pcall(h2.flash_range, 99999, 0, 1)
57+
end)
58+
end)
59+
end)
60+
61+
describe('install', function()
62+
it('should install the handler', function()
63+
highlight.install()
64+
assert.is_true(highlight.is_installed())
65+
end)
66+
67+
it('should be idempotent', function()
68+
highlight.install()
69+
highlight.install()
70+
assert.is_true(highlight.is_installed())
71+
end)
72+
end)
73+
end)

tests/locations_spec.lua

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---@diagnostic disable: undefined-field
2+
3+
local locations = require 'neocrush.locations'
4+
5+
describe('neocrush.locations', function()
6+
describe('show_quickfix', function()
7+
it('should set quickfix list with items', function()
8+
local items = {
9+
{ filename = 'test.lua', lnum = 10, text = 'some code', note = 'relevant because X' },
10+
{ filename = 'other.lua', lnum = 20, col = 5, text = 'other code' },
11+
}
12+
13+
locations.show_quickfix('Test Locations', items)
14+
15+
local qf = vim.fn.getqflist { title = true, items = true }
16+
assert.are.same('Test Locations', qf.title)
17+
assert.are.same(2, #qf.items)
18+
19+
vim.cmd 'cclose'
20+
end)
21+
22+
it('should use default title when nil', function()
23+
locations.show_quickfix(nil, {
24+
{ filename = 'a.lua', lnum = 1 },
25+
})
26+
27+
local qf = vim.fn.getqflist { title = true }
28+
assert.are.same('AI Locations', qf.title)
29+
30+
vim.cmd 'cclose'
31+
end)
32+
33+
it('should combine note and text in quickfix text field', function()
34+
locations.show_quickfix('Test', {
35+
{ filename = 'a.lua', lnum = 1, text = 'code here', note = 'because reasons' },
36+
})
37+
38+
local qf = vim.fn.getqflist { items = true }
39+
local text = qf.items[1].text
40+
assert.truthy(text:find 'because reasons')
41+
assert.truthy(text:find 'code here')
42+
43+
vim.cmd 'cclose'
44+
end)
45+
46+
it('should handle items with only note', function()
47+
locations.show_quickfix('Test', {
48+
{ filename = 'a.lua', lnum = 1, note = 'just a note' },
49+
})
50+
51+
local qf = vim.fn.getqflist { items = true }
52+
assert.are.same('just a note', qf.items[1].text)
53+
54+
vim.cmd 'cclose'
55+
end)
56+
57+
it('should handle items with only text', function()
58+
locations.show_quickfix('Test', {
59+
{ filename = 'a.lua', lnum = 1, text = 'just text' },
60+
})
61+
62+
local qf = vim.fn.getqflist { items = true }
63+
assert.are.same('just text', qf.items[1].text)
64+
65+
vim.cmd 'cclose'
66+
end)
67+
end)
68+
69+
describe('handler', function()
70+
it('should handle error parameter', function()
71+
-- Should not crash when called with error
72+
assert.has_no.errors(function()
73+
locations.handler('some error', nil, nil, nil)
74+
end)
75+
end)
76+
77+
it('should handle nil params', function()
78+
assert.has_no.errors(function()
79+
locations.handler(nil, nil, nil, nil)
80+
end)
81+
end)
82+
83+
it('should handle empty items', function()
84+
assert.has_no.errors(function()
85+
locations.handler(nil, { items = {} }, nil, nil)
86+
end)
87+
end)
88+
89+
it('should fall back to quickfix when telescope is not available', function()
90+
-- In test env telescope is not available, so it should use quickfix
91+
locations.handler(nil, {
92+
title = 'Handler Test',
93+
items = {
94+
{ filename = 'test.lua', lnum = 5, text = 'hello' },
95+
},
96+
}, nil, nil)
97+
98+
local qf = vim.fn.getqflist { title = true, items = true }
99+
assert.are.same('Handler Test', qf.title)
100+
assert.are.same(1, #qf.items)
101+
102+
vim.cmd 'cclose'
103+
end)
104+
end)
105+
end)

0 commit comments

Comments
 (0)