-
Notifications
You must be signed in to change notification settings - Fork 33
/
table_test.go
81 lines (72 loc) · 1.36 KB
/
table_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
package uitable
import (
"sync"
"testing"
)
func TestCell(t *testing.T) {
c := &Cell{
Data: "foo bar",
Width: 5,
}
got := c.String()
if got != "fo..." {
t.Fatal("need", "fo...", "got", got)
}
if c.LineWidth() != 5 {
t.Fatal("need", 5, "got", c.LineWidth())
}
c.Wrap = true
got = c.String()
if got != "foo\nbar" {
t.Fatal("need", "foo\nbar", "got", got)
}
if c.LineWidth() != 3 {
t.Fatal("need", 3, "got", c.LineWidth())
}
}
func TestRow(t *testing.T) {
row := &Row{
Separator: "\t",
Cells: []*Cell{
{Data: "foo", Width: 3, Wrap: true},
{Data: "bar baz", Width: 3, Wrap: true},
},
}
got := row.String()
need := "foo\tbar\n \tbaz"
if got != need {
t.Fatalf("need: %q | got: %q ", need, got)
}
}
func TestAlign(t *testing.T) {
table := New()
table.AddRow("foo", "bar baz")
table.Rows = []*Row{{
Separator: "\t",
Cells: []*Cell{
{Data: "foo", Width: 5, Wrap: true},
{Data: "bar baz", Width: 10, Wrap: true},
},
}}
table.RightAlign(1)
got := table.String()
need := "foo \t bar baz"
if got != need {
t.Fatalf("need: %q | got: %q ", need, got)
}
}
func TestAddRow(t *testing.T) {
var wg sync.WaitGroup
table := New()
for i := 0; i < 100; i++ {
wg.Add(1)
go func() {
defer wg.Done()
table.AddRow("foo")
}()
}
wg.Wait()
if len(table.Rows) != 100 {
t.Fatal("want", 100, "got", len(table.Rows))
}
}