From 4f527f374737c6f87464e59dc8e7d10d936ff5cd Mon Sep 17 00:00:00 2001 From: Hazel Noack Date: Tue, 7 Oct 2025 14:03:12 +0200 Subject: [PATCH] added basic tests --- internal/common/strings_test.go | 37 +++++++++++++++++++++++++++++++++ internal/data/song.go | 1 + internal/data/song_test.go | 34 ++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 internal/common/strings_test.go create mode 100644 internal/data/song_test.go diff --git a/internal/common/strings_test.go b/internal/common/strings_test.go new file mode 100644 index 0000000..2b97643 --- /dev/null +++ b/internal/common/strings_test.go @@ -0,0 +1,37 @@ +package common + +import "testing" + +func TestUnify(t *testing.T) { + if "foo" != Unify("foo") { + t.Errorf(`"foo" has to be untouched by unify`) + } + + if "foo" != Unify("Foo") { + t.Errorf(`"Foo" needs to be lowercase after test`) + } + + if "foo" != Unify(" Foo") { + t.Errorf(`The spaces need to be stripped`) + } + + if "foo" != Unify(" Foo ") { + t.Errorf(`The spaces need to be stripped`) + } + + if "foo bar" != Unify("Foo bar") { + t.Errorf(`Single whitespaces need to be left alone`) + } + + if "foo bar" != Unify("Foo bar") { + t.Errorf(`Double whitespaces need to be removed`) + } + + if "foo bar" != Unify("Foo bar") { + t.Errorf(`Double whitespaces need to be removed`) + } + + if "foo bar baz" != Unify("Foo bar baz") { + t.Errorf(`Double whitespaces need to be removed`) + } +} diff --git a/internal/data/song.go b/internal/data/song.go index fdd2e98..d5c6b69 100644 --- a/internal/data/song.go +++ b/internal/data/song.go @@ -105,6 +105,7 @@ func (m Song) Merge(other MusicObject) MusicObject { func (m Song) Compile() MusicObject { m.Sources = dedupeSources(m.Sources) m.UnifiedName = common.Unify(m.Name) + m.Album = m.Album.Compile().(Album) m.Artists = dedupeMusicObjects(m.Artists) return m } diff --git a/internal/data/song_test.go b/internal/data/song_test.go new file mode 100644 index 0000000..fb4b7bf --- /dev/null +++ b/internal/data/song_test.go @@ -0,0 +1,34 @@ +package data + +import ( + "testing" +) + +func TestSong(t *testing.T) { + song := Song{ + Name: "song_a", + Album: Album{ + Name: "album_a", + Artists: []Artist{ + {Name: "artist_a"}, + {Name: "artist_a"}, + {Name: "artist_b"}, + }, + }, + Artists: []Artist{ + {Name: "artist_a"}, + {Name: "artist_a"}, + {Name: "artist_b"}, + }, + } + + compiled := song.Compile().(Song) + + if len(compiled.Artists) != 2 { + t.Errorf(`the two artists with the same name have to be merged, %d`, len(compiled.Artists)) + } + + if len(compiled.Album.Artists) != 2 { + t.Errorf(`the two artists with the same names in the album have to be merged, %d`, len(compiled.Album.Artists)) + } +}