Skip to content

Commit

Permalink
fix(bar): missing slot.len for another edge case
Browse files Browse the repository at this point in the history
  • Loading branch information
MunifTanjim committed Dec 15, 2023
1 parent d9129e1 commit 53f8fea
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lua/nougat/bar/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ function Bar.__prepare_slots(items, ctx)
parts[nested_items_idx] = nested_slots
end

nested_slots.len = nested_items.len
nested_slots.len = nested_items.len or #nested_items
ctx.available_width = available_width
ctx.slots = nested_slots

Expand Down
114 changes: 87 additions & 27 deletions tests/nougat/bar/init_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -473,17 +473,68 @@ describe("NougatBar", function()
t.eq(bar:generate(ctx), string.format("%s%s%s", string.rep("A", 0), string.rep("B", 10), string.rep("C", 0)))
end)

it("nested", function()
bar:add_item(nut.mode.create({
priority = 3,
}))
bar:add_item(nut.buf.filename.create({
priority = 1,
}))
bar:add_item(Item({
priority = 2,
prefix = " ",
content = {
describe("nested", function()
it("static", function()
bar:add_item(nut.mode.create({
priority = 3,
}))
bar:add_item(nut.buf.filename.create({
priority = 1,
}))
bar:add_item(Item({
priority = 2,
prefix = " ",
content = {
Item({
priority = 1,
prefix = "+",
content = "1",
suffix = " ",
}),
Item({
priority = 2,
prefix = "~",
content = "1",
suffix = " ",
}),
Item({
priority = 1,
content = {
Item({ content = "-" }),
Item({ content = "1" }),
},
suffix = " ",
}),
},
}))

ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_#[No Name] +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 2 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# ~1 ")

ctx.width = 1 + (2 + 1) * 1 + 1
t.eq(bar:generate(ctx), " ~1 ")
end)

it("dynamic", function()
bar:add_item(nut.mode.create({
priority = 3,
}))
bar:add_item(nut.buf.filename.create({
priority = 1,
}))
local sub_items = {
Item({
priority = 1,
prefix = "+",
Expand All @@ -498,30 +549,39 @@ describe("NougatBar", function()
}),
Item({
priority = 1,
prefix = "-",
content = "1",
content = {
Item({ content = "-" }),
Item({ content = "1" }),
},
suffix = " ",
}),
},
}))
}
bar:add_item(Item({
priority = 2,
prefix = " ",
content = function()
return sub_items
end,
}))

ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_#[No Name] +1 ~1 -1 ")
ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_#[No Name] +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")
ctx.width = string.len("NORMAL") + string.len("[No Name]") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")
ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 -1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 ")
ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 3 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# +1 ~1 ")

ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 2 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# ~1 ")
ctx.width = string.len("NORMAL") + 1 + (2 + 1) * 2 - 1
t.eq(bar:generate(ctx), "%#bg_663399_fg_ffcd00_#NORMAL%#bg_ffcd00_fg_663399_# ~1 ")

ctx.width = 1 + (2 + 1) * 1 + 1
t.eq(bar:generate(ctx), " ~1 ")
ctx.width = 1 + (2 + 1) * 1 + 1
t.eq(bar:generate(ctx), " ~1 ")
end)
end)

it("handles sep.none gracefully", function()
Expand Down

0 comments on commit 53f8fea

Please sign in to comment.