-
Notifications
You must be signed in to change notification settings - Fork 4
/
SetterSpec.hs
51 lines (43 loc) · 1.51 KB
/
SetterSpec.hs
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
{-# LANGUAGE OverloadedStrings #-}
module Sound.HTagLib.SetterSpec (spec) where
import Sound.HTagLib
import Sound.HTagLib.Test.Util
import System.Directory (getTemporaryDirectory, copyFile)
import System.FilePath ((</>), takeFileName)
import Test.Hspec
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative
#endif
spec :: Spec
spec =
describe "setters" $ do
mapM_ (withFile $ const simpleSetter) fileList
mapM_ (withFile specializedSetter) fileList
dupeFile :: FilePath -> IO FilePath
dupeFile path = do
newPath <- (</> takeFileName path) <$> getTemporaryDirectory
copyFile path newPath
return newPath
updateSampleTags :: AudioTags -> AudioTags
updateSampleTags tags = tags
{ atTitle = mkTitle "title'"
, atArtist = mkArtist "artist'"
, atAlbum = mkAlbum "album'"
, atComment = mkComment "comment'"
, atGenre = mkGenre "genre'"
, atYear = mkYear 2056
, atTrackNumber = mkTrackNumber 8 }
simpleSetter :: AudioTags -> Expectation
simpleSetter tags = do
let path = atFileName tags
dupe <- dupeFile path
setTags dupe Nothing sampleSetter
extracted <- getTags dupe (sampleGetter dupe)
extracted `shouldMatchTags` updateSampleTags (tags { atFileName = dupe })
specializedSetter :: FileType -> AudioTags -> Expectation
specializedSetter t tags = do
let path = atFileName tags
dupe <- dupeFile path
setTags' dupe Nothing t sampleSetter
extracted <- getTags dupe (sampleGetter dupe)
extracted `shouldMatchTags` updateSampleTags (tags { atFileName = dupe })