-
Notifications
You must be signed in to change notification settings - Fork 2
/
title_test.go
116 lines (111 loc) · 2.53 KB
/
title_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
package rendercard
import (
"crypto/md5"
"encoding/hex"
"image/png"
"os"
"testing"
"github.com/FloatTech/gg"
"github.com/stretchr/testify/assert"
)
func TestDrawTitle(t *testing.T) {
glows, err := os.ReadFile("GlowSansSC-Normal-ExtraBold.ttf")
if err != nil {
t.Fatal(err)
}
impact, err := os.ReadFile("Impact.ttf")
if err != nil {
t.Fatal(err)
}
img, err := (&Title{
Line: 0,
LeftTitle: "服务列表",
LeftSubtitle: "service_list",
RightTitle: "FloatTech",
RightSubtitle: "ZeroBot-Plugin",
TitleFontData: glows,
TextFontData: impact,
ImagePath: ".github/warma.png",
}).DrawTitle()
if err != nil {
t.Fatal(err)
}
err = gg.SavePNG(".github/DrawTitle.png", img)
if err != nil {
t.Fatal(err)
}
h := md5.New()
err = png.Encode(h, img)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "5450734a22186aa176387ff2a91d9a7e", hex.EncodeToString(h.Sum(nil)))
}
func TestDrawTitleWithText(t *testing.T) {
glows, err := os.ReadFile("GlowSansSC-Normal-ExtraBold.ttf")
if err != nil {
t.Fatal(err)
}
impact, err := os.ReadFile("Impact.ttf")
if err != nil {
t.Fatal(err)
}
img, err := (&Title{
Line: 0,
IsEnabled: true,
LeftTitle: "ServiceName",
LeftSubtitle: "简介",
RightTitle: "FloatTech",
RightSubtitle: "ZeroBot-Plugin",
TitleFontData: impact,
TextFontData: glows,
ImagePath: ".github/warma.png",
}).DrawTitleWithText([]string{"one", "two", "san", "si"})
if err != nil {
t.Fatal(err)
}
err = gg.SavePNG(".github/DrawTitleWithText.png", img)
if err != nil {
t.Fatal(err)
}
h := md5.New()
err = png.Encode(h, img)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "49c0bb06f1b8e16833e73d2bdcbe01ce", hex.EncodeToString(h.Sum(nil)))
}
func TestDrawCard(t *testing.T) {
glows, err := os.ReadFile("GlowSansSC-Normal-ExtraBold.ttf")
if err != nil {
t.Fatal(err)
}
impact, err := os.ReadFile("Impact.ttf")
if err != nil {
t.Fatal(err)
}
img, err := (&Title{
Line: 0,
IsEnabled: true,
LeftTitle: "ServiceName",
LeftSubtitle: "简介",
TitleFontData: impact,
TextFontData: glows,
ImagePath: ".github/warma.png",
TitleFontOffsetPoint: -6,
TextFontOffsetPoint: -6,
}).DrawCard()
if err != nil {
t.Fatal(err)
}
err = gg.SavePNG(".github/DrawCard.png", img)
if err != nil {
t.Fatal(err)
}
h := md5.New()
err = png.Encode(h, img)
if err != nil {
t.Fatal(err)
}
assert.Equal(t, "deba289674306c6d674c0c07f6ae458c", hex.EncodeToString(h.Sum(nil)))
}