Skip to content

Commit

Permalink
remove mini.test
Browse files Browse the repository at this point in the history
  • Loading branch information
tris203 committed Jan 3, 2024
1 parent 7434bf8 commit c8e574b
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 67 deletions.
106 changes: 50 additions & 56 deletions tests/hawtkeys/ui_spec.lua
Original file line number Diff line number Diff line change
@@ -1,71 +1,62 @@
---@diagnostic disable-next-line: undefined-field
local eq = assert.are.same

local function getTestPath()
if package.config:sub(1, 1) == "\\" then
return "tests\\minimal_init.lua"
else
return "tests/minimal_init.lua"
end
end

local MiniTest = require("mini.test")

---TODO: add search functionality tests (willothy)

describe("ui", function()
local child = MiniTest.new_child_neovim({}, { connection_timeout = 30000 })
local SearchBuf, SearchWin, ResultBuf, ResultWin, Namespace, prompt_extmark

before_each(function()
child.restart({ "-u", getTestPath() })
child.lua([[require("hawtkeys").setup({})]])
require("plenary.reload").reload_module("hawtkeys")
require("hawtkeys").setup({})
end)

describe("search", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show()]])
require("plenary.reload").reload_module("hawtkeys")
require("hawtkeys").setup({})
vim.cmd([[lua require("hawtkeys.ui").show()]])
SearchBuf, SearchWin, ResultBuf, ResultWin, Namespace, prompt_extmark =
unpack(child.lua([[
local ui = require("hawtkeys.ui")
return {
ui.SearchBuf,
ui.SearchWin,
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
ui.prompt_extmark
}
]]))
unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.SearchBuf,
ui.SearchWin,
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
ui.prompt_extmark,
}
end)())
end)

it("should show the search UI", function()
assert(child.api.nvim_buf_is_valid(SearchBuf))
assert(child.api.nvim_win_is_valid(SearchWin))
assert(vim.api.nvim_buf_is_valid(SearchBuf))
assert(vim.api.nvim_win_is_valid(SearchWin))

assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(SearchBuf, child.api.nvim_get_current_buf())
eq(SearchWin, child.api.nvim_get_current_win())
eq(SearchBuf, vim.api.nvim_get_current_buf())
eq(SearchWin, vim.api.nvim_get_current_win())

local win_config = child.api.nvim_win_get_config(SearchWin)
local win_config = vim.api.nvim_win_get_config(SearchWin)
eq("editor", win_config.relative)
end)
--TODO: This doesnt work since removing the dependency on mini.test
--[[ it("starts in insert mode", function()
assert(vim.api.nvim_buf_is_valid(SearchBuf))
assert(vim.api.nvim_win_is_valid(SearchWin))
it("starts in insert mode", function()
assert(child.api.nvim_buf_is_valid(SearchBuf))
assert(child.api.nvim_win_is_valid(SearchWin))

eq(child.api.nvim_get_current_win(), SearchWin)
eq("i", child.api.nvim_get_mode().mode)
eq(vim.api.nvim_get_current_win(), SearchWin)
eq("i", vim.api.nvim_get_mode().mode)
end)

]]
it("should show the hint extmark", function()
assert(SearchBuf)
assert(prompt_extmark)
assert(Namespace)
local extmark_info = child.api.nvim_buf_get_extmark_by_id(
local extmark_info = vim.api.nvim_buf_get_extmark_by_id(
SearchBuf,
Namespace,
prompt_extmark,
Expand All @@ -78,50 +69,53 @@ describe("ui", function()

describe("all", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show_all()]])
ResultBuf, ResultWin, Namespace = unpack(child.lua([[
require("plenary.reload").reload_module("hawtkeys")
require("hawtkeys").setup({})
vim.cmd([[lua require("hawtkeys.ui").show_all()]])
ResultBuf, ResultWin, Namespace = unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
}
]]))
end)())
end)

it("should show the all UI", function()
assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
print(vim.inspect(ResultBuf))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(child.api.nvim_get_current_buf(), ResultBuf)
eq(child.api.nvim_get_current_win(), ResultWin)
eq(vim.api.nvim_get_current_buf(), ResultBuf)
eq(vim.api.nvim_get_current_win(), ResultWin)

local win_config = child.api.nvim_win_get_config(ResultWin)
local win_config = vim.api.nvim_win_get_config(ResultWin)
eq(win_config.relative, "editor")
end)
end)

describe("dupes", function()
before_each(function()
child.lua([[require("hawtkeys.ui").show_dupes()]])
ResultBuf, ResultWin, Namespace = unpack(child.lua([[
vim.cmd([[lua require("hawtkeys.ui").show_dupes()]])
ResultBuf, ResultWin, Namespace = unpack((function()
local ui = require("hawtkeys.ui")
return {
ui.ResultBuf,
ui.ResultWin,
ui.Namespace,
}
]]))
end)())
end)

it("should show the duplicates UI", function()
assert(child.api.nvim_buf_is_valid(ResultBuf))
assert(child.api.nvim_win_is_valid(ResultWin))
assert(vim.api.nvim_buf_is_valid(ResultBuf))
assert(vim.api.nvim_win_is_valid(ResultWin))

eq(child.api.nvim_get_current_buf(), ResultBuf)
eq(child.api.nvim_get_current_win(), ResultWin)
eq(vim.api.nvim_get_current_buf(), ResultBuf)
eq(vim.api.nvim_get_current_win(), ResultWin)

local win_config = child.api.nvim_win_get_config(ResultWin)
local win_config = vim.api.nvim_win_get_config(ResultWin)
eq(win_config.relative, "editor")
end)
end)
Expand Down
11 changes: 0 additions & 11 deletions tests/minimal_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ end

local plenary_dir = os.getenv("PLENARY_DIR") or tempdir("plenary.nvim")
local treesitter_dir = os.getenv("TREESITTER_DIR") or tempdir("nvim-treesitter")
local mini_dir = os.getenv("MINI_DIR") or tempdir("mini-test")
if vim.fn.isdirectory(plenary_dir) == 0 then
vim.fn.system({
"git",
Expand All @@ -58,20 +57,10 @@ if vim.fn.isdirectory(treesitter_dir) == 0 then
treesitter_dir,
})
end
if vim.fn.isdirectory(mini_dir) == 0 then
vim.fn.system({
"git",
"clone",
"https://github.com/tris203/mini.test",
mini_dir,
})
end
vim.opt.rtp:append(".")
vim.opt.rtp:append(plenary_dir)
vim.opt.rtp:append(treesitter_dir)
vim.opt.rtp:append(mini_dir)
require("plenary.busted")
require("mini.test").setup()

vim.cmd("runtime plugin/plenary.vim")
vim.cmd("runtime plugin/treesitter.vim")
Expand Down

0 comments on commit c8e574b

Please sign in to comment.