-
Notifications
You must be signed in to change notification settings - Fork 31
/
content_test.go
106 lines (84 loc) · 1.81 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
package simpletable
import (
"fmt"
"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 TestContent_StripAnsiEscape(t *testing.T) {
line := "\t\u001b[0;35mBlabla\u001b[0m \u001b[0;36m172.18.0.2\u001b[0m"
if stripAnsiEscape(line) != "\tBlabla 172.18.0.2" {
t.Error("Wrong ANSI escape sequences stripping")
}
}
func TestContent_RealLength(t *testing.T) {
colorDefault := "\x1b[39m"
colorRed := "\x1b[91m"
plainString := "I am string"
colorizedString := fmt.Sprintf("%s%s%s", colorRed, plainString, colorDefault)
if realLength(plainString) != realLength(colorizedString) {
t.Error("Wrong real string length calculation")
}
}
func testContentEqual(o, s []string) bool {
for i, v := range o {
if s[i] != v {
return false
}
}
return true
}