Skip to content

Commit

Permalink
Merge pull request #10 from ram02z/feat/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ram02z authored Aug 21, 2022
2 parents 0870612 + 48904c8 commit 23d5a02
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 17 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: ci

on:
pull_request:
push:
branches: [master]

jobs:
stylua:
name: formatting
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- uses: JohnnyMorganz/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
# CLI arguments
args: --color always --check .
busted:
name: tests
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
path: dev-comments.nvim
- uses: actions/checkout@v2
with:
repository: nvim-lua/plenary.nvim
path: plenary.nvim
- uses: rhysd/action-setup-vim@v1
with:
neovim: true
version: nightly
- run: make test
working-directory: dev-comments.nvim
timeout-minutes: 1
15 changes: 0 additions & 15 deletions .github/workflows/lint.yml

This file was deleted.

3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.PHONY: test
test:
nvim --headless --noplugin -u test/minimal.vim -c "lua require(\"plenary.test_harness\").test_directory_command('test {minimal_init = \"test/minimal.vim\"}')"
2 changes: 0 additions & 2 deletions lua/dev_comments/utils.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
local U = {}

local comment_tag_fallback_highlight = "TSNote"

local bufload_file = function(file_path)
local bufnr = vim.fn.bufadd(file_path)
-- NOTE: silent is required to avoid E325
Expand Down
49 changes: 49 additions & 0 deletions test/dev_comments/utils_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
local utils = require("dev_comments.utils")
local mock = require("luassert.mock")

describe("utils", function()
local notify
local config = require("dev_comments").config
before_each(function()
notify = mock(vim.notify, true)
end)

after_each(function()
mock.revert(notify)
end)

it("does not notify if not debug", function()
config.debug = false
utils.notify()
assert.stub(notify).was_not_called()
end)

it("gets filename from default buffer", function()
local get_filename = utils.get_filename_fn()
local api = mock(vim.api, true)

get_filename()

assert.stub(api.nvim_buf_get_name).was_called_with(0)

mock.revert(api)
end)

it("returns empty string with invalid node", function()
local node = nil
local text = utils.get_node_text(node)
assert.equals("", text)
end)

it("gets fallback highlight from config if tag and fallback are not found", function()
local fallback = config.highlight.fallback
local hlname = utils.get_highlight_by_tag(nil, nil)
assert(hlname, fallback)
end)

it("gets fallback highlight from param if tag is not found", function()
local fallback = "test"
local hlname = utils.get_highlight_by_tag(nil, fallback)
assert(hlname, fallback)
end)
end)
6 changes: 6 additions & 0 deletions test/minimal.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
set hidden
set noswapfile

set rtp+=../plenary.nvim
set rtp+=../dev-comments.nvim
runtime! plugin/plenary.vim

0 comments on commit 23d5a02

Please sign in to comment.