diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..a5dcaff --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,28 @@ +name: Linting + +on: [push, pull_request] + +jobs: + selene: + name: selene + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: NTBBloodbath/selene-action@v1.0.0 + with: + # Github secret token + token: ${{ secrets.GITHUB_TOKEN }} + # selene arguments + args: --display-style=quiet . + # selene version + version: 0.12.1 + stylua: + name: stylua + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: JohnnyMorganz/stylua-action@v3 + with: + version: latest + token: ${{ secrets.GITHUB_TOKEN }} + args: --color always --check lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..4a8272d --- /dev/null +++ b/.github/workflows/test.yml @@ -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/site/pack/vendor/start + git clone --depth 1 https://github.com/nvim-lua/plenary.nvim ~/.local/share/nvim/site/pack/vendor/start/plenary.nvim + ln -s $(pwd) ~/.local/share/nvim/site/pack/vendor/start + + - name: Run tests + run: | + export PATH="${PWD}/_neovim/bin:${PATH}" + export VIM="${PWD}/_neovim/share/nvim/runtime" + nvim --version + make test diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ff23038 --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: test lint init + +TESTS_DIR := tests/ +PLUGIN_DIR := lua/ + +MINIMAL_INIT := ./scripts/minimal_init.vim + +test: + nvim --headless --noplugin -u ${MINIMAL_INIT} \ + -c "PlenaryBustedDirectory ${TESTS_DIR} { minimal_init = '${MINIMAL_INIT}' }" + +lint: + selene . + +format: + stylua --glob lua/**/*.lua tests/**/*.lua diff --git a/lua/tshjkl/init.lua b/lua/tshjkl/init.lua index 707f317..be9c409 100644 --- a/lua/tshjkl/init.lua +++ b/lua/tshjkl/init.lua @@ -3,6 +3,28 @@ local nav = require('tshjkl.nav') local M = {} +---@class TshjklKeymaps +---@field toggle any +---@field toggle_outer any +---@field parent any +---@field next any +---@field prev any +---@field child any +---@field toggle_named any + +---@class TshjklMarks +---@field parent table +---@field child table +---@field next table +---@field prev table +---@field current table + +---@class TshjklConfig +---@field select_current_node boolean +---@field keymaps TshjklKeymaps +---@field marks TshjklMarks + +---@type TshjklConfig local default_config = { -- false to highlight only. Note that enabling this will hide the highlighting of child nodes select_current_node = true, diff --git a/scripts/minimal_init.vim b/scripts/minimal_init.vim new file mode 100644 index 0000000..ba4bb7d --- /dev/null +++ b/scripts/minimal_init.vim @@ -0,0 +1,7 @@ +set rtp+=. +set rtp+=../plenary.nvim/ +set rtp+=../tree-sitter-lua/ + +runtime! plugin/plenary.vim +runtime! plugin/ts_lua.vim +runtime! plugin/tshjkl.lua diff --git a/selene.toml b/selene.toml new file mode 100644 index 0000000..7312a91 --- /dev/null +++ b/selene.toml @@ -0,0 +1 @@ +std="vim" diff --git a/tests/tshjkl/example_spec.lua b/tests/tshjkl/example_spec.lua new file mode 100644 index 0000000..c151a8b --- /dev/null +++ b/tests/tshjkl/example_spec.lua @@ -0,0 +1,10 @@ +local plugin = require('tshjkl') +local assert = require('luassert') + +describe('setup with no custom options', function() + it('example spec', function() + -- TODO remove this example spec and add actual tests later + plugin.setup({}) + assert.equals(plugin.did_setup, true) + end) +end) diff --git a/vim.toml b/vim.toml new file mode 100644 index 0000000..77b3b7f --- /dev/null +++ b/vim.toml @@ -0,0 +1,55 @@ +[selene] +base = "lua51" +name = "vim" + +[vim] +any = true + +[[describe.args]] +type = "string" +[[describe.args]] +type = "function" + +[[it.args]] +type = "string" +[[it.args]] +type = "function" + +[[before_each.args]] +type = "function" +[[after_each.args]] +type = "function" + +[assert.is_not] +any = true + +[assert.matches] +any = true + +[assert.has_error] +any = true + +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +[[assert.equals.args]] +type = "any" +required = false + +[[assert.same.args]] +type = "any" +[[assert.same.args]] +type = "any" + +[[assert.truthy.args]] +type = "any" + +[[assert.falsy.args]] +type = "any" + +[[assert.spy.args]] +type = "any" + +[[assert.stub.args]] +type = "any"