From 55b5472dcb41eef1479ece40410f0ebc08eb8f25 Mon Sep 17 00:00:00 2001 From: bashbunni Date: Thu, 3 Apr 2025 22:16:35 -0700 Subject: [PATCH] test(table): add TestOverwriteStylesFromLipgloss test --- table/table_test.go | 24 +++++++++++++++++++ .../TestOverwriteStylesFromLipgloss.golden | 20 ++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 table/testdata/TestOverwriteStylesFromLipgloss.golden diff --git a/table/table_test.go b/table/table_test.go index 5045556..cf57f1b 100644 --- a/table/table_test.go +++ b/table/table_test.go @@ -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() { diff --git a/table/testdata/TestOverwriteStylesFromLipgloss.golden b/table/testdata/TestOverwriteStylesFromLipgloss.golden new file mode 100644 index 0000000..3cb3da3 --- /dev/null +++ b/table/testdata/TestOverwriteStylesFromLipgloss.golden @@ -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  │ +└───────────────────┴───────────────────┴───────────────────┴──────────────────┘ \ No newline at end of file