package table import ( "strings" "testing" "charm.land/lipgloss/v2" ) func TestRenderRowSelection(t *testing.T) { cols := []Column{ {Title: "ID", Width: 5}, {Title: "Task", Width: 10}, } rows := []Row{ {"1", "Task 1"}, {"2", "Task 2"}, } m := New( WithColumns(cols), WithRows(rows), WithStyles(Styles{ Cell: lipgloss.NewStyle().Padding(0, 1), Selected: lipgloss.NewStyle().Background(lipgloss.Color("212")), }), ) m.SetWidth(30) m.SetCursor(0) rendered := m.renderRow(0) // The rendered row should contain the background color 212 // AND the background should be present in the padding area. // Since we are using lipgloss, we check for the color code. if !strings.Contains(rendered, "212") { t.Errorf("expected rendered row to contain background color 212, got %s", rendered) } // Verify it has the full width if lipgloss.Width(rendered) != 30 { t.Errorf("expected width 30, got %d", lipgloss.Width(rendered)) } } func TestRenderRowOutOfBounds(t *testing.T) { cols := []Column{ {Title: "ID", Width: 5}, } rows := []Row{ {"1", "Task 1 Extra Column"}, } m := New( WithColumns(cols), WithRows(rows), ) // This should not panic m.renderRow(0) } func TestRenderRowNoStyles(t *testing.T) { cols := []Column{ {Title: "ID", Width: 5}, } rows := []Row{ {"1"}, } m := New( WithColumns(cols), WithRows(rows), ) m.rowStyles = nil // Ensure rowStyles is nil // This should not panic m.renderRow(0) }