Skip to content

Commit 3ef2114

Browse files
De-duplicate test to pass sonarqube
1 parent c358bc2 commit 3ef2114

File tree

1 file changed

+13
-43
lines changed

1 file changed

+13
-43
lines changed

table/render_test.go

Lines changed: 13 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -879,11 +879,7 @@ func TestTable_Render_Reset(t *testing.T) {
879879

880880
func TestTable_Render_RowPainter(t *testing.T) {
881881
tw := NewWriter()
882-
tw.AppendHeader(testHeader)
883-
tw.AppendRows(testRows)
884-
tw.AppendRow(testRowMultiLine)
885-
tw.AppendFooter(testFooter)
886-
tw.SetIndexColumn(1)
882+
887883
tw.SetRowPainter(func(row Row) text.Colors {
888884
if salary, ok := row[3].(int); ok {
889885
if salary > 3000 {
@@ -894,49 +890,13 @@ func TestTable_Render_RowPainter(t *testing.T) {
894890
}
895891
return nil
896892
})
897-
tw.SetStyle(StyleLight)
898-
tw.SortBy([]SortBy{{Name: "Salary", Mode: AscNumeric}})
899893

900-
expectedOutLines := []string{
901-
"┌─────┬────────────┬───────────┬────────┬─────────────────────────────┐",
902-
"│ # │ FIRST NAME │ LAST NAME │ SALARY │ │",
903-
"├─────┼────────────┼───────────┼────────┼─────────────────────────────┤",
904-
"│ 0 │\x1b[41;30m Winter \x1b[0m│\x1b[41;30m Is \x1b[0m│\x1b[41;30m 0 \x1b[0m│\x1b[41;30m Coming. \x1b[0m│",
905-
"│ │\x1b[41;30m \x1b[0m│\x1b[41;30m \x1b[0m│\x1b[41;30m \x1b[0m│\x1b[41;30m The North Remembers! \x1b[0m│",
906-
"│ │\x1b[41;30m \x1b[0m│\x1b[41;30m \x1b[0m│\x1b[41;30m \x1b[0m│\x1b[41;30m This is known. \x1b[0m│",
907-
"│ 20 │ Jon │ Snow │ 2000 │ You know nothing, Jon Snow! │",
908-
"│ 1 │ Arya │ Stark │ 3000 │ │",
909-
"│ 300 │\x1b[43;30m Tyrion \x1b[0m│\x1b[43;30m Lannister \x1b[0m│\x1b[43;30m 5000 \x1b[0m│\x1b[43;30m \x1b[0m│",
910-
"├─────┼────────────┼───────────┼────────┼─────────────────────────────┤",
911-
"│ │ │ TOTAL │ 10000 │ │",
912-
"└─────┴────────────┴───────────┴────────┴─────────────────────────────┘",
913-
}
914-
expectedOut := strings.Join(expectedOutLines, "\n")
915-
assert.Equal(t, expectedOut, tw.Render())
916-
917-
tw.SetStyle(StyleColoredBright)
918-
tw.Style().Color.RowAlternate = tw.Style().Color.Row
919-
expectedOutLines = []string{
920-
"\x1b[106;30m # \x1b[0m\x1b[106;30m FIRST NAME \x1b[0m\x1b[106;30m LAST NAME \x1b[0m\x1b[106;30m SALARY \x1b[0m\x1b[106;30m \x1b[0m",
921-
"\x1b[106;30m 0 \x1b[0m\x1b[41;30m Winter \x1b[0m\x1b[41;30m Is \x1b[0m\x1b[41;30m 0 \x1b[0m\x1b[41;30m Coming. \x1b[0m",
922-
"\x1b[106;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m The North Remembers! \x1b[0m",
923-
"\x1b[106;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m \x1b[0m\x1b[41;30m This is known. \x1b[0m",
924-
"\x1b[106;30m 20 \x1b[0m\x1b[107;30m Jon \x1b[0m\x1b[107;30m Snow \x1b[0m\x1b[107;30m 2000 \x1b[0m\x1b[107;30m You know nothing, Jon Snow! \x1b[0m",
925-
"\x1b[106;30m 1 \x1b[0m\x1b[107;30m Arya \x1b[0m\x1b[107;30m Stark \x1b[0m\x1b[107;30m 3000 \x1b[0m\x1b[107;30m \x1b[0m",
926-
"\x1b[106;30m 300 \x1b[0m\x1b[43;30m Tyrion \x1b[0m\x1b[43;30m Lannister \x1b[0m\x1b[43;30m 5000 \x1b[0m\x1b[43;30m \x1b[0m",
927-
"\x1b[46;30m \x1b[0m\x1b[46;30m \x1b[0m\x1b[46;30m TOTAL \x1b[0m\x1b[46;30m 10000 \x1b[0m\x1b[46;30m \x1b[0m",
928-
}
929-
expectedOut = strings.Join(expectedOutLines, "\n")
930-
assert.Equal(t, expectedOut, tw.Render())
894+
RunTestTable_Render_WithRowPainter(t, tw)
931895
}
932896

933897
func TestTable_Render_IndexedRowPainter(t *testing.T) {
934898
tw := NewWriter()
935-
tw.AppendHeader(testHeader)
936-
tw.AppendRows(testRows)
937-
tw.AppendRow(testRowMultiLine)
938-
tw.AppendFooter(testFooter)
939-
tw.SetIndexColumn(1)
899+
940900
tw.SetIndexedRowPainter(func(idx int) text.Colors {
941901
if idx > -1 {
942902
if idx == 3 {
@@ -947,6 +907,16 @@ func TestTable_Render_IndexedRowPainter(t *testing.T) {
947907
}
948908
return nil
949909
})
910+
911+
RunTestTable_Render_WithRowPainter(t, tw)
912+
}
913+
914+
func RunTestTable_Render_WithRowPainter(t *testing.T, tw Writer) {
915+
tw.AppendHeader(testHeader)
916+
tw.AppendRows(testRows)
917+
tw.AppendRow(testRowMultiLine)
918+
tw.AppendFooter(testFooter)
919+
tw.SetIndexColumn(1)
950920
tw.SetStyle(StyleLight)
951921
tw.SortBy([]SortBy{{Name: "Salary", Mode: AscNumeric}})
952922

0 commit comments

Comments
 (0)