Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pablopunk committed Jan 23, 2024
1 parent 4e003cf commit db6051b
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 0 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
name: unit tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
rev: nightly/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
- os: ubuntu-latest
rev: v0.9.0/nvim-linux64.tar.gz
manager: sudo apt-get
packages: -y ripgrep
steps:
- uses: actions/checkout@v3
- run: date +%F > todays-date
- name: Restore from todays cache
uses: actions/cache@v3
with:
path: _neovim
key: ${{ runner.os }}-${{ matrix.rev }}-${{ hashFiles('todays-date') }}

- name: Prepare
run: |
${{ matrix.manager }} update
${{ matrix.manager }} install ${{ matrix.packages }}
test -d _neovim || {
mkdir -p _neovim
curl -sL "https://github.com/neovim/neovim/releases/download/${{ matrix.rev }}" | tar xzf - --strip-components=1 -C "${PWD}/_neovim"
}
mkdir -p ~/.local/share/nvim/lazy
git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/lazy/plenary.nvim
ln -s $(pwd) ~/.local/share/nvim/lazy
- name: Run tests
run: |
export PATH="${PWD}/_neovim/bin:${PATH}"
export VIM="${PWD}/_neovim/share/nvim/runtime"
nvim --version
make test
9 changes: 9 additions & 0 deletions .neoconf.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"neodev": {
"library": {
"plugins": [
"plenary.nvim"
]
}
}
}
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
MINIMAL_INIT := ./scripts/minimal_init.vim

test:
nvim --headless --noplugin -u ${MINIMAL_INIT} \
-c "PlenaryBustedDirectory lua/ { minimal_init = '${MINIMAL_INIT}' }"

55 changes: 55 additions & 0 deletions lua/unclutter/tabline_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
local M = require "unclutter.tabline"

describe("Tabpage section", function()
it("creates tabpage section for multiple tabpages", function()
-- Mock vim.fn.tabpagenr
---@diagnostic disable-next-line: duplicate-set-field
vim.fn.tabpagenr = function(arg)
if arg == "$" then
return 3
end -- total tabpages
return 2 -- current tabpage
end

M.make_tabpage_section()
assert.are.equal(" Tab 2/3 ", M.tabpage_section)
end)

it("creates no tabpage section for a single tabpage", function()
-- Mock vim.fn.tabpagenr
---@diagnostic disable-next-line: duplicate-set-field
vim.fn.tabpagenr = function(arg)
if arg == "$" then
return 1
end
return 1
end

M.make_tabpage_section()
assert.are.equal("", M.tabpage_section)
end)
end)

describe("Buffer management", function()
before_each(function()
M.buffers_to_keep = {}
end)

it("keeps a buffer", function()
M.keep_buffer(1)
assert.is_true(M.is_buffer_kept(1))
end)

it("removes a buffer", function()
M.keep_buffer(1)
M.remove_buffer(1)
assert.is_false(M.is_buffer_kept(1))
end)

it("toggles a buffer", function()
M.toggle_buffer(1)
assert.is_true(M.is_buffer_kept(1))
M.toggle_buffer(1)
assert.is_false(M.is_buffer_kept(1))
end)
end)
6 changes: 6 additions & 0 deletions scripts/minimal_init.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
let plenary_path = stdpath('data') . '/lazy/plenary.nvim/'
execute 'set rtp+=' . plenary_path

runtime! plugin/plenary.vim
runtime! plugin/unclutter.lua

0 comments on commit db6051b

Please sign in to comment.