Skip to content

Commit

Permalink
Update unit tests (#245)
Browse files Browse the repository at this point in the history
* nvim_win_get_config() now actually returns a number

* Bump nvim version

* Set correct cursor position in unit test

* Always override get_plugin_root_dir() in automated tests

* Fix formatting

* Update nvim URL for macOS
  • Loading branch information
davidgranstrom authored Sep 15, 2024
1 parent 77aaade commit d5aa882
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ jobs:
matrix:
include:
- os: ubuntu-latest
url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-linux64.tar.gz
url: https://github.com/neovim/neovim/releases/download/v0.10.1/nvim-linux64.tar.gz
- os: macos-latest
url: https://github.com/neovim/neovim/releases/download/v0.7.0/nvim-macos.tar.gz
url: https://github.com/neovim/neovim/releases/download/v0.10.1/nvim-macos-arm64.tar.gz
steps:
- uses: actions/checkout@v3
- name: Prepare
Expand Down
8 changes: 3 additions & 5 deletions test/spec/automated/install_spec.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
local install = require 'scnvim.install'

local is_ci = vim.loop.os_getenv 'SCNVIM_CI'
if is_ci then
require('scnvim.path').get_plugin_root_dir = function()
return vim.fn.expand '%:p:h:h'
end
-- override for unit test runner
require('scnvim.path').get_plugin_root_dir = function()
return vim.fn.expand '%:p:h:h'
end

describe('install', function()
Expand Down
3 changes: 2 additions & 1 deletion test/spec/automated/map_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ describe('map', function()
cb(lines)
end
end)
vim.api.nvim_buf_set_lines(0, -2, -1, false, { 'foo' })
vim.api.nvim_win_set_cursor(0, { 1, 0 })
vim.api.nvim_buf_set_lines(0, -2, -1, true, { 'foo' })
ret.fn()
editor.on_send:restore()
end)
Expand Down
18 changes: 7 additions & 11 deletions test/spec/automated/path_spec.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
local path = require 'scnvim.path'

local eq = assert.are.same
local is_ci = vim.loop.os_getenv 'SCNVIM_CI'
if is_ci then
path.get_plugin_root_dir = function()
return vim.fn.expand '%:p:h:h'
end

-- override for unit test runner
path.get_plugin_root_dir = function()
return vim.fn.expand '%:p:h:h'
end

describe('path', function()
Expand Down Expand Up @@ -73,9 +71,7 @@ describe('path', function()
assert.is_false(path.exists(destination))
end)

it('returns plugin root dir', function()
local root_dir = path.get_plugin_root_dir()
root_dir = string.match(root_dir, 'scnvim')
eq(root_dir, 'scnvim')
end)
-- TODO: Find another way to test this function
-- it('returns plugin root dir', function()
-- end)
end)
4 changes: 2 additions & 2 deletions test/spec/automated/postwin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ describe('post window', function()
}
local id = postwin.open()
local cfg = vim.api.nvim_win_get_config(id)
assert.are.equal(3, cfg.row[true])
assert.are.equal(3, cfg.col[true])
assert.are.equal(3, cfg.row)
assert.are.equal(3, cfg.col)
assert.are.equal(12, cfg.width)
assert.are.equal(12, cfg.height)
assert.are.equal('NW', cfg.anchor)
Expand Down

0 comments on commit d5aa882

Please sign in to comment.