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

Function Test_ttyTablePrinter_AddHeader

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

Source from the content-addressed store, hash-verified

79}
80
81func Test_ttyTablePrinter_AddHeader(t *testing.T) {
82 buf := bytes.Buffer{}
83 tp := New(&buf, true, 80)
84
85 tp.AddHeader([]string{"ONE", "TWO", "THREE"}, WithColor(func(s string) string {
86 return fmt.Sprintf("\x1b[4m%s\x1b[m", s)
87 }))
88 // Subsequent calls to AddHeader are ignored.
89 tp.AddHeader([]string{"SHOULD", "NOT", "EXIST"})
90
91 tp.AddField("hello")
92 tp.AddField("beautiful")
93 tp.AddField("people")
94 tp.EndRow()
95
96 err := tp.Render()
97 if err != nil {
98 t.Fatalf("unexpected error: %v", err)
99 }
100
101 expected := heredoc.Docf(`
102 %[1]s[4mONE %[1]s[m %[1]s[4mTWO %[1]s[m %[1]s[4mTHREE%[1]s[m
103 hello beautiful people
104 `, "\x1b")
105 if buf.String() != expected {
106 t.Errorf("expected: %q, got: %q", expected, buf.String())
107 }
108}
109
110func Test_ttyTablePrinter_WithPadding(t *testing.T) {
111 buf := bytes.Buffer{}

Callers

nothing calls this directly

Calls 7

WithColorFunction · 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…