aboutsummaryrefslogtreecommitdiff
path: root/test/Sound/MusicDirTrans
diff options
context:
space:
mode:
Diffstat (limited to 'test/Sound/MusicDirTrans')
-rw-r--r--test/Sound/MusicDirTrans/DirectorySpec.hs30
-rw-r--r--test/Sound/MusicDirTrans/FileSpec.hs25
-rw-r--r--test/Sound/MusicDirTrans/Test/Util.hs89
-rw-r--r--test/Sound/MusicDirTrans/TypeSpec.hs46
4 files changed, 190 insertions, 0 deletions
diff --git a/test/Sound/MusicDirTrans/DirectorySpec.hs b/test/Sound/MusicDirTrans/DirectorySpec.hs
new file mode 100644
index 0000000..328f5df
--- /dev/null
+++ b/test/Sound/MusicDirTrans/DirectorySpec.hs
@@ -0,0 +1,30 @@
+module Sound.MusicDirTrans.DirectorySpec
+ ( spec
+ )
+where
+
+import Test.Hspec
+import Sound.MusicDirTrans
+import Sound.MusicDirTrans.Test.Util
+
+spec :: Spec
+spec = do
+ describe "getTracksInDir" $ do
+ it "should get the tracks in a directory" $ do
+ files <- getTracksInDir "audio-samples"
+ files `shouldBe` audioTracks
+
+ describe "genArtistPathFromTracks" $ do
+ it "should get the tracks in a directory" $ do
+ ap <- genArtistPathFromTracks "audio-samples"
+ ap `shouldBe` metadataArtistPath
+
+ describe "mkRevertArtistPath" $ do
+ it "should create the dir.orig.name.txt path" $ do
+ mkRevertArtistPath "/tmp/audio-samples" "audio-samples-revert"
+ `shouldBe` ArtistPath "/tmp/audio-samples" "" "//tmp/audio-samples-revert"
+
+ describe "revertFile" $ do
+ it "should represent the filemane - dir.orig.name.txt" $ do
+ revertFile `shouldBe` "dir.orig.name.txt"
+
diff --git a/test/Sound/MusicDirTrans/FileSpec.hs b/test/Sound/MusicDirTrans/FileSpec.hs
new file mode 100644
index 0000000..37f8851
--- /dev/null
+++ b/test/Sound/MusicDirTrans/FileSpec.hs
@@ -0,0 +1,25 @@
+module Sound.MusicDirTrans.FileSpec
+ ( spec
+ )
+where
+
+import Test.Hspec
+import Sound.MusicDirTrans
+import Sound.MusicDirTrans.Test.Util
+
+spec :: Spec
+spec = do
+ describe "trackFilePatterns" $ do
+ it "should compile track file extensions patterns" $ do
+ trackFilePatterns `shouldBe` patterns
+
+ describe "getMetadata" $ do
+ it "should gather track metadata" $ do
+ fileMetadata <- getMetadata "audio-samples/sample.flac"
+ sampleMetadata `shouldBe` fileMetadata
+
+ describe "mkNewPathName" $ do
+ it "should create an Artist -> Album ArtistPath structure" $ do
+ mkArtistPath origPath metadata `shouldBe` artistPath
+ mkArtistPath origPath metadataWithoutYear
+ `shouldBe` artistPathWithoutYear
diff --git a/test/Sound/MusicDirTrans/Test/Util.hs b/test/Sound/MusicDirTrans/Test/Util.hs
new file mode 100644
index 0000000..743ce99
--- /dev/null
+++ b/test/Sound/MusicDirTrans/Test/Util.hs
@@ -0,0 +1,89 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Sound.MusicDirTrans.Test.Util
+ ( artistPath
+ , artistPathStr
+ , artistPathWithoutYear
+ , metadata
+ , metadataArtistPath
+ , metadataWithoutYear
+ , sampleMetadata
+ , sampleMetadataStr
+ , patterns
+ , origPath
+ , audioTracks
+ )
+where
+
+import Data.Text
+import Sound.HTagLib
+import Sound.MusicDirTrans
+import System.FilePath.Glob
+
+patterns :: [Pattern]
+patterns =
+ [ compile "*.flac"
+ , compile "*.wav"
+ , compile "*.mp3"
+ , compile "*.mp4"
+ , compile "*.asf"
+ , compile "*.aiff"
+ , compile "*.mpc"
+ , compile "*.spx"
+ , compile "*.tt"
+ , compile "*.wv"
+ ]
+
+sampleMetadata :: Metadata
+sampleMetadata = Metadata (mkArtist $ pack "artist")
+ (mkAlbum $ pack "album")
+ (mkYear 2055)
+
+sampleMetadataStr :: String
+sampleMetadataStr = "Metadata {mArtist = Artist \"artist\","
+ ++ " mAlbum = Album \"album\", mYear = Just (Year 2055)}"
+
+metadata :: [Metadata]
+metadata =
+ (Prelude.replicate 5 $ Metadata
+ (mkArtist $ pack "Mono")
+ (mkAlbum $ pack "Requiem for Hell")
+ (mkYear 2019)
+ )
+ ++ [ Metadata
+ (mkArtist $ pack "artist")
+ (mkAlbum $ pack "album")
+ (mkYear 2055)
+ ]
+metadataWithoutYear :: [Metadata]
+metadataWithoutYear =
+ (Prelude.replicate 5 $ Metadata
+ (mkArtist $ pack "Mono")
+ (mkAlbum $ pack "Requiem for Hell")
+ Nothing
+ )
+ ++ [ Metadata
+ (mkArtist $ pack "artist")
+ (mkAlbum $ pack "album")
+ (mkYear 2055)
+ ]
+
+origPath :: FilePath
+origPath = "Mono - Requiem for Hell (2019) JP [FLAC] Vinyl"
+
+artistPath :: ArtistPath
+artistPath = ArtistPath origPath "Mono" "Requiem for Hell (2019)"
+
+artistPathStr :: String
+artistPathStr = "ArtistPath {rootPath = \"Mono - Requiem for Hell (2019) JP [FLAC] Vinyl\""
+ ++ ", parentPath = \"Mono\", childPath = \"Requiem for Hell (2019)\"}"
+
+artistPathWithoutYear :: ArtistPath
+artistPathWithoutYear = ArtistPath origPath "Mono" "Requiem for Hell"
+
+audioTracks :: [AudioTrack]
+audioTracks = [ AudioTrack "audio-samples/sample.flac"
+ , AudioTrack "audio-samples/sample.mp3"]
+
+metadataArtistPath :: ArtistPath
+metadataArtistPath = ArtistPath "audio-samples" "artist" "album (2055)"
diff --git a/test/Sound/MusicDirTrans/TypeSpec.hs b/test/Sound/MusicDirTrans/TypeSpec.hs
new file mode 100644
index 0000000..d825539
--- /dev/null
+++ b/test/Sound/MusicDirTrans/TypeSpec.hs
@@ -0,0 +1,46 @@
+module Sound.MusicDirTrans.TypeSpec
+ (
+ spec
+ )
+where
+
+import Test.Hspec
+import Sound.MusicDirTrans
+import Sound.MusicDirTrans.Test.Util
+
+spec :: Spec
+spec = do
+ describe "AudioTrack" $ do
+ it "should work with the show function" $ do
+ show $ AudioTrack "Mono/Requiem for Hell (2019)/01-song.flac"
+ `shouldBe` "AudioTrack {currentPath = \"Mono/Requiem for Hell (2019)/01-song.flac\"}"
+ it "should have an equivalency" $ do
+ AudioTrack "Mono/Requiem for Hell (2019)/01-song.flac"
+ == AudioTrack "Mono/Requiem for Hell (2019)/01-song.flac"
+ `shouldBe` True
+ it "should have currentPath field accessible" $do
+ currentPath (AudioTrack "Mono/Requiem for Hell (2019)/01-song.flac")
+ `shouldBe` "Mono/Requiem for Hell (2019)/01-song.flac"
+
+ describe "ArtistPath" $ do
+ it "should work with the show function" $ do
+ show artistPath
+ `shouldBe` artistPathStr
+ it "should have an equivalency" $ do
+ artistPath == artistPath
+ `shouldBe` True
+ it "should have rootPath field accessible" $ do
+ rootPath artistPath `shouldBe` origPath
+ it "should have parentPath field accessible" $ do
+ parentPath artistPath `shouldBe` "Mono"
+ it "should have childPath field accessible" $ do
+ childPath artistPath `shouldBe` "Requiem for Hell (2019)"
+
+ describe "Metadata" $ do
+ it "should work with the show function" $ do
+ show $ sampleMetadata
+ `shouldBe` sampleMetadataStr
+
+ describe "newPath" $ do
+ it "should create a concatenated filepath" $ do
+ newPath artistPath `shouldBe` "Mono/Requiem for Hell (2019)/"