mirror of
https://github.com/zoriya/bubbles.git
synced 2026-08-16 01:43:21 +00:00
Add support fo style func to table bubble
This commit is contained in:
committed by
Maas Lalani
parent
63b0917193
commit
04658fed8e
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user