-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
tables_test.go
87 lines (79 loc) · 1.44 KB
/
tables_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package markdown
import (
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestColumnWidths(t *testing.T) {
const lineWidth = 40
cases := []struct {
cellWidths []int
expected []int
truncated bool
}{
{
[]int{0},
[]int{0},
false,
},
{
[]int{0, 0, 0, 0, 0},
[]int{0, 0, 0, 0, 0},
false,
},
{
[]int{1, 2, 3, 4, 5},
[]int{1, 2, 3, 4, 5},
false,
},
{
// overflow, one column
[]int{60},
[]int{38},
false,
},
{
// overflow, multiple columns
[]int{30, 30, 30},
[]int{12, 12, 12}, // (40-4)/3
false,
},
{
// overflow, different columns
[]int{30, 60, 30},
[]int{12, 12, 12},
false,
},
{
// overflow, different columns with one small enough
[]int{10, 30, 30},
[]int{10, 13, 13},
false,
},
{
// overflow, different columns with one small enough
[]int{10, 60, 30},
[]int{10, 13, 13},
false,
},
{
// too much columns
[]int{10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10},
[]int{5, 5, 5, 5, 5, 5},
true,
},
}
for _, tc := range cases {
tr := newTableRenderer()
for _, w := range tc.cellWidths {
tr.AddHeaderCell(strings.Repeat("a", w), CellAlignLeft)
}
tr.NextBodyRow()
for _, w := range tc.cellWidths {
tr.AddBodyCell(strings.Repeat("a", w), CellAlignCopyHeader)
}
result, truncated := tr.columnWidths(lineWidth)
assert.Equal(t, tc.expected, result)
assert.Equal(t, tc.truncated, truncated)
}
}