Skip to content

Commit

Permalink
fix: specs and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 26, 2023
1 parent 24c8c44 commit d5941ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 31 deletions.
28 changes: 14 additions & 14 deletions lua/trouble/spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -134,22 +134,22 @@ function M.group(spec)
error("invalid `group` key: " .. k)
end
end
ret.directory = vim.tbl_contains(ret.fields, "directory")
if ret.directory and #ret.fields > 1 then
error("group: cannot specify other fields with `directory`")
if vim.tbl_contains(ret.fields, "directory") then
ret.directory = true
ret.format = ret.format == "" and "{directory_icon} {directory} {count}" or ret.format
if #ret.fields > 1 then
error("group: cannot specify other fields with `directory`")
end
ret.fields = nil
end
if ret.format == "" then
if ret.directory then
ret.format = "{directory_icon} {directory} {count}"
else
ret.format = table.concat(
---@param f string
vim.tbl_map(function(f)
return "{" .. f .. "}"
end, ret.fields),
" "
)
end
ret.format = table.concat(
---@param f string
vim.tbl_map(function(f)
return "{" .. f .. "}"
end, ret.fields),
" "
)
end
return ret
end
Expand Down
26 changes: 9 additions & 17 deletions tests/spec_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,34 @@ describe("parses specs", function()
local tests = {
{
input = "foo",
output = { type = "fields", fields = { "foo" }, format = "{foo}" },
output = { fields = { "foo" }, format = "{foo}" },
},
{
input = "foo",
output = { type = "fields", fields = { "foo" }, format = "{foo}" },
output = { fields = { "foo" }, format = "{foo}" },
},
{
input = { "foo", "bar" },
output = { type = "fields", fields = { "foo", "bar" }, format = "{foo} {bar}" },
output = { fields = { "foo", "bar" }, format = "{foo} {bar}" },
},
{
input = { "foo", "bar" },
output = { type = "fields", fields = { "foo", "bar" }, format = "{foo} {bar}" },
output = { fields = { "foo", "bar" }, format = "{foo} {bar}" },
},
{
input = { "foo", "bar" },
output = { type = "fields", fields = { "foo", "bar" }, format = "{foo} {bar}" },
output = { fields = { "foo", "bar" }, format = "{foo} {bar}" },
},
{
input = {
type = "hierarchy",
"directory",
format = "{kind_icon} {symbol.name} {text:Comment} {pos}",
},
output = {
type = "hierarchy",
directory = true,
format = "{kind_icon} {symbol.name} {text:Comment} {pos}",
},
},
{
input = {
type = "directory",
},
output = {
type = "directory",
format = "{directory_icon} {directory} {count}",
},
},
}

for _, test in ipairs(tests) do
Expand All @@ -90,8 +81,9 @@ describe("parses specs", function()
sort = { "filename", "-pos" },
},
output = {
events = {},
source = "diagnostics",
groups = { { type = "fields", fields = { "filename" }, format = "{filename}" } },
groups = { { fields = { "filename" }, format = "{filename}" } },
sort = { { field = "filename" }, { field = "pos", desc = true } },
filter = { severity = 1 },
format = "{filename} {pos}",
Expand Down

0 comments on commit d5941ad

Please sign in to comment.