test(table): add TestOverwriteStylesFromLipgloss test

This commit is contained in:
bashbunni
2025-04-03 22:16:35 -07:00
parent 9489b33613
commit 55b5472dcb
2 changed files with 44 additions and 0 deletions
+24
View File
@@ -355,6 +355,30 @@ func TestNewFromTemplate(t *testing.T) {
golden.RequireEqual(t, []byte(bubblesTable.View()))
}
func TestOverwriteStylesFromLipgloss(t *testing.T) {
baseStyle := lipgloss.NewStyle().Padding(0, 1)
headerStyle := baseStyle.Foreground(lipgloss.Color("252")).Bold(true)
lipglossTable := table.New().
Border(lipgloss.NormalBorder()).
BorderStyle(lipgloss.NewStyle().Foreground(lipgloss.Color("238"))).
Width(80).
StyleFunc(func(row, col int) lipgloss.Style {
if row == table.HeaderRow {
return headerStyle
}
even := row%2 == 0
if even {
return baseStyle.Foreground(lipgloss.Color("245"))
}
return baseStyle.Foreground(lipgloss.Color("252"))
})
bubblesTable := New().SetHeaders(headers...).SetRows(rows...)
bubblesTable.OverwriteStylesFromLipgloss(lipglossTable)
golden.RequireEqual(t, []byte(bubblesTable.View()))
}
// Examples
func ExampleOption() {
+20
View File
@@ -0,0 +1,20 @@
┌───────────────────┬───────────────────┬───────────────────┬──────────────────┐
│ Rank  │ City  │ Country  │ Population  │
├───────────────────┼───────────────────┼───────────────────┼──────────────────┤
│ 1  │ Tokyo  │ Japan  │ 37,274,000  │
│ 2  │ Delhi  │ India  │ 32,065,760  │
│ 3  │ Shanghai  │ China  │ 28,516,904  │
│ 4  │ Dhaka  │ Bangladesh  │ 22,478,116  │
│ 5  │ São Paulo  │ Brazil  │ 22,429,800  │
│ 6  │ Mexico City  │ Mexico  │ 22,085,140  │
│ 7  │ Cairo  │ Egypt  │ 21,750,020  │
│ 8  │ Beijing  │ China  │ 21,333,332  │
│ 9  │ Mumbai  │ India  │ 20,961,472  │
│ 10  │ Osaka  │ Japan  │ 19,059,856  │
│ 11  │ Chongqing  │ China  │ 16,874,740  │
│ 12  │ Karachi  │ Pakistan  │ 16,839,950  │
│ 13  │ Istanbul  │ Turkey  │ 15,636,243  │
│ 14  │ Kinshasa  │ DR Congo  │ 15,628,085  │
│ 15  │ Lagos  │ Nigeria  │ 15,387,639  │
│ 16  │ Buenos Aires  │ Argentina  │ 15,369,919  │
└───────────────────┴───────────────────┴───────────────────┴──────────────────┘