Meh I'll figure out submodules later

This commit is contained in:
mustard 2025-09-16 01:01:02 +02:00
parent 4ca9d44a90
commit 8cb281f436
352 changed files with 66107 additions and 0 deletions

View file

@ -0,0 +1,146 @@
pcall(require, "luacov")
local ns_id = require("neo-tree.ui.highlights").ns_id
local u = require("tests.utils")
local config = {
renderers = {
directory = {
{
"container",
content = {
{ "indent", zindex = 10 },
{ "icon", zindex = 10 },
{ "name", zindex = 10 },
{ "name", zindex = 5, align = "right" },
},
},
},
file = {
{
"container",
content = {
{ "indent", zindex = 10 },
{ "icon", zindex = 10 },
{ "name", zindex = 10 },
{ "name", zindex = 20, align = "right" },
},
},
},
},
window = {
width = 40,
},
}
local config_right = {
renderers = {
directory = {
{
"container",
enable_character_fade = false,
content = {
{ "indent", zindex = 10, align = "right" },
{ "icon", zindex = 10, align = "right" },
{ "name", zindex = 10, align = "right" },
},
},
},
file = {
{
"container",
enable_character_fade = false,
content = {
{ "indent", zindex = 10, align = "right" },
{ "icon", zindex = 10, align = "right" },
{ "name", zindex = 10, align = "right" },
},
},
},
},
window = {
width = 40,
},
}
local test_dir = {
items = {
{
name = "foo",
type = "dir",
items = {
{
name = "bar",
type = "dir",
items = {
{ name = "bar1.txt", type = "file" },
{ name = "bar2.txt", type = "file" },
},
},
{ name = "foo1.lua", type = "file" },
},
},
{ name = "bazbazbazbazbazbazbazbazbazbazbazbazbazbazbazbazbaz", type = "dir" },
{ name = "1.md", type = "file" },
},
}
describe("sources/components/container", function()
local req_switch = u.get_require_switch()
local test = u.fs.init_test(test_dir)
test.setup()
after_each(function()
if req_switch then
req_switch.restore()
end
u.clear_environment()
end)
describe("should expand to width", function()
for pow = 4, 8 do
it(2 ^ pow, function()
config.window.width = 2 ^ pow
require("neo-tree").setup(config)
vim.cmd([[Neotree focus]])
u.wait_for(function()
return vim.bo.filetype == "neo-tree"
end)
assert.equals(vim.bo.filetype, "neo-tree")
local width = vim.api.nvim_win_get_width(0)
local lines = vim.api.nvim_buf_get_lines(0, 2, -1, false)
for _, line in ipairs(lines) do
assert.is_true(#line >= width)
end
end)
end
end)
describe("right-align should matches width", function()
for pow = 4, 8 do
it(2 ^ pow, function()
config_right.window.width = 2 ^ pow
require("neo-tree").setup(config_right)
vim.cmd([[Neotree focus]])
u.wait_for(function()
return vim.bo.filetype == "neo-tree"
end)
assert.equals(vim.bo.filetype, "neo-tree")
local width = vim.api.nvim_win_get_width(0)
local lines = vim.api.nvim_buf_get_lines(0, 1, -1, false)
for _, line in ipairs(lines) do
line = vim.fn.trim(line, " ", 2)
assert.equals(width, vim.fn.strchars(line))
end
end)
end
end)
test.teardown()
end)

View file

@ -0,0 +1,89 @@
pcall(require, "luacov")
local u = require("tests.utils")
local verify = require("tests.utils.verify")
describe("Filesystem netrw hijack", function()
after_each(function()
u.clear_environment()
end)
it("does not interfere with netrw when disabled", function()
require("neo-tree").setup({
filesystem = {
hijack_netrw_behavior = "disabled",
window = {
position = "left",
},
},
})
vim.cmd("edit .")
assert(#vim.api.nvim_list_wins() == 1, "there should only be one window")
verify.after(100, function()
local name = vim.api.nvim_buf_get_name(0)
return name ~= "neo-tree filesystem [1]"
end, "the buffer should not be neo-tree")
end)
it("opens in sidebar when behavior is open_default", function()
local file = "Makefile"
vim.cmd("edit " .. file)
require("neo-tree").setup({
filesystem = {
hijack_netrw_behavior = "open_default",
window = {
position = "left",
},
},
})
vim.cmd("edit .")
verify.eventually(200, function()
return #vim.api.nvim_list_wins() == 2
end, "there should be two windows")
verify.buf_name_endswith("neo-tree filesystem [1]")
verify.eventually(100, function()
local expected_buf_name = "Makefile"
local buf_at_2 = vim.api.nvim_win_get_buf(vim.fn.win_getid(2))
local name_at_2 = vim.api.nvim_buf_get_name(buf_at_2)
if name_at_2:sub(-#expected_buf_name) == expected_buf_name then
return true
else
return false
end
end, file .. " is not at window 2")
end)
-- This test is flaky and usually fails in github actions but not always
-- so I'm disabling it for now.
-- TODO: fix this test
--
--it("opens in in splits when behavior is open_current", function()
-- local file = "Makefile"
-- vim.cmd("edit " .. file)
-- require("neo-tree").setup({
-- filesystem = {
-- hijack_netrw_behavior = "open_current",
-- },
-- })
-- assert(#vim.api.nvim_list_wins() == 1, "Test should start with one window")
-- vim.cmd("split .")
-- verify.eventually(200, function()
-- if #vim.api.nvim_list_wins() ~= 2 then
-- return false
-- end
-- return vim.bo[0].filetype == "neo-tree"
-- end, "neotree is not in the second window")
--end)
end)

View file

@ -0,0 +1,124 @@
pcall(require, "luacov")
local u = require("tests.utils")
local verify = require("tests.utils.verify")
local manager = require("neo-tree.sources.manager")
local get_dirs = function(winid)
winid = winid or vim.api.nvim_get_current_win()
local tabnr = vim.api.nvim_tabpage_get_number(vim.api.nvim_win_get_tabpage(winid))
local winnr = vim.api.nvim_win_get_number(winid)
return {
win = vim.fn.getcwd(winnr),
tab = vim.fn.getcwd(-1, tabnr),
global = vim.fn.getcwd(-1, -1),
}
end
local get_state_for_tab = function(tabid)
for _, state in ipairs(manager._get_all_states()) do
if state.tabid == tabid then
return state
end
end
end
local get_tabnr = function(tabid)
return vim.api.nvim_tabpage_get_number(tabid or vim.api.nvim_get_current_tabpage())
end
describe("Manager", function()
local test = u.fs.init_test({
items = {
{
name = "foo",
type = "dir",
items = {
{ name = "foofile1.txt", type = "file" },
},
},
{ name = "topfile1.txt", type = "file", id = "topfile1" },
},
})
test.setup()
local fs_tree = test.fs_tree
-- Just make sure we start all tests in the expected state
before_each(function()
u.eq(1, #vim.api.nvim_list_wins())
u.eq(1, #vim.api.nvim_list_tabpages())
vim.cmd.lcd(fs_tree.abspath)
vim.cmd.tcd(fs_tree.abspath)
vim.cmd.cd(fs_tree.abspath)
end)
after_each(function()
u.clear_environment()
end)
local setup_2_tabs = function()
-- create 2 tabs
local tab1 = vim.api.nvim_get_current_tabpage()
local win1 = vim.api.nvim_get_current_win()
vim.cmd.tabnew()
local tab2 = vim.api.nvim_get_current_tabpage()
local win2 = vim.api.nvim_get_current_win()
u.neq(tab2, tab1)
u.neq(win2, win1)
-- set different directories
vim.api.nvim_set_current_tabpage(tab2)
local base_dir = vim.fn.getcwd()
vim.cmd.tcd("foo")
local new_dir = vim.fn.getcwd()
-- open neo-tree
vim.api.nvim_set_current_tabpage(tab1)
vim.cmd.Neotree("show")
vim.api.nvim_set_current_tabpage(tab2)
vim.cmd.Neotree("show")
return {
tab1 = tab1,
tab2 = tab2,
win1 = win1,
win2 = win2,
tab1_dir = base_dir,
tab2_dir = new_dir,
}
end
it("should respect changed tab cwd", function()
local ctx = setup_2_tabs()
local state1 = get_state_for_tab(ctx.tab1)
local state2 = get_state_for_tab(ctx.tab2)
u.eq(ctx.tab1_dir, manager.get_cwd(state1))
u.eq(ctx.tab2_dir, manager.get_cwd(state2))
end)
it("should have correct tab cwd after tabs order is changed", function()
local ctx = setup_2_tabs()
-- tab numbers should be the same as ids
u.eq(1, get_tabnr(ctx.tab1))
u.eq(2, get_tabnr(ctx.tab2))
-- swap tabs
vim.cmd.tabfirst()
vim.cmd.tabmove("+1")
-- make sure tabs have been swapped
u.eq(2, get_tabnr(ctx.tab1))
u.eq(1, get_tabnr(ctx.tab2))
-- verify that tab dirs are the same as nvim tab cwd
local state1 = get_state_for_tab(ctx.tab1)
local state2 = get_state_for_tab(ctx.tab2)
u.eq(get_dirs(ctx.win1).tab, manager.get_cwd(state1))
u.eq(get_dirs(ctx.win2).tab, manager.get_cwd(state2))
end)
end)

View file

@ -0,0 +1,51 @@
pcall(require, "luacov")
local uv = vim.uv or vim.loop
---Return all sources inside "lua/neo-tree/sources"
---@return string[] # name of sources found
local function find_all_sources()
local base_dir = "lua/neo-tree/sources"
local result = {}
local fd = uv.fs_scandir(base_dir)
while fd do
local name, typ = uv.fs_scandir_next(fd)
if not name then
break
end
if typ == "directory" then
local ok, mod = pcall(require, "neo-tree.sources." .. name)
if ok and mod.name then
result[#result + 1] = name
end
end
end
return result
end
describe("sources.navigate(...: #<nparams>)", function()
it("neo-tree.sources.filesystem.navigate exists", function()
local ok, mod = pcall(require, "neo-tree.sources.filesystem")
assert.is_true(ok)
assert.not_nil(mod.navigate)
end)
local filesystem_navigate_nparams =
debug.getinfo(require("neo-tree.sources.filesystem").navigate).nparams
it("neo-tree.sources.filesystem.navigate is a func and has args", function()
assert.not_nil(filesystem_navigate_nparams)
assert.is_true(filesystem_navigate_nparams > 0)
end)
for _, source in ipairs(find_all_sources()) do
describe(string.format("Test: %s.navigate", source), function()
it(source .. ".navigate is able to require and exists", function()
local ok, mod = pcall(require, "neo-tree.sources." .. source)
assert.is_true(ok)
assert.not_nil(mod.navigate)
end)
it(source .. ".navigate has same num of args as filesystem", function()
local nparams = debug.getinfo(require("neo-tree.sources." .. source).navigate).nparams
assert.are.equal(filesystem_navigate_nparams, nparams)
end)
end)
end
end)