-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtableify_test.go
51 lines (41 loc) · 977 Bytes
/
tableify_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
package tableify
import (
"os"
"testing"
)
type TestStruct struct {
Value1 string
Value2 string
}
func initTestStructTable() *StructTable {
st, err := NewStructTable(os.Stdout, TestStruct{})
if err != nil {
panic(err)
}
return st
}
func TestHeader(t *testing.T) {
st := initTestStructTable()
expectedHeaders := []string{"Value1", "Value2"}
if st.headers[0] != expectedHeaders[0] {
t.Errorf("Expected %v, got %v", expectedHeaders, st.headers)
}
}
func TestValues(t *testing.T) {
st := initTestStructTable()
st.Append(TestStruct{"A", "B"})
if st.rows[0][0] != "A" {
t.Errorf("Error: expected %v, got %v", "A", st.rows[0][0])
}
}
func TestAppendBuild(t *testing.T) {
st := initTestStructTable()
st.AppendBulk([]TestStruct{
TestStruct{"A", "B"},
TestStruct{"C", "D"},
})
if st.rows[0][0] != "A" || st.rows[1][0] != "C" {
t.Errorf("Error: \n\t->expected %v, got %v\n\t->expected %v, got %v", "A",
st.rows[0][0], "C", st.rows[1][0])
}
}