mirror of
https://github.com/stevearc/aerial.nvim
synced 2024-09-08 02:35:44 +02:00
test: more integration tests
This commit is contained in:
parent
6a8fd67801
commit
fa67761027
5 changed files with 73 additions and 17 deletions
3
.github/pre-commit
vendored
3
.github/pre-commit
vendored
|
@ -1,4 +1,5 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
luacheck .
|
luacheck lua tests
|
||||||
|
|
||||||
stylua --check .
|
stylua --check .
|
||||||
|
|
|
@ -2,7 +2,7 @@ max_comment_line_length = false
|
||||||
codes = true
|
codes = true
|
||||||
|
|
||||||
exclude_files = {
|
exclude_files = {
|
||||||
"tests/",
|
"tests/treesitter",
|
||||||
}
|
}
|
||||||
|
|
||||||
ignore = {
|
ignore = {
|
||||||
|
@ -14,4 +14,6 @@ ignore = {
|
||||||
|
|
||||||
read_globals = {
|
read_globals = {
|
||||||
"vim",
|
"vim",
|
||||||
|
"a",
|
||||||
|
"assert",
|
||||||
}
|
}
|
||||||
|
|
47
tests/attach_and_events_spec.lua
Normal file
47
tests/attach_and_events_spec.lua
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
require("plenary.async").tests.add_to_env()
|
||||||
|
local aerial = require("aerial")
|
||||||
|
local sleep = require("plenary.async.util").sleep
|
||||||
|
local loading = require("aerial.loading")
|
||||||
|
local test_util = require("tests.test_util")
|
||||||
|
local util = require("aerial.util")
|
||||||
|
|
||||||
|
---@param bufnr integer
|
||||||
|
---@return boolean
|
||||||
|
local function has_no_symbols(bufnr)
|
||||||
|
for _, line in ipairs(vim.api.nvim_buf_get_lines(bufnr, 0, -1, true)) do
|
||||||
|
if line:match("^%s*No symbols%s*$") then
|
||||||
|
return true
|
||||||
|
elseif not line:match("^%s*$") then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
a.describe("config", function()
|
||||||
|
after_each(function()
|
||||||
|
test_util.reset_editor()
|
||||||
|
end)
|
||||||
|
|
||||||
|
a.it("attach_mode = 'window' updates symbols when changing to unsupported buffer", function()
|
||||||
|
aerial.setup({
|
||||||
|
lazy_load = false,
|
||||||
|
attach_mode = "window",
|
||||||
|
})
|
||||||
|
vim.cmd("edit README.md")
|
||||||
|
aerial.toggle({ focus = false })
|
||||||
|
local aerial_win = util.get_aerial_win(0)
|
||||||
|
assert.is_not_nil(aerial_win)
|
||||||
|
-- Wait for symbols to populate
|
||||||
|
sleep(1)
|
||||||
|
assert.falsy(has_no_symbols(vim.api.nvim_win_get_buf(aerial_win)))
|
||||||
|
vim.cmd("edit LICENSE")
|
||||||
|
-- Wait for autocmd to run and attached buffer to switch
|
||||||
|
sleep(10)
|
||||||
|
local aerial_buf = vim.api.nvim_win_get_buf(aerial_win)
|
||||||
|
assert.truthy(loading.is_loading(aerial_buf))
|
||||||
|
sleep(50)
|
||||||
|
assert.falsy(loading.is_loading(aerial_buf))
|
||||||
|
assert.truthy(has_no_symbols(vim.api.nvim_win_get_buf(aerial_win)))
|
||||||
|
end)
|
||||||
|
end)
|
|
@ -1,20 +1,10 @@
|
||||||
require("plenary.async").tests.add_to_env()
|
require("plenary.async").tests.add_to_env()
|
||||||
local aerial = require("aerial")
|
local aerial = require("aerial")
|
||||||
|
local test_util = require("tests.test_util")
|
||||||
|
|
||||||
a.describe("config", function()
|
a.describe("config", function()
|
||||||
after_each(function()
|
after_each(function()
|
||||||
aerial.setup({})
|
test_util.reset_editor()
|
||||||
for i, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
|
||||||
if i > 1 then
|
|
||||||
vim.api.nvim_win_close(winid, true)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(false, true))
|
|
||||||
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
|
||||||
if vim.api.nvim_buf_get_option(bufnr, "buflisted") then
|
|
||||||
vim.api.nvim_buf_delete(bufnr, { force = true })
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
|
|
||||||
a.it("can open relative to the window, to the left", function()
|
a.it("can open relative to the window, to the left", function()
|
||||||
|
@ -25,7 +15,7 @@ a.describe("config", function()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
vim.cmd("edit README.md")
|
vim.cmd("edit README.md")
|
||||||
vim.cmd("AerialToggle")
|
aerial.toggle()
|
||||||
local winid = vim.api.nvim_tabpage_list_wins(0)[1]
|
local winid = vim.api.nvim_tabpage_list_wins(0)[1]
|
||||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||||
|
@ -39,7 +29,7 @@ a.describe("config", function()
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
vim.cmd("edit README.md")
|
vim.cmd("edit README.md")
|
||||||
vim.cmd("AerialToggle")
|
aerial.toggle()
|
||||||
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
||||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||||
|
@ -47,7 +37,7 @@ a.describe("config", function()
|
||||||
|
|
||||||
a.it("can open aerial in float", function()
|
a.it("can open aerial in float", function()
|
||||||
vim.cmd("edit README.md")
|
vim.cmd("edit README.md")
|
||||||
vim.cmd("AerialToggle float")
|
aerial.toggle({ direction = "float" })
|
||||||
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
local winid = vim.api.nvim_tabpage_list_wins(0)[2]
|
||||||
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
local aer_bufnr = vim.api.nvim_win_get_buf(winid)
|
||||||
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
assert.equals("aerial", vim.api.nvim_buf_get_option(aer_bufnr, "filetype"))
|
||||||
|
|
|
@ -89,4 +89,20 @@ M.assert_tree_equals = function(received, expected, path)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
M.reset_editor = function()
|
||||||
|
require("aerial").setup({})
|
||||||
|
vim.cmd.tabonly()
|
||||||
|
for i, winid in ipairs(vim.api.nvim_tabpage_list_wins(0)) do
|
||||||
|
if i > 1 then
|
||||||
|
vim.api.nvim_win_close(winid, true)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
vim.api.nvim_win_set_buf(0, vim.api.nvim_create_buf(false, true))
|
||||||
|
for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
|
||||||
|
if vim.api.nvim_buf_get_option(bufnr, "buflisted") then
|
||||||
|
vim.api.nvim_buf_delete(bufnr, { force = true })
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
Loading…
Reference in a new issue