MCPcopy Create free account
hub / github.com/charmbracelet/bubbles / TestTableAlignment

Function TestTableAlignment

table/table_test.go:307–356  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

305}
306
307func 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
358func ansiStrip(s string) string {
359 // Replace all \r\n with \n

Callers

nothing calls this directly

Calls 10

WithColumnsFunction · 0.85
WithRowsFunction · 0.85
ansiStripFunction · 0.85
WithStylesFunction · 0.85
NewFunction · 0.70
WithWidthFunction · 0.70
WithHeightFunction · 0.70
DefaultStylesFunction · 0.70
RenderMethod · 0.65
ViewMethod · 0.45

Tested by

no test coverage detected