-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspotify_test.go
More file actions
88 lines (68 loc) · 2.32 KB
/
spotify_test.go
File metadata and controls
88 lines (68 loc) · 2.32 KB
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
package main
import (
"testing"
"time"
)
func TestEchoesSongToSearchStringDoesNotIncludeAlbum(t *testing.T) {
song := EchoesSong{Title: "Tubes Are Great", Artist: "Tubemeister", Album: "Best of Tubes"}
expected := "track:\"Tubes Are Great\" artist:\"Tubemeister\""
actual := echoesSongToSearchString(song)
if actual != expected {
t.Errorf("Expected %v but got %v", expected, actual)
}
}
func TestEchoesSongToSearchStringProperlyHandlesASong(t *testing.T) {
song := EchoesSong{Title: "Tubes Are Great", Artist: "Tubemeister"}
expected := "track:\"Tubes Are Great\" artist:\"Tubemeister\""
actual := echoesSongToSearchString(song)
if actual != expected {
t.Errorf("Expected %v but got %v", expected, actual)
}
}
func TestEchoesSongsToSearchStringsCreatesAProperLengthArray(t *testing.T) {
song1 := EchoesSong{Title: "11"}
song2 := EchoesSong{Title: "22"}
song3 := EchoesSong{Title: "33"}
songs := append(make([]EchoesSong, 0), song1, song2, song3)
terms := echoesSongsToSearchStrings(songs)
assertLength(t, terms, 3)
}
func TestGeneratePlaylistNamePreservesUnixTime(t *testing.T) {
unixTime := time.Unix(1457039693, 0)
playlistName := generatePlaylistName(unixTime)
if playlistName != "Echoespl Playlist 1457039693" {
t.Error("Expected Echoespl Playlist 1457039693 but got", playlistName)
}
}
func assertLength(t *testing.T, array []string, expectedLength int) {
if len(array) != expectedLength {
t.Error("Expected length", expectedLength, "but instead got", len(array))
}
}
func assertEquivalent(t *testing.T, expected []string, actual []string) {
if len(expected) != len(actual) {
t.Error("Expected length", len(expected), "but actual length", len(actual))
return
}
for i := range actual {
expectedValue := expected[i]
actualValue := actual[i]
if expectedValue != actualValue {
t.Errorf("At index %v: expected was %v and actual was %v", i, expectedValue, actualValue)
}
}
}
func TestStripString(t *testing.T) {
artist := "Bob (feat. Dave)"
stripped := stripParentheses(artist)
if stripped != "Bob" {
t.Errorf("Expected stripped parens. Should be 'Bob' but got '%s'", stripped)
}
}
func TestSplitPascalCase(t *testing.T) {
artist := "John DiMeo"
split := splitUpPascalCase(artist)
if split != "john di meo" {
t.Errorf("Expected split case. Should be 'john di meo' but got '%s'", split)
}
}