2021-12-01 01:03:59 +01:00
|
|
|
local config = require("aerial.config")
|
|
|
|
|
2022-01-01 06:32:55 +01:00
|
|
|
local function reset()
|
|
|
|
package.loaded["aerial.config"] = nil
|
|
|
|
config = require("aerial.config")
|
|
|
|
end
|
|
|
|
|
2021-12-01 01:03:59 +01:00
|
|
|
describe("config", function()
|
|
|
|
before_each(function()
|
2022-01-01 06:32:55 +01:00
|
|
|
reset()
|
2021-12-01 01:03:59 +01:00
|
|
|
end)
|
|
|
|
|
|
|
|
it("falls back to default options", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup()
|
2022-08-04 08:08:43 +02:00
|
|
|
assert.equals(config.attach_mode, "window")
|
2021-12-01 01:03:59 +01:00
|
|
|
end)
|
|
|
|
|
2021-12-01 19:32:06 +01:00
|
|
|
-- Filetype maps
|
2021-12-01 02:32:03 +01:00
|
|
|
it("reads the default value for filetype map option", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup()
|
2022-04-18 18:18:48 +02:00
|
|
|
assert.equals(config.open_automatic(0), false)
|
2021-12-01 02:32:03 +01:00
|
|
|
end)
|
|
|
|
it("reads the filetype default value for filetype map option", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
2023-02-13 21:08:16 +01:00
|
|
|
manage_folds = {
|
2022-01-01 06:32:55 +01:00
|
|
|
["_"] = true,
|
2021-12-01 02:32:03 +01:00
|
|
|
},
|
2022-08-04 06:05:09 +02:00
|
|
|
})
|
2023-02-13 21:08:16 +01:00
|
|
|
assert.equals(config.manage_folds(0), true)
|
2021-12-01 02:32:03 +01:00
|
|
|
end)
|
|
|
|
it("reads the filetype value for filetype map option", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
2023-02-13 21:08:16 +01:00
|
|
|
manage_folds = {
|
2022-01-01 06:32:55 +01:00
|
|
|
fake_ft = true,
|
2021-12-01 02:32:03 +01:00
|
|
|
},
|
2022-08-04 06:05:09 +02:00
|
|
|
})
|
2021-12-01 02:32:03 +01:00
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "fake_ft")
|
2023-02-13 21:08:16 +01:00
|
|
|
assert.equals(config.manage_folds(0), true)
|
2021-12-01 02:32:03 +01:00
|
|
|
end)
|
2021-12-23 21:23:28 +01:00
|
|
|
it("reads the filetype value when using a compound filetype", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
2023-02-13 21:08:16 +01:00
|
|
|
manage_folds = {
|
2022-01-01 06:32:55 +01:00
|
|
|
fake_ft = true,
|
2021-12-23 21:23:28 +01:00
|
|
|
},
|
2022-08-04 06:05:09 +02:00
|
|
|
})
|
2021-12-23 21:23:28 +01:00
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "fake_ft.extension")
|
2023-02-13 21:08:16 +01:00
|
|
|
assert.equals(config.manage_folds(0), true)
|
2021-12-23 21:23:28 +01:00
|
|
|
end)
|
2021-12-01 02:32:03 +01:00
|
|
|
|
2022-01-02 03:56:56 +01:00
|
|
|
it("Calls the open_automatic function", function()
|
|
|
|
config.setup({
|
|
|
|
open_automatic = function()
|
|
|
|
return true
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
assert.equals(config.open_automatic(), true)
|
|
|
|
end)
|
|
|
|
|
2021-12-01 19:32:06 +01:00
|
|
|
-- Filter kind
|
2021-12-01 02:32:03 +01:00
|
|
|
it("reads the filter_kind option", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
2021-12-01 02:32:03 +01:00
|
|
|
filter_kind = { "Function" },
|
2022-08-04 06:05:09 +02:00
|
|
|
})
|
2023-07-29 19:40:13 +02:00
|
|
|
local fk = config.get_filter_kind_map(0)
|
2021-12-01 02:32:03 +01:00
|
|
|
assert.equals(nil, fk.Class)
|
|
|
|
assert.equals(true, fk.Function)
|
|
|
|
end)
|
|
|
|
it("reads the filter_kind option from filetype map", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
2021-12-01 02:32:03 +01:00
|
|
|
filter_kind = { foo = { "Function" } },
|
2022-08-04 06:05:09 +02:00
|
|
|
})
|
2021-12-23 21:23:28 +01:00
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "foo")
|
2023-07-29 19:40:13 +02:00
|
|
|
local fk = config.get_filter_kind_map(0)
|
2021-12-01 02:32:03 +01:00
|
|
|
assert.equals(nil, fk.Class)
|
|
|
|
assert.equals(true, fk.Function)
|
|
|
|
end)
|
|
|
|
it("recognizes when filter_kind is false", function()
|
2022-08-04 06:05:09 +02:00
|
|
|
config.setup({
|
|
|
|
filter_kind = { foo = false },
|
|
|
|
})
|
2021-12-23 21:23:28 +01:00
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "foo")
|
2023-07-29 19:40:13 +02:00
|
|
|
local fk = config.get_filter_kind_map(0)
|
2021-12-01 02:32:03 +01:00
|
|
|
assert.equals(true, fk.Class)
|
|
|
|
assert.equals(true, fk.Function)
|
|
|
|
end)
|
|
|
|
|
2021-12-01 19:32:06 +01:00
|
|
|
-- Icons
|
|
|
|
it("reads icons from the default table", function()
|
2024-07-16 01:09:29 +02:00
|
|
|
config.setup({ nerd_font = true, use_icon_provider = false })
|
2023-03-26 21:38:06 +02:00
|
|
|
assert.equals(" ", config.get_icon(0, "Function", false))
|
2021-12-01 19:32:06 +01:00
|
|
|
end)
|
2022-05-29 22:30:19 +02:00
|
|
|
it("reads icons from setup var", function()
|
|
|
|
config.setup({
|
2021-12-01 19:32:06 +01:00
|
|
|
nerd_font = true,
|
|
|
|
icons = {
|
|
|
|
Function = "*",
|
|
|
|
},
|
2024-07-16 01:09:29 +02:00
|
|
|
use_icon_provider = false,
|
2022-05-29 22:30:19 +02:00
|
|
|
})
|
|
|
|
assert.equals("*", config.get_icon(0, "Function", false))
|
2023-03-26 21:38:06 +02:00
|
|
|
assert.equals(" ", config.get_icon(0, "Method", false))
|
2022-05-29 22:30:19 +02:00
|
|
|
end)
|
|
|
|
it("fetches the collapsed version of icon", function()
|
|
|
|
config.setup({
|
|
|
|
icons = {
|
|
|
|
FunctionCollapsed = "a",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equals("a", config.get_icon(0, "Function", true))
|
|
|
|
end)
|
|
|
|
it("defaults to 'Collapsed' for collapsed icons", function()
|
|
|
|
config.setup({
|
|
|
|
icons = {
|
|
|
|
Collapsed = "a",
|
|
|
|
},
|
|
|
|
})
|
|
|
|
assert.equals("a", config.get_icon(0, "Function", true))
|
|
|
|
end)
|
|
|
|
it("uses filetype overrides for icons", function()
|
|
|
|
config.setup({
|
|
|
|
icons = {
|
|
|
|
foo = {
|
|
|
|
Function = "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "foo")
|
|
|
|
assert.equals("a", config.get_icon(0, "Function", false))
|
|
|
|
end)
|
|
|
|
it("falls back to '_' filetype if no match", function()
|
|
|
|
config.setup({
|
|
|
|
icons = {
|
|
|
|
["_"] = {
|
|
|
|
Function = "a",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
vim.api.nvim_buf_set_option(0, "filetype", "foo")
|
|
|
|
assert.equals("a", config.get_icon(0, "Function", false))
|
2021-12-01 19:32:06 +01:00
|
|
|
end)
|
2021-12-01 01:03:59 +01:00
|
|
|
end)
|