-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathfont_test.go
157 lines (152 loc) · 3.01 KB
/
font_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
package gocaptcha
import (
"testing"
)
func TestFontFamily_Random(t *testing.T) {
type args struct {
}
fontFamily := NewFontFamily()
tests := []struct {
name string
t *FontFamily
args args
fn func(*FontFamily) error
wantErr bool
wantFont bool
}{
{
name: "test1",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
return nil
},
wantErr: true,
wantFont: false,
},
{
name: "test2",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
family.fonts = append(family.fonts, "./testdata/Hiragino Sans GB.ttc")
return nil
},
wantErr: true,
wantFont: false,
},
{
name: "test3",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
family.fonts = []string{"./fonts/3Dumb.ttf"}
return nil
},
wantErr: false,
wantFont: true,
},
{
name: "test4",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
return family.AddFont("./fonts/3Dumb.ttf")
},
wantErr: false,
wantFont: true,
},
{
name: "test5",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
return family.AddFont("./fonts/Comismsh.ttf")
},
wantErr: false,
wantFont: true,
},
{
name: "test6",
t: fontFamily,
args: args{},
fn: func(family *FontFamily) error {
return family.AddFont("./testdata/Hiragino Sans GB.ttc")
},
wantErr: false,
wantFont: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
_ = tt.fn(tt.t)
if font, err := tt.t.Random(); (font == nil) == tt.wantFont || (err != nil) != tt.wantErr {
t.Errorf("FontFamily.Random() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestSetFonts(t *testing.T) {
type args struct {
fonts []string
}
tests := []struct {
name string
args args
wantErr bool
}{
{
name: "test1",
args: args{
fonts: []string{"./fonts/3Dumb.ttf"},
},
wantErr: false,
},
{
name: "test2",
args: args{
fonts: []string{"./testdata/Hiragino Sans GB.ttc"},
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := SetFonts(tt.args.fonts...); (err != nil) != tt.wantErr {
t.Errorf("SetFonts() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
func TestFontFamily_AddFontPath(t *testing.T) {
type args struct {
dirPath string
}
fontFamily := NewFontFamily()
tests := []struct {
name string
t *FontFamily
args args
wantErr bool
}{
{
name: "test1",
t: fontFamily,
args: args{dirPath: "./fonts"},
wantErr: false,
},
{
name: "test2",
t: fontFamily,
args: args{dirPath: "./testdata/not_exist"},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if err := tt.t.AddFontPath(tt.args.dirPath); (err != nil) != tt.wantErr {
t.Errorf("FontFamily.AddFontPath() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}