packages feed

htaglib 1.0.3 → 1.0.4

raw patch · 12 files changed

+314/−356 lines, 12 filesdep +hspecdep −HUnitdep −test-frameworkdep −test-framework-hunitdep ~basedep ~bytestringdep ~directory

Dependencies added: hspec

Dependencies removed: HUnit, test-framework, test-framework-hunit

Dependency ranges changed: base, bytestring, directory, filepath, htaglib, text

Files

CHANGELOG.md view
@@ -1,3 +1,9 @@+## HTagLib 1.0.4++* Re-wrote the test suite with Hspec.++* Drop support for GHC 7.6.+ ## HTagLib 1.0.3  * Export functions instead of record selectors for tag newtype wrappers.
README.md view
@@ -128,13 +128,13 @@ ``` $ ./example "/home/mark/music/David Bowie/1977, Low/01 Speed of Life.flac" AudioTrack-  { atTitle   = Title   {unTitle   = "Speed of Life"}-  , atArtist  = Artist  {unArtist  = "David Bowie"}-  , atAlbum   = Album   {unAlbum   = "Low"}-  , atComment = Comment {unComment = ""}-  , atGenre   = Genre   {unGenre   = ""}-  , atYear    = Just    (Year {unYear = 1977})-  , atTrack   = Just    (TrackNumber {unTrackNumber = 1})+  { atTitle   = Title   "Speed of Life"+  , atArtist  = Artist  "David Bowie"+  , atAlbum   = Album   "Low"+  , atComment = Comment ""+  , atGenre   = Genre   ""+  , atYear    = Just    (Year 1977)+  , atTrack   = Just    (TrackNumber 1)   } ``` 
Sound/HTagLib/Internal.hs view
@@ -164,8 +164,8 @@  -- File API --- | Open audio file and return its ID (abstraction that rest of library can--- pass around). In case of trouble 'IOException' is thrown.+-- | Open audio file and return its ID (an opaque type that the rest of+-- library can pass around). In case of trouble 'IOException' is thrown.  newFile   :: FilePath          -- ^ Path to audio file
htaglib.cabal view
@@ -31,7 +31,7 @@ -- POSSIBILITY OF SUCH DAMAGE.  name:                htaglib-version:             1.0.3+version:             1.0.4 cabal-version:       >= 1.10 license:             BSD3 license-file:        LICENSE.md@@ -43,11 +43,11 @@ synopsis:            Bindings to TagLib, audio meta-data library build-type:          Simple description:         Bindings to TagLib, audio meta-data library.-extra-source-files:  CHANGELOG.md+extra-doc-files:     CHANGELOG.md                    , README.md                    , audio-samples/README.md-                   , audio-samples/sample.flac-                   , audio-samples/sample.mp3+data-files:          audio-samples/*.flac+                   , audio-samples/*.mp3  flag dev   description:       Turn on development settings.@@ -55,9 +55,9 @@   default:           False  library-  build-depends:     base       >= 4.6 && < 5-                   , bytestring >= 0.9-                   , text       >= 1.0+  build-depends:     base       >= 4.7 && < 5.0+                   , bytestring >= 0.9 && < 0.11+                   , text       >= 1.0 && < 1.3   extra-libraries:   tag_c   exposed-modules:   Sound.HTagLib                    , Sound.HTagLib.Type@@ -71,23 +71,21 @@   default-language:  Haskell2010  test-suite tests-  main-is:           Main.hs+  main-is:           Spec.hs   hs-source-dirs:    tests   type:              exitcode-stdio-1.0   if flag(dev)     ghc-options:     -O0 -Wall -Werror   else     ghc-options:     -O2 -Wall-  other-modules:     Getter-                   , Setter-                   , Util-  build-depends:     base                 >= 4.6 && < 5-                   , HUnit                >= 1.2 && < 1.4-                   , directory            >= 1.2-                   , filepath             >= 1.4 && < 2-                   , htaglib              >= 1.0-                   , test-framework       >= 0.6 && < 1-                   , test-framework-hunit >= 0.2 && < 0.4+  other-modules:     Sound.HTagLib.GetterSpec+                   , Sound.HTagLib.SetterSpec+                   , Sound.HTagLib.Test.Util+  build-depends:     base       >= 4.7 && < 5.0+                   , directory  >= 1.2 && < 1.3+                   , filepath   >= 1.4 && < 2.0+                   , hspec      >= 2.0 && < 3.0+                   , htaglib    >= 1.0.4   default-extensions:                      CPP   default-language:  Haskell2010
− tests/Getter.hs
@@ -1,60 +0,0 @@------ HTagLib tests, testing of getters.------ Copyright © 2015–2016 Mark Karpov------ Redistribution and use in source and binary forms, with or without--- modification, are permitted provided that the following conditions are--- met:------ * Redistributions of source code must retain the above copyright notice,---   this list of conditions and the following disclaimer.------ * Redistributions in binary form must reproduce the above copyright---   notice, this list of conditions and the following disclaimer in the---   documentation and/or other materials provided with the distribution.------ * Neither the name Mark Karpov nor the names of contributors may be used---   to endorse or promote products derived from this software without---   specific prior written permission.------ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY--- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED--- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE--- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY--- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL--- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS--- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)--- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,--- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN--- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE--- POSSIBILITY OF SUCH DAMAGE.--module Getter (tests) where--import Test.Framework-import Test.HUnit hiding (Test, path)--import Sound.HTagLib-import Util--#if !MIN_VERSION_base(4,8,0)-import Control.Applicative ((<$>))-#endif--tests :: Test-tests = testGroup "Getters" $-  fmap (caseWithFile (const simpleGetter)) fileList ++-  fmap (caseWithFile specializedGetter)    fileList--simpleGetter :: AudioTags -> Assertion-simpleGetter tags = do-  let path = atFileName tags-  extracted <- getTags path (id <$> sampleGetter path)-  extracted `cfbr` tags--specializedGetter :: FileType -> AudioTags -> Assertion-specializedGetter t tags = do-  let path = atFileName tags-  extracted <- getTags' path t (id <$> sampleGetter path)-  extracted `cfbr` tags
− tests/Main.hs
@@ -1,43 +0,0 @@------ HTagLib tests, main module.------ Copyright © 2015–2016 Mark Karpov------ Redistribution and use in source and binary forms, with or without--- modification, are permitted provided that the following conditions are--- met:------ * Redistributions of source code must retain the above copyright notice,---   this list of conditions and the following disclaimer.------ * Redistributions in binary form must reproduce the above copyright---   notice, this list of conditions and the following disclaimer in the---   documentation and/or other materials provided with the distribution.------ * Neither the name Mark Karpov nor the names of contributors may be used---   to endorse or promote products derived from this software without---   specific prior written permission.------ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY--- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED--- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE--- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY--- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL--- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS--- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)--- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,--- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN--- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE--- POSSIBILITY OF SUCH DAMAGE.--module Main (main) where--import Test.Framework (defaultMain)--import qualified Getter-import qualified Setter--main :: IO ()-main = defaultMain-       [ Getter.tests-       , Setter.tests ]
− tests/Setter.hs
@@ -1,85 +0,0 @@------ HTagLib tests, testing of Setters.------ Copyright © 2015–2016 Mark Karpov------ Redistribution and use in source and binary forms, with or without--- modification, are permitted provided that the following conditions are--- met:------ * Redistributions of source code must retain the above copyright notice,---   this list of conditions and the following disclaimer.------ * Redistributions in binary form must reproduce the above copyright---   notice, this list of conditions and the following disclaimer in the---   documentation and/or other materials provided with the distribution.------ * Neither the name Mark Karpov nor the names of contributors may be used---   to endorse or promote products derived from this software without---   specific prior written permission.------ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY--- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED--- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE--- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY--- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL--- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS--- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)--- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,--- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN--- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE--- POSSIBILITY OF SUCH DAMAGE.--{-# LANGUAGE OverloadedStrings #-}--module Setter (tests) where--import System.Directory (getTemporaryDirectory, copyFile)-import System.FilePath ((</>), takeFileName)--import Test.Framework-import Test.HUnit hiding (Test, path)--import Sound.HTagLib-import Util--#if !MIN_VERSION_base(4,8,0)-import Control.Applicative ((<$>))-#endif--tests :: Test-tests = testGroup "Setters" $-  fmap (caseWithFile (const simpleSetter)) fileList ++-  fmap (caseWithFile specializedGetter)    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 -> Assertion-simpleSetter tags = do-  let path = atFileName tags-  dupe <- dupeFile path-  setTags dupe Nothing sampleSetter-  extracted <- getTags dupe (sampleGetter dupe)-  extracted `cfbr` updateSampleTags (tags { atFileName = dupe })--specializedGetter :: FileType -> AudioTags -> Assertion-specializedGetter t tags = do-  let path = atFileName tags-  dupe <- dupeFile path-  setTags' dupe Nothing t sampleSetter-  extracted <- getTags dupe (sampleGetter dupe)-  extracted `cfbr` updateSampleTags (tags { atFileName = dupe })
+ tests/Sound/HTagLib/GetterSpec.hs view
@@ -0,0 +1,59 @@+--+-- HTagLib tests, testing of getters.+--+-- Copyright © 2015–2016 Mark Karpov+--+-- Redistribution and use in source and binary forms, with or without+-- modification, are permitted provided that the following conditions are+-- met:+--+-- * Redistributions of source code must retain the above copyright notice,+--   this list of conditions and the following disclaimer.+--+-- * Redistributions in binary form must reproduce the above copyright+--   notice, this list of conditions and the following disclaimer in the+--   documentation and/or other materials provided with the distribution.+--+-- * Neither the name Mark Karpov nor the names of contributors may be used+--   to endorse or promote products derived from this software without+--   specific prior written permission.+--+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY+-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+-- POSSIBILITY OF SUCH DAMAGE.++module Sound.HTagLib.GetterSpec (spec) where++import Sound.HTagLib+import Sound.HTagLib.Test.Util+import Test.Hspec++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>))+#endif++spec :: Spec+spec =+  describe "getters" $ do+    mapM_ (withFile $ const simpleGetter) fileList+    mapM_ (withFile specializedGetter)    fileList++simpleGetter :: AudioTags -> Expectation+simpleGetter tags = do+  let path = atFileName tags+  extracted <- getTags path (id <$> sampleGetter path)+  extracted `shouldMatchTags` tags++specializedGetter :: FileType -> AudioTags -> Expectation+specializedGetter t tags = do+  let path = atFileName tags+  extracted <- getTags' path t (id <$> sampleGetter path)+  extracted `shouldMatchTags` tags
+ tests/Sound/HTagLib/SetterSpec.hs view
@@ -0,0 +1,83 @@+--+-- HTagLib tests, testing of Setters.+--+-- Copyright © 2015–2016 Mark Karpov+--+-- Redistribution and use in source and binary forms, with or without+-- modification, are permitted provided that the following conditions are+-- met:+--+-- * Redistributions of source code must retain the above copyright notice,+--   this list of conditions and the following disclaimer.+--+-- * Redistributions in binary form must reproduce the above copyright+--   notice, this list of conditions and the following disclaimer in the+--   documentation and/or other materials provided with the distribution.+--+-- * Neither the name Mark Karpov nor the names of contributors may be used+--   to endorse or promote products derived from this software without+--   specific prior written permission.+--+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY+-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+-- POSSIBILITY OF SUCH DAMAGE.++{-# 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 })
+ tests/Sound/HTagLib/Test/Util.hs view
@@ -0,0 +1,140 @@+--+-- HTagLib tests, utility definitions.+--+-- Copyright © 2015–2016 Mark Karpov+--+-- Redistribution and use in source and binary forms, with or without+-- modification, are permitted provided that the following conditions are+-- met:+--+-- * Redistributions of source code must retain the above copyright notice,+--   this list of conditions and the following disclaimer.+--+-- * Redistributions in binary form must reproduce the above copyright+--   notice, this list of conditions and the following disclaimer in the+--   documentation and/or other materials provided with the distribution.+--+-- * Neither the name Mark Karpov nor the names of contributors may be used+--   to endorse or promote products derived from this software without+--   specific prior written permission.+--+-- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY+-- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+-- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+-- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY+-- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL+-- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS+-- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)+-- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,+-- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN+-- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE+-- POSSIBILITY OF SUCH DAMAGE.++{-# LANGUAGE OverloadedStrings #-}++module Sound.HTagLib.Test.Util+  ( AudioTags (..)+  , sampleGetter+  , sampleSetter+  , fileList+  , withFile+  , shouldMatchTags )+where++import Data.Maybe (fromJust)+import Data.Monoid+import Sound.HTagLib+import Test.Hspec++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative ((<$>), (<*>), pure)+#endif++data AudioTags = AudioTags+  { atFileName    :: FilePath+  , atTitle       :: Title+  , atArtist      :: Artist+  , atAlbum       :: Album+  , atComment     :: Comment+  , atGenre       :: Genre+  , atYear        :: Maybe Year+  , atTrackNumber :: Maybe TrackNumber+  , atDuration    :: Duration+  , atBitRate     :: BitRate+  , atSampleRate  :: SampleRate+  , atChannels    :: Channels }+  deriving (Show, Eq)++sampleGetter :: FilePath -> TagGetter AudioTags+sampleGetter path = AudioTags+  <$> pure path+  <*> titleGetter+  <*> artistGetter+  <*> albumGetter+  <*> commentGetter+  <*> genreGetter+  <*> yearGetter+  <*> trackNumberGetter+  <*> durationGetter+  <*> bitRateGetter+  <*> sampleRateGetter+  <*> channelsGetter++sampleSetter :: TagSetter+sampleSetter =+  mempty <>+  titleSetter (mkTitle "title'") <>+  artistSetter (mkArtist "artist'") <>+  albumSetter (mkAlbum "album'") <>+  commentSetter (mkComment "comment'") <>+  genreSetter (mkGenre "genre'") <>+  yearSetter (mkYear 2056) <>+  trackNumberSetter (mkTrackNumber 8)++sampleTags :: AudioTags+sampleTags = AudioTags+  { atFileName    = undefined+  , atTitle       = "title"+  , atArtist      = "artist"+  , atAlbum       = "album"+  , atComment     = "comment"+  , atGenre       = "genre"+  , atYear        = mkYear 2055+  , atTrackNumber = mkTrackNumber 7+  , atDuration    = fromJust $ mkDuration 0+  , atBitRate     = fromJust $ mkBitRate 0+  , atSampleRate  = fromJust $ mkSampleRate 44100+  , atChannels    = fromJust $ mkChannels 2 }++fileList :: [(FileType, AudioTags)]+fileList =+  [ (FLAC, sampleTags+     { atBitRate = fromJust $ mkBitRate 217+     , atFileName = "audio-samples/sample.flac" })+  , (MPEG, sampleTags+     { atBitRate = fromJust $ mkBitRate 136+     , atFileName = "audio-samples/sample.mp3"  }) ]++-- | Call given function with provided data.++withFile+  :: (FileType -> AudioTags -> Expectation)+  -> (FileType, AudioTags)+  -> Spec+withFile f (t, tags) = it name (f t tags)+  where name = "using file: " ++ show (atFileName tags) ++ " (" ++ show t ++ ")"++-- | Create an expectation that two collections of tags match. However, if+-- bit rate of the first is zero (which is the case with older versions of+-- TagLib when it's used with such short files as our samples), allow bit+-- rate values differ.++shouldMatchTags+  :: AudioTags         -- ^ Tags to test+  -> AudioTags         -- ^ Correct tags to test against+  -> Expectation+shouldMatchTags given expected =+  let zeroBitRate = fromJust (mkBitRate 0)+  in if atBitRate given == zeroBitRate+       then given `shouldBe` expected { atBitRate = zeroBitRate }+       else given `shouldBe` expected
+ tests/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}
− tests/Util.hs
@@ -1,141 +0,0 @@------ HTagLib tests, utility definitions.------ Copyright © 2015–2016 Mark Karpov------ Redistribution and use in source and binary forms, with or without--- modification, are permitted provided that the following conditions are--- met:------ * Redistributions of source code must retain the above copyright notice,---   this list of conditions and the following disclaimer.------ * Redistributions in binary form must reproduce the above copyright---   notice, this list of conditions and the following disclaimer in the---   documentation and/or other materials provided with the distribution.------ * Neither the name Mark Karpov nor the names of contributors may be used---   to endorse or promote products derived from this software without---   specific prior written permission.------ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS “AS IS” AND ANY--- EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED--- WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE--- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY--- DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL--- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS--- OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)--- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,--- STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN--- ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE--- POSSIBILITY OF SUCH DAMAGE.--{-# LANGUAGE OverloadedStrings #-}--module Util-  ( AudioTags (..)-  , sampleGetter-  , sampleSetter-  , fileList-  , caseWithFile-  , cfbr )-where--import Data.Maybe (fromJust)-import Data.Monoid-import Sound.HTagLib--import Test.Framework-import Test.Framework.Providers.HUnit (testCase)-import Test.HUnit hiding (Test, path)--#if !MIN_VERSION_base(4,8,0)-import Control.Applicative ((<$>), (<*>), pure)-#endif--data AudioTags = AudioTags-  { atFileName    :: FilePath-  , atTitle       :: Title-  , atArtist      :: Artist-  , atAlbum       :: Album-  , atComment     :: Comment-  , atGenre       :: Genre-  , atYear        :: Maybe Year-  , atTrackNumber :: Maybe TrackNumber-  , atDuration    :: Duration-  , atBitRate     :: BitRate-  , atSampleRate  :: SampleRate-  , atChannels    :: Channels }-  deriving (Show, Eq)--sampleGetter :: FilePath -> TagGetter AudioTags-sampleGetter path = AudioTags-  <$> pure path-  <*> titleGetter-  <*> artistGetter-  <*> albumGetter-  <*> commentGetter-  <*> genreGetter-  <*> yearGetter-  <*> trackNumberGetter-  <*> durationGetter-  <*> bitRateGetter-  <*> sampleRateGetter-  <*> channelsGetter--sampleSetter :: TagSetter-sampleSetter =-  mempty <>-  titleSetter (mkTitle "title'") <>-  artistSetter (mkArtist "artist'") <>-  albumSetter (mkAlbum "album'") <>-  commentSetter (mkComment "comment'") <>-  genreSetter (mkGenre "genre'") <>-  yearSetter (mkYear 2056) <>-  trackNumberSetter (mkTrackNumber 8)--sampleTags :: AudioTags-sampleTags = AudioTags-  { atFileName    = undefined-  , atTitle       = "title"-  , atArtist      = "artist"-  , atAlbum       = "album"-  , atComment     = "comment"-  , atGenre       = "genre"-  , atYear        = mkYear 2055-  , atTrackNumber = mkTrackNumber 7-  , atDuration    = fromJust $ mkDuration 0-  , atBitRate     = fromJust $ mkBitRate 0-  , atSampleRate  = fromJust $ mkSampleRate 44100-  , atChannels    = fromJust $ mkChannels 2 }--fileList :: [(FileType, AudioTags)]-fileList =-  [ (FLAC, sampleTags-     { atBitRate = fromJust $ mkBitRate 217-     , atFileName = "audio-samples/sample.flac" })-  , (MPEG, sampleTags-     { atBitRate = fromJust $ mkBitRate 136-     , atFileName = "audio-samples/sample.mp3"  }) ]--caseWithFile-  :: (FileType -> AudioTags -> Assertion)-  -> (FileType, AudioTags)-  -> Test-caseWithFile f (t, tags) = testCase name (f t tags)-  where name = "using file: " ++ show (atFileName tags) ++ " (" ++ show t ++ ")"---- | Create 'Assertion' that two collections of tags match. However, if bit--- rate of the first is zero (which is the case with older versions of--- TagLib when it's used with such short files as our samples), allow bit--- rate values differ.--cfbr-  :: AudioTags         -- ^ Tags to test-  -> AudioTags         -- ^ Correct tags to test against-  -> Assertion-cfbr n tags =-  let zeroBitRate = fromJust (mkBitRate 0)-  in if atBitRate n == zeroBitRate-       then n @?= tags { atBitRate = zeroBitRate }-       else n @?= tags