forked from wtfutil/wtf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_settings_test.go
194 lines (176 loc) · 3.57 KB
/
common_settings_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package cfg
import (
"testing"
"github.com/olebedev/config"
"github.com/stretchr/testify/assert"
)
var (
testYaml = `
wtf:
colors:
`
moduleConfig, _ = config.ParseYaml(testYaml)
globalSettings, _ = config.ParseYaml(testYaml)
testCfg = NewCommonSettingsFromModule(
"test",
"Test Config",
true,
moduleConfig,
globalSettings,
)
)
func Test_NewCommonSettingsFromModule(t *testing.T) {
assert.Equal(t, true, testCfg.Bordered)
assert.Equal(t, false, testCfg.Enabled)
assert.Equal(t, true, testCfg.Focusable)
assert.Equal(t, "test", testCfg.Module.Name)
assert.Equal(t, "test", testCfg.Module.Type)
assert.Equal(t, "", testCfg.FocusChar())
assert.Equal(t, 300, testCfg.RefreshInterval)
assert.Equal(t, "Test Config", testCfg.Title)
}
func Test_DefaultFocusedRowColor(t *testing.T) {
assert.Equal(t, "black:green", testCfg.DefaultFocusedRowColor())
}
func Test_DefaultRowColor(t *testing.T) {
assert.Equal(t, "white:transparent", testCfg.DefaultRowColor())
}
func Test_FocusChar(t *testing.T) {
tests := []struct {
name string
before func(testCfg *Common)
expectedChar string
}{
{
name: "with negative focus char",
before: func(testCfg *Common) {
testCfg.focusChar = -1
},
expectedChar: "",
},
{
name: "with positive focus char",
before: func(testCfg *Common) {
testCfg.focusChar = 3
},
expectedChar: "3",
},
{
name: "with zero focus char",
before: func(testCfg *Common) {
testCfg.focusChar = 0
},
expectedChar: "",
},
{
name: "with large focus char",
before: func(testCfg *Common) {
testCfg.focusChar = 10
},
expectedChar: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
tt.before(testCfg)
assert.Equal(t, tt.expectedChar, testCfg.FocusChar())
})
}
}
func Test_RowColor(t *testing.T) {
tests := []struct {
name string
idx int
expectedColor string
}{
{
name: "odd rows, default",
idx: 3,
expectedColor: "lightblue",
},
{
name: "even rows, default",
idx: 8,
expectedColor: "white",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expectedColor, testCfg.RowColor(tt.idx))
})
}
}
func Test_RightAlignFormat(t *testing.T) {
tests := []struct {
name string
width int
expected string
}{
{
name: "with zero",
width: 0,
expected: "%-2s",
},
{
name: "with positive integer",
width: 3,
expected: "%1s",
},
{
name: "with negative integer",
width: -3,
expected: "%-5s",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, testCfg.RightAlignFormat(tt.width))
})
}
}
func Test_PaginationMarker(t *testing.T) {
tests := []struct {
name string
len int
pos int
width int
expected string
}{
{
name: "with zero pages",
len: 0,
pos: 1,
width: 5,
expected: "",
},
{
name: "with one page",
len: 1,
pos: 1,
width: 5,
expected: "",
},
{
name: "with multiple pages",
len: 3,
pos: 1,
width: 5,
expected: "[lightblue]*_*[white]",
},
{
name: "with negative pages",
len: -3,
pos: 1,
width: 5,
expected: "",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
assert.Equal(t, tt.expected, testCfg.PaginationMarker(tt.len, tt.pos, tt.width))
})
}
}
func Test_Validations(t *testing.T) {
assert.Equal(t, 4, len(testCfg.Validations()))
}