forked from jiro4989/textimg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_test.go
123 lines (117 loc) · 3.71 KB
/
main_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
package main
import (
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
)
func TestMainNormal(t *testing.T) {
tests := []struct {
desc string
in []string
want int
}{
{
desc: "正常系: 普通に描画する",
in: []string{"", "test"},
want: 0,
},
{
desc: "正常系: 赤色のエスケープシーケンス",
in: []string{"", "\x1b[31mRed\x1b[m"},
want: 0,
},
{
desc: "正常系: 赤色のエスケープシーケンスでファイル出力する",
in: []string{"", "\x1b[31mRed\x1b[m", "-o", outDir + "/main_normal_red.png"},
want: 0,
},
{
desc: "正常系: 文字色、背景色を変更する",
in: []string{"", "Sample", "-o", outDir + "/main_normal_red.png", "-g", "green", "-b", "blue"},
want: 0,
},
{
desc: "正常系: カンマ区切り指定",
in: []string{"", "Sample", "-o", outDir + "/main_normal_red.png", "-g", "0,255,0,255", "-b", "0,0,255,255"},
want: 0,
},
{
desc: "正常系: Slackアイコンサイズで生成できる",
in: []string{"", "Sample", "-o", outDir + "/main_slack.png", "--slack"},
want: 0,
},
{
desc: "正常系: width, height指定でresizeできる",
in: []string{"", "Sample", "-o", outDir + "/main_resize_width_height.png", "--resize-width", "1000", "--resize-height", "200"},
want: 0,
},
{
desc: "正常系: widthのみ指定した場合、heightが調整される",
in: []string{"", "Sample", "-o", outDir + "/main_resize_width.png", "--resize-width", "600"},
want: 0,
},
{
desc: "正常系: heightのみ指定した場合、heightが調整される",
in: []string{"", "Sample", "-o", outDir + "/main_resize_height.png", "--resize-height", "600"},
want: 0,
},
{
desc: "正常系: FontIndex, EmojiFontIndexを指定できる",
in: []string{"", "Sample", "-o", outDir + "/main_font_index.png", "-x", "0", "-X", "0"},
want: 0,
},
{
desc: "正常系: SlackアイコンサイズでアニメーションGIFを生成できる",
in: []string{"", "Sample", "-o", outDir + "/main_slack_anim.gif", "--slack", "-a"},
want: 0,
},
{
desc: "正常系: 連番付与オプションのテスト",
in: []string{"", "Sample", "-o", outDir + "/main_numbering.gif", "-n"},
want: 0,
},
{
desc: "正常系: 同じファイルがすでに存在するため別名で保存される (_2)",
in: []string{"", "Sample", "-o", outDir + "/main_numbering.gif", "-n"},
want: 0,
},
{
desc: "正常系: 同じファイルがすでに存在するため別名で保存される (_3)",
in: []string{"", "Sample", "-o", outDir + "/main_numbering.gif", "-n"},
want: 0,
},
{
desc: "異常系: 不正な文字色",
in: []string{"", "Sample", "-o", outDir + "/main_normal_red.png", "-g", "gggg", "-b", "blue"},
want: -1,
},
{
desc: "異常系: 不正な背景色",
in: []string{"", "Sample", "-o", outDir + "/main_normal_red.png", "-g", "green", "-b", "bbbb"},
want: -1,
},
{
desc: "異常系: 不正なフォントを指定",
in: []string{"", "Sample", "-o", outDir + "/illegal_case1.png", "-f", filepath.Join(testdataInputDir, "illegal_font.ttc")},
want: -1,
},
{
desc: "異常系: 不正な絵文字フォントを指定",
in: []string{"", "Sample", "-o", outDir + "/illegal_case2.png", "-e", filepath.Join(testdataInputDir, "illegal_font.ttc")},
want: -1,
},
}
for _, tt := range tests {
t.Run(tt.desc, func(t *testing.T) {
assert := assert.New(t)
os.Args = tt.in
got := Main()
assert.Equal(tt.want, got, tt.desc)
})
}
_, err := os.Stat(outDir + "/main_numbering_2.gif")
assert.NoError(t, err)
_, err = os.Stat(outDir + "/main_numbering_3.gif")
assert.NoError(t, err)
}