(t *testing.T)
| 305 | } |
| 306 | |
| 307 | func TestTableAlignment(t *testing.T) { |
| 308 | t.Run("No border", func(t *testing.T) { |
| 309 | biscuits := New( |
| 310 | WithWidth(59), |
| 311 | WithHeight(5), |
| 312 | WithColumns([]Column{ |
| 313 | {Title: "Name", Width: 25}, |
| 314 | {Title: "Country of Origin", Width: 16}, |
| 315 | {Title: "Dunk-able", Width: 12}, |
| 316 | }), |
| 317 | WithRows([]Row{ |
| 318 | {"Chocolate Digestives", "UK", "Yes"}, |
| 319 | {"Tim Tams", "Australia", "No"}, |
| 320 | {"Hobnobs", "UK", "Yes"}, |
| 321 | }), |
| 322 | ) |
| 323 | got := ansiStrip(biscuits.View()) |
| 324 | golden.RequireEqual(t, []byte(got)) |
| 325 | }) |
| 326 | t.Run("With border", func(t *testing.T) { |
| 327 | baseStyle := lipgloss.NewStyle(). |
| 328 | BorderStyle(lipgloss.NormalBorder()). |
| 329 | BorderForeground(lipgloss.Color("240")) |
| 330 | |
| 331 | s := DefaultStyles() |
| 332 | s.Header = s.Header. |
| 333 | BorderStyle(lipgloss.NormalBorder()). |
| 334 | BorderForeground(lipgloss.Color("240")). |
| 335 | BorderBottom(true). |
| 336 | Bold(false) |
| 337 | |
| 338 | biscuits := New( |
| 339 | WithWidth(59), |
| 340 | WithHeight(5), |
| 341 | WithColumns([]Column{ |
| 342 | {Title: "Name", Width: 25}, |
| 343 | {Title: "Country of Origin", Width: 16}, |
| 344 | {Title: "Dunk-able", Width: 12}, |
| 345 | }), |
| 346 | WithRows([]Row{ |
| 347 | {"Chocolate Digestives", "UK", "Yes"}, |
| 348 | {"Tim Tams", "Australia", "No"}, |
| 349 | {"Hobnobs", "UK", "Yes"}, |
| 350 | }), |
| 351 | WithStyles(s), |
| 352 | ) |
| 353 | got := ansiStrip(baseStyle.Render(biscuits.View())) |
| 354 | golden.RequireEqual(t, []byte(got)) |
| 355 | }) |
| 356 | } |
| 357 | |
| 358 | func ansiStrip(s string) string { |
| 359 | // Replace all \r\n with \n |
nothing calls this directly
no test coverage detected