Skip to content

Commit

Permalink
test(table): failing text alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Sep 26, 2024
1 parent 6548f4e commit 9516572
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
28 changes: 28 additions & 0 deletions table/table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func TestSetStyleFunc(t *testing.T) {

func TestWithStyleFunc(t *testing.T) {
t.Run("single cell styling", func(t *testing.T) {
// #502
s := DefaultStyles()
s.BorderHeader = false
biscuits := New(
Expand Down Expand Up @@ -237,6 +238,7 @@ func TestWithStyleFunc(t *testing.T) {
golden.RequireEqual(t, []byte(biscuits.View()))
})
t.Run("cell styling by content", func(t *testing.T) {
// #502
rows := []Row{
{"Chocolate Digestives", "UK", "Yes"},
{"Tim Tams", "Australia", "No"},
Expand Down Expand Up @@ -268,4 +270,30 @@ func TestWithStyleFunc(t *testing.T) {
}))
golden.RequireEqual(t, []byte(biscuits.View()))
})
t.Run("change column text alignment", func(t *testing.T) {
// #399
s := DefaultStyles()
s.BorderHeader = false
biscuits := New(
WithColumns([]Column{
{Title: "Name", Width: 25},
{Title: "Country of Origin", Width: 16},
{Title: "Dunk-able", Width: 12},
}),
WithRows([]Row{
{"Chocolate Digestives", "UK", "Yes"},
{"Tim Tams", "Australia", "No"},
{"Hobnobs", "UK", "Yes"},
}),
WithStyleFunc(func(row, col int) lipgloss.Style {
if row == table.HeaderRow {
return s.Header
}
if col == 1 {
return s.Cell.Align(lipgloss.Right)
}
return s.Cell
}))
golden.RequireEqual(t, []byte(biscuits.View()))
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ Name โ”‚ Country of Origin โ”‚ Dunk-able โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ Chocolate Digestives โ”‚ UKโ”‚ Yes โ”‚
โ”‚ Tim Tams โ”‚ Australiaโ”‚ No โ”‚
โ”‚ Hobnobs โ”‚ UKโ”‚ Yes โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

0 comments on commit 9516572

Please sign in to comment.