forked from issadarkthing/gomu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
105 lines (75 loc) · 2.33 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
package main
import (
"os"
"testing"
"time"
)
func TestFmtDuration(t *testing.T) {
samples := map[time.Duration]string{
time.Second * 5: "00:05",
time.Hour * 2: "02:00:00",
time.Minute*4 + time.Second*15: "04:15",
time.Minute * 0: "00:00",
time.Millisecond * 5: "00:00",
}
for k, v := range samples {
got := fmtDuration(k)
if got != v {
t.Errorf("fmtDuration(%s); Expected %s got %s", k, v, got)
}
}
}
func TestGetName(t *testing.T) {
samples := map[string]string{
"hello.mp3": "hello",
"~/music/fl.mp3": "fl",
"/home/terra/Music/pop/hola na.mp3": "hola na",
"~/macklemary - (ft jello) extreme!! .mp3": "macklemary - (ft jello) extreme!! ",
}
for k, v := range samples {
got := getName(k)
if got != v {
t.Errorf("GetName(%s); Expected %s got %s", k, v, got)
}
}
}
func TestDownloadedFilePath(t *testing.T) {
sample := `[youtube] jJPMnTXl63E: Downloading webpage
[download] Destination: /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.webm
[download] 100%% of 2.54MiB in 00:0213MiB/s ETA 00:002
[ffmpeg] Destination: /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.mp3
Deleting original file /tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.webm (pass -k to keep)`
result := "/tmp/Powfu - death bed (coffee for your head) (Official Video) ft. beabadoobee.mp3"
got := extractFilePath([]byte(sample), "/tmp")
if got != result {
t.Errorf("downloadedFilePath(%s); expected %s got %s", sample, result, got)
}
}
func TestEscapeBackSlash(t *testing.T) {
sample := map[string]string{
"/home/terra": "\\/home\\/terra",
"~/Documents/memes": "~\\/Documents\\/memes",
}
for k, v := range sample {
got := escapeBackSlash(k)
if got != v {
t.Errorf("escapeBackSlash(%s); expected %s, got %s", k, v, got)
}
}
}
func TestExpandTilde(t *testing.T) {
homeDir, err := os.UserHomeDir()
if err != nil {
t.Errorf("Unable to get home dir: %e", err)
}
sample := map[string]string{
"~/music": homeDir + "/music",
homeDir + "/Music": homeDir + "/Music",
}
for k, v := range sample {
got := expandTilde(k)
if got != v {
t.Errorf("expected %s; got %s", v, got)
}
}
}