MCPcopy Create free account
hub / github.com/cli/go-gh / Test_ttyTablePrinter_WithPadding

Function Test_ttyTablePrinter_WithPadding

pkg/tableprinter/table_test.go:110–137  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

108}
109
110func Test_ttyTablePrinter_WithPadding(t *testing.T) {
111 buf := bytes.Buffer{}
112 tp := New(&buf, true, 80)
113
114 // Center the headers.
115 tp.AddHeader([]string{"A", "B", "C"}, WithPadding(func(width int, s string) string {
116 left := (width - len(s)) / 2
117 return strings.Repeat(" ", left) + s + strings.Repeat(" ", width-left-len(s))
118 }))
119
120 tp.AddField("hello")
121 tp.AddField("beautiful")
122 tp.AddField("people")
123 tp.EndRow()
124
125 err := tp.Render()
126 if err != nil {
127 t.Fatalf("unexpected error: %v", err)
128 }
129
130 expected := heredoc.Doc(`
131 A B C
132 hello beautiful people
133 `)
134 if buf.String() != expected {
135 t.Errorf("expected: %q, got: %q", expected, buf.String())
136 }
137}
138
139func Test_tsvTablePrinter(t *testing.T) {
140 buf := bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

WithPaddingFunction · 0.85
StringMethod · 0.80
NewFunction · 0.70
AddHeaderMethod · 0.65
AddFieldMethod · 0.65
EndRowMethod · 0.65
RenderMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…