forked from alexeyco/simpletable
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_test.go
85 lines (68 loc) · 1.2 KB
/
content_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
package simpletable
import (
"testing"
)
var testContent = `1
22
333`
func TestContent_Width(t *testing.T) {
c := newContent(testContent)
if c.width() != 3 {
t.Error("Wrong content width")
}
}
func TestContent_Height(t *testing.T) {
c := newContent(testContent)
if c.height() != 3 {
t.Error("Wrong content height")
}
}
func TestContent_SetHeight(t *testing.T) {
c := newContent(testContent)
c.setHeight(5)
if c.height() != 5 {
t.Error("Wrong content height")
}
}
func TestContent_Lines(t *testing.T) {
c := newContent(testContent)
c.setHeight(5)
left := []string{
"1 ",
"22 ",
"333",
" ",
" ",
}
center := []string{
" 1 ",
"22 ",
"333",
" ",
" ",
}
right := []string{
" 1",
" 22",
"333",
" ",
" ",
}
if !testContentEqual(c.lines(AlignLeft), left) {
t.Error("Wrong lines rendering (align: left)")
}
if !testContentEqual(c.lines(AlignCenter), center) {
t.Error("Wrong lines rendering (align: center)")
}
if !testContentEqual(c.lines(AlignRight), right) {
t.Error("Wrong lines rendering (align: right)")
}
}
func testContentEqual(o, s []string) bool {
for i, v := range o {
if s[i] != v {
return false
}
}
return true
}