Add support fo style func to table bubble

This commit is contained in:
Kevin Miller
2024-04-24 13:37:52 -04:00
committed by Maas Lalani
parent 63b0917193
commit 04658fed8e
2 changed files with 55 additions and 6 deletions
+31
View File
@@ -1,6 +1,7 @@
package table
import (
"strings"
"testing"
"github.com/charmbracelet/lipgloss"
@@ -108,3 +109,33 @@ func TestRenderRow(t *testing.T) {
})
}
}
func TestRenderRowStyleFunc(t *testing.T) {
tests := []struct {
name string
table *Model
expected string
}{
{
name: "simple row",
table: &Model{
rows: []Row{{"Foooooo", "Baaaaar", "Baaaaaz"}},
cols: cols,
styleFunc: func(row, col int, value string) lipgloss.Style {
if strings.HasSuffix(value, "z") {
return lipgloss.NewStyle().Transform(strings.ToLower)
}
return lipgloss.NewStyle().Transform(strings.ToUpper)
},
},
expected: "FOOOOOO BAAAAAR baaaaaz ",
},
}
for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
row := tc.table.renderRow(0)
if row != tc.expected {
t.Fatalf("\n\nWant: \n%s\n\nGot: \n%s\n", tc.expected, row)
}
})
}
}