-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathutil_test.go
94 lines (88 loc) · 2.11 KB
/
util_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
package box
import (
"fmt"
"testing"
)
func TestBoxCheckColorType(t *testing.T) {
tests := []struct {
name string
b Box
}{
{
"string Color Check", Box{Config: Config{Color: "Green"}},
},
{
"string HiColor Check", Box{Config: Config{Color: "HiGreen"}},
},
{
"string Invalid Color Check", Box{Config: Config{Color: "Any"}},
},
{
"uint Color Check", Box{Config: Config{Color: uint(0x345ED3)}},
},
{
"Simple [3]uint Color Check", Box{Config: Config{Color: [3]uint{230, 45, 233}}},
},
}
for i := range tests {
t.Run(tests[i].name, func(t *testing.T) {
switch tests[i].b.Config.Color.(type) {
case uint:
case string:
case [3]uint:
default:
t.Errorf("Expected string, uint and [3]uint not %v", tests[i].b.Config.Color)
}
top, bottom := tests[i].b.checkColorType("top", "bottom", "")
fmt.Println(top, bottom)
bar := tests[i].b.obtainBoxColor()
fmt.Println(bar)
})
}
panicTest := struct {
name string
b Box
}{
"Unknown type panic", Box{Config: Config{Color: byte(23)}},
}
t.Run(panicTest.name, func(t *testing.T) {
defer func() {
if r := recover(); r == nil {
t.Errorf("Not expected string, uint, [3]uint, but got %v", panicTest.b.Config.Color)
}
}()
_, _ = panicTest.b.checkColorType("top", "bottom", "")
_ = panicTest.b.obtainBoxColor()
})
}
func TestFindAlignment(t *testing.T) {
tests := []struct {
name string
b Box
want string
}{
{
"b.findAlignment() Default Check", Box{Config: Config{ContentAlign: ""}}, leftAlign,
},
{
"b.findAlignment() Centre Check", Box{Config: Config{ContentAlign: "Center"}}, centerAlign,
},
{
"b.findAlignment() Left Check", Box{Config: Config{ContentAlign: "Left"}}, leftAlign,
},
{
"b.findAlignment() Right Check", Box{Config: Config{ContentAlign: "Right"}}, rightAlign,
},
{
"b.findAlignment() Invalid Check", Box{Config: Config{ContentAlign: "Invalid"}}, leftAlign,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
want := tt.b.findAlign()
if want != tt.want {
t.Errorf("expected %v but got %v", tt.want, want)
}
})
}
}