Skip to content

Commit

Permalink
test commands and fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
kentookura committed Oct 12, 2024
1 parent 91e65e1 commit bde24a6
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 5 deletions.
3 changes: 1 addition & 2 deletions lua/forester/commands.lua
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ M.commands = {
end,

link_new = function()
local prefixes = config.all_prefixes()
vim.ui.select(prefixes, {
vim.ui.select(vim.g.forester_current_config.prefixes, {
format_item = function(item)
return item
end,
Expand Down
2 changes: 1 addition & 1 deletion lua/forester/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,6 @@ end

M.parse = parse
M.set_default_config = set_default_config
M.switch = switch
M.all_configs = all_configs

return M
8 changes: 6 additions & 2 deletions tests/test_bindings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ local expect, eq = MiniTest.expect, MiniTest.expect.equality
local T = MiniTest.new_set()
local hooks = require("tests.hooks")

T["bindings"] =
MiniTest.new_set({ hooks = { pre_once = hooks.setup_test_forest, post_once = hooks.clean_test_forest } })
T["bindings"] = MiniTest.new_set({
hooks = {
pre_once = hooks.setup_test_forest,
post_once = hooks.clean_test_forest,
},
})

T["bindings"]["build"] = function()
local res = forester.build("forest.toml", { no_assets = true, no_theme = true })
Expand Down
70 changes: 70 additions & 0 deletions tests/test_commands.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
local forester = require("forester")
local commands = require("forester.commands").commands
local expect, eq = MiniTest.expect, MiniTest.expect.equality
local child = MiniTest.new_child_neovim()
local hooks = require("tests.hooks")

local T = MiniTest.new_set({
hooks = {
pre_once = function()
hooks.setup_test_forest()
end,
pre_case = function()
child.restart({ "-u", "scripts/minimal_init.lua" })
child.bo.readonly = false
child.lua([[
require('forester').setup()
commands = require('forester.commands').commands
]])
end,
post_once = function()
child.stop()
-- hooks.clean_test_forest()
end,
},
})

T["browse"] = function()
expect.no_error(function()
child.lua([[commands.browse()]])
end)
end

T["build"] = function()
expect.no_error(function()
child.lua([[commands.build()]])
end)
end

T["config"] = function()
expect.no_error(function()
child.lua([[commands.config()]])
end)
end

-- TODO: figure out how to test commands that modify the buffer
T["link_new"] = function()
expect.no_error(function()
-- child.lua([[commands.link_new()]])
end)
end

T["new"] = function()
expect.no_error(function()
-- child.lua([[commands.new()]])
end)
end

T["new_random"] = function()
expect.no_error(function()
-- child.lua([[commands.new_random()]])
end)
end

T["transclude_new"] = function()
expect.no_error(function()
-- child.lua([[commands.transclude_new()]])
end)
end

return T

0 comments on commit bde24a6

Please sign in to comment.