Skip to content

Commit c0e236d

Browse files
committed
add test for #285
1 parent 13d24de commit c0e236d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/merge_test.go

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,3 +656,61 @@ func TestMergeWithMultipleLines(t *testing.T) {
656656
}
657657
})
658658
}
659+
660+
func TestMergeHierarchicalCombined(t *testing.T) {
661+
var buf bytes.Buffer
662+
table := tablewriter.NewTable(&buf, tablewriter.WithConfig(tablewriter.Config{
663+
Header: tw.CellConfig{Alignment: tw.CellAlignment{Global: tw.AlignCenter}},
664+
Row: tw.CellConfig{
665+
Formatting: tw.CellFormatting{MergeMode: tw.MergeHierarchical},
666+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
667+
},
668+
Footer: tw.CellConfig{
669+
Alignment: tw.CellAlignment{Global: tw.AlignLeft},
670+
Formatting: tw.CellFormatting{
671+
MergeMode: tw.MergeHorizontal,
672+
},
673+
},
674+
Debug: true,
675+
}),
676+
tablewriter.WithRenderer(renderer.NewBlueprint(tw.Rendition{
677+
Settings: tw.Settings{Separators: tw.Separators{BetweenRows: tw.On}},
678+
})),
679+
)
680+
681+
data := [][]string{
682+
{"Engineering", "Backend", "API Team", "Alice"},
683+
{"Engineering", "Backend", "Database Team", "Bob"},
684+
{"Engineering", "Frontend", "UI Team", "Charlie"},
685+
{"Marketing", "Digital", "SEO Team", "Dave"},
686+
{"Marketing", "Digital", "Content Team", "Eve"},
687+
}
688+
689+
table.Header([]string{"Department", "Division", "Team", "Lead"})
690+
table.Bulk(data)
691+
table.Footer([]string{"Total Teams", "5", "5", "5"})
692+
table.Render()
693+
694+
expected := `
695+
┌─────────────┬──────────┬───────────────┬─────────┐
696+
│ DEPARTMENT │ DIVISION │ TEAM │ LEAD │
697+
├─────────────┼──────────┼───────────────┼─────────┤
698+
│ Engineering │ Backend │ API Team │ Alice │
699+
│ │ ├───────────────┼─────────┤
700+
│ │ │ Database Team │ Bob │
701+
│ ├──────────┼───────────────┼─────────┤
702+
│ │ Frontend │ UI Team │ Charlie │
703+
├─────────────┼──────────┼───────────────┼─────────┤
704+
│ Marketing │ Digital │ SEO Team │ Dave │
705+
│ │ ├───────────────┼─────────┤
706+
│ │ │ Content Team │ Eve │
707+
├─────────────┼──────────┴───────────────┴─────────┤
708+
│ Total Teams │ 5 │
709+
└─────────────┴────────────────────────────────────┘
710+
711+
`
712+
check := visualCheck(t, "MergeHierarchical", buf.String(), expected)
713+
if !check {
714+
t.Error(table.Debug())
715+
}
716+
}

0 commit comments

Comments
 (0)