-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathutils_test.go
159 lines (148 loc) · 3.68 KB
/
utils_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
package utils
import (
"testing"
)
func TestNormalize(t *testing.T) {
cases := []struct {
in string
expected string
}{
{"Les misérables", "Les miserables"},
{" Kagerô-za", "Kagero-za"},
{" Méliès: Fairy Tales in Color", "Melies:Fairy Tales in Color"},
{" Love (2D + 3D) ", "Love (2D + 3D)"},
{" F/X: The Usual Suspects ", "F X:The Usual Suspects"},
{"Another / Movie / Test", "Another Movie Test"},
{"", ""},
}
for _, c := range cases {
got, _ := Normalize(c.in)
if got != c.expected {
t.Errorf("Normalize(%q) == %q, expected %q", c.in, got, c.expected)
}
}
}
func TestRemoveURLParams(t *testing.T) {
cases := []struct {
in string
expected string
}{
{"https://defret.in/log/dark-theme-on-ruby-on-rails", "https://defret.in/log/dark-theme-on-ruby-on-rails"},
{"https://www.youtube.com/watch?v=LvgVSSpwND8", "https://www.youtube.com/watch"},
{"https://i1.wp.com/caps.pictures/198/0-airplane/full/airplane-movie-screencaps.com-1.jpg?strip=all",
"https://i1.wp.com/caps.pictures/198/0-airplane/full/airplane-movie-screencaps.com-1.jpg"},
{"https://film-grab.com/wp-content/uploads/photo-gallery/imported_from_media_libray/10cloverfield001.jpg?bwg=1546957525",
"https://film-grab.com/wp-content/uploads/photo-gallery/imported_from_media_libray/10cloverfield001.jpg"},
{"https://stillsfrmfilms.files.wordpress.com/2014/02/012.jpg?w=150&h=64",
"https://stillsfrmfilms.files.wordpress.com/2014/02/012.jpg"},
{"", ""},
}
for _, c := range cases {
got := RemoveURLParams(c.in)
if got != c.expected {
t.Errorf("RemoveURLParams(%q) == %q, expected %q", c.in, got, c.expected)
}
}
}
func TestLimitLength(t *testing.T) {
type args struct {
s string
length int
}
tests := []struct {
name string
args args
expected string
}{
{
name: "normal test",
args: args{
s: "你好 hello",
length: 8,
},
expected: "你好 hello",
},
{
name: "truncated test",
args: args{
s: "你好 hello",
length: 6,
},
expected: "你好 ...",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := LimitLength(tt.args.s, tt.args.length); got != tt.expected {
t.Errorf("LimitLength() = %v, expected %v", got, tt.expected)
}
})
}
}
func TestRemoveDisallowedChars(t *testing.T) {
cases := []struct {
in string
expected string
}{
{"hello/world", "hello world"},
{"hello:world", "hello:world"},
{"2001|2020", "2001-2020"},
{"", ""},
}
for _, c := range cases {
got := RemoveDisallowedChars(c.in)
if got != c.expected {
t.Errorf("RemoveDisallowedChars(%q) == %q, expected %q", c.in, got, c.expected)
}
}
}
func TestCreateFolder(t *testing.T) {
type args struct {
moviePath string
}
cases := []struct {
name string
args args
expected string
}{
{
name: "wrong path to create folder",
args: args{
moviePath: "/....$x/dev/null/root/8 Mile$$$\\..111@:£*\n",
},
expected: "",
},
}
for _, c := range cases {
got, _ := CreateFolder(c.args.moviePath)
// if got is nil, there was an error during creation of the folder
if got != c.expected {
t.Errorf("CreateFolder(%q) == %q, expected %q", c.args.moviePath, got, c.expected)
}
}
}
func TestMD5(t *testing.T) {
type args struct {
text string
}
tests := []struct {
name string
args args
expected string
}{
{
name: "normal test",
args: args{
text: "123456",
},
expected: "e10adc3949ba59abbe56e057f20f883e",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MD5(tt.args.text); got != tt.expected {
t.Errorf("MD5() = %v, expected %v", got, tt.expected)
}
})
}
}