Upstream rodaine/table state of the touched files before 9c71bfd95e

This commit is contained in:
upstream committed 2026-09-04 09:47:25 +02:00
1 parent b384e08abf
commit c86829d169
2 files changed
+2 -32

No files matched your search

+2 -5
View File
@@ -238,13 +238,10 @@ func (t *table) SetRows(rows [][]string) Table {
headerLength := len(t.header)
for _, row := range rows {
if len(row) >= headerLength {
if len(row) > headerLength {
t.rows = append(t.rows, row[:headerLength])
} else {
// pad short rows so every column is rendered, matching AddRow
padded := make([]string, headerLength)
copy(padded, row)
t.rows = append(t.rows, padded)
t.rows = append(t.rows, row)
}
}
-27
View File
@@ -309,30 +309,3 @@ func TestTable_WithWidthFunc(t *testing.T) {
assert.Contains(t, actual, "请求 alpha")
assert.Contains(t, actual, "abc beta")
}
func TestSetRowsShortRowsPadded(t *testing.T) {
// SetRows must pad short rows like AddRow, not emit %!s(MISSING).
buf := &bytes.Buffer{}
tbl := New("A", "B", "C").WithWriter(buf).WithPadding(1)
tbl.SetRows([][]string{{"x", "y"}})
tbl.Print()
out := buf.String()
if strings.Contains(out, "MISSING") {
t.Fatalf("output contains missing-arg verb: %q", out)
}
assert.Equal(t, "A B C \nx y \n", out)
}
func TestSetRowsEmptyRowWithFirstColumnFormatter(t *testing.T) {
// An empty row must not panic when a first-column formatter is set.
buf := &bytes.Buffer{}
tbl := New("A", "B").WithWriter(buf).WithPadding(1).
WithFirstColumnFormatter(func(f string, v ...interface{}) string {
return fmt.Sprintf(f, v...)
})
assert.NotPanics(t, func() {
tbl.SetRows([][]string{{}})
tbl.Print()
})
}