epub-tools 1.1.0 → 1.1.1
raw patch · 10 files changed
+1148/−1025 lines, 10 files
Files
- epub-tools.cabal +7/−4
- src/EpubTools/EpubMeta/Opts.hs +1/−1
- src/EpubTools/EpubName/Format.hs +2/−15
- src/EpubTools/EpubName/Opts.hs +18/−9
- src/EpubTools/EpubName/PubYear.hs +56/−0
- src/EpubTools/EpubZip/Opts.hs +1/−1
- testsuite/EpubTools/Test/EpubName/Format.hs +1000/−0
- testsuite/EpubTools/Test/EpubName/PubYear.hs +29/−0
- testsuite/EpubTools/test-epubname.hs +34/−0
- testsuite/epubname.hs +0/−995
epub-tools.cabal view
@@ -1,6 +1,6 @@ name: epub-tools cabal-version: >= 1.8-version: 1.1.0+version: 1.1.1 build-type: Simple license: BSD3 license-file: LICENSE@@ -13,7 +13,8 @@ description: A suite of command-line utilities for creating and manipulating epub book files. Included are: epubmeta, epubname, epubzip category: Application, Console tested-with: GHC >= 7.0.3-extra-source-files: testsuite/*.hs+extra-source-files: testsuite/EpubTools/*.hs+ testsuite/EpubTools/Test/EpubName/*.hs source-repository head type: darcs@@ -44,6 +45,7 @@ other-modules: EpubTools.EpubName.Author EpubTools.EpubName.Format EpubTools.EpubName.Opts+ EpubTools.EpubName.PubYear EpubTools.EpubName.Util -- Strip symbols from binary, for Windows, not portable, see [1] below@@ -52,8 +54,9 @@ test-suite epubname-tests type: exitcode-stdio-1.0- main-is: epubname.hs- build-depends: base, epub-metadata >= 2.2, HUnit, mtl, regex-compat+ main-is: EpubTools/test-epubname.hs+ build-depends: base, directory, epub-metadata >= 2.2, HUnit, mtl,+ regex-compat hs-source-dirs: src testsuite ghc-options: -Wall
src/EpubTools/EpubMeta/Opts.hs view
@@ -103,5 +103,5 @@ , "" , "For more information please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , ""- , "Version 1.1.0 Dino Morelli <dino@ui3.info>"+ , "Version 1.1.1 Dino Morelli <dino@ui3.info>" ]
src/EpubTools/EpubName/Format.hs view
@@ -15,6 +15,7 @@ import EpubTools.EpubName.Author import EpubTools.EpubName.Opts+import EpubTools.EpubName.PubYear import EpubTools.EpubName.Util @@ -253,7 +254,7 @@ book :: Metadata -> EN (String, [String]) book md = do (title:_) <- extractTitle md "(.*)"- year <- extractYear md+ year <- getPubYear md return ("book", [extractAuthors md, filterCommon title, year]) @@ -281,20 +282,6 @@ case matchRegex (mkRegex re) oldTitle of Just matches -> return matches Nothing -> throwError $ printf "extract title failed: %s" re---{- Look for a date tag with event="original-publication" in the- metadata--}-extractYear :: Metadata -> EN String-extractYear md = do- inclY <- asks optYear- return . maybe "" ('_' :) $- (foldr mplus Nothing (map (maybeYear inclY) $ metaDates md))-- where- maybeYear True (MetaDate (Just "original-publication") d) = Just d- maybeYear _ _ = Nothing extractPublisher :: Metadata -> Bool -> String
src/EpubTools/EpubName/Opts.hs view
@@ -4,7 +4,7 @@ module EpubTools.EpubName.Opts- ( Options (..)+ ( PubYear (..), Options (..) , defaultOptions , parseOpts, usageText )@@ -15,13 +15,19 @@ import System.Exit +data PubYear+ = Publication -- Default, use date event='publication' or 'original-publication'+ | AnyDate -- Use first date element found+ | NoDate -- Don't do publication date at all++ data Options = Options { optHelp :: Bool , optNoAction :: Bool , optOverwrite :: Bool , optPublisher :: Bool , optVerbose :: Maybe Int- , optYear :: Bool+ , optPubYear :: PubYear } @@ -32,13 +38,19 @@ , optOverwrite = False , optPublisher = False , optVerbose = Nothing- , optYear = True+ , optPubYear = Publication } options :: [OptDescr (Options -> Options)] options =- [ Option ['h'] ["help"] + [ Option ['d'] ["any-date"]+ (NoArg (\opts -> opts { optPubYear = AnyDate } )) + "If no publication year found, use first date element of any kind"+ , Option ['D'] ["no-date"]+ (NoArg (\opts -> opts { optPubYear = NoDate } )) + "Suppress inclusion of original publication year"+ , Option ['h'] ["help"] (NoArg (\opts -> opts { optHelp = True } )) "This help text" , Option ['n'] ["no-action"]@@ -55,9 +67,6 @@ ((\n opts -> opts { optVerbose = Just (read n)}) . fromMaybe "1") "LEVEL") "Verbosity level: 1, 2"- , Option ['y'] ["year"]- (NoArg (\opts -> opts { optPublisher = True } )) - "Suppress inclusion of original publication year, if present" ] @@ -104,7 +113,7 @@ , "" , "Only creator tags with either a role attribute of 'aut' or no role at all are considered authors. If a file-as attribute is present, this will be the preferred string. If not, the program tries to do some intelligent parsing of the name." , ""- , "The publication year is taken from the first date tag with an event attribute of 'original-publication', if present. The OPF spec is a little thin on this. I noticed frequent use of this attribute in books, and so went with that."+ , "The OPF spec suggests there may be a <dc:date event='publication'>2011</date> element representing original publication date. If this is present, or event='original-publication', it will be used by default. The --any-date switch will fall back to the first date found as necessary. The year can be parsed out of many date formats, it's very flexible." , "" , "Publisher: I wanted to provide a way to have multiple copies of the same book produced by different publishers and name them sort-of unambiguously. I came up with the idea of expecting a contributor tag with role attribute of 'bkp' (so far, this is fairly normal). And then use a file-as attribute on that tag to contain a small string to be used in the filename. The idea here is short and sweet for the file-as." , ""@@ -112,5 +121,5 @@ , "" , "For more information please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , ""- , "Version 1.1.0 Dino Morelli <dino@ui3.info>"+ , "Version 1.1.1 Dino Morelli <dino@ui3.info>" ]
+ src/EpubTools/EpubName/PubYear.hs view
@@ -0,0 +1,56 @@+-- Copyright: 2011 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++module EpubTools.EpubName.PubYear+ ( extractYear+ , getPubYear+ )+ where++import Codec.Epub.Opf.Package+import Control.Monad+import Text.Regex++import EpubTools.EpubName.Opts+import EpubTools.EpubName.Util+++{- Look for publication date, return "" if none found+-}+getPubYear :: Metadata -> EN String+getPubYear md = do+ yearHandling <- asks optPubYear++ case yearHandling of+ Publication -> getPubYear' pubAttrs+ AnyDate -> getPubYear' $ pubAttrs ++ [getFirstDate]+ NoDate -> return ""++ where+ getPubYear' = return . maybe "" ('_' :) . foldr mplus Nothing .+ map (\f -> f (metaDates md))++ pubAttrs =+ [ getDateWithAttr "publication"+ , getDateWithAttr "original-publication"+ ]+++getDateWithAttr :: String -> [MetaDate] -> Maybe String+getDateWithAttr attrVal mds = foldr mplus Nothing $ map getPublication' mds+ where+ getPublication' (MetaDate (Just av) d)+ | av == attrVal = extractYear d+ getPublication' _ = Nothing+++getFirstDate :: [MetaDate] -> Maybe String+getFirstDate ((MetaDate _ d) : _) = extractYear d+getFirstDate _ = Nothing+++extractYear :: String -> Maybe String+extractYear s = case matchRegex (mkRegex "(^| )([0-9]{4})") s of+ Just (_ : y : []) -> Just y+ _ -> Nothing
src/EpubTools/EpubZip/Opts.hs view
@@ -68,5 +68,5 @@ , "" , "For more information please see the IDPF OPF specification found here: http://idpf.org/epub/20/spec/OPF_2.0.1_draft.htm" , ""- , "Version 1.1.0 Dino Morelli <dino@ui3.info>"+ , "Version 1.1.1 Dino Morelli <dino@ui3.info>" ]
+ testsuite/EpubTools/Test/EpubName/Format.hs view
@@ -0,0 +1,1000 @@+-- Copyright: 2011 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++module EpubTools.Test.EpubName.Format+ ( formatTests+ )+ where++import Codec.Epub.Opf.Package.Metadata+import Test.HUnit ( Test (..), assertEqual )+import Test.HUnit.Base ( Assertion )++import EpubTools.EpubName.Format ( tryFormatting )+import EpubTools.EpubName.Opts+import EpubTools.EpubName.Util+++formatTests :: Test+formatTests = TestLabel "Format" $ TestList+ [ testAuthorMinimal+ , testAuthorOneName+ , testAuthorRole+ , testAuthorFileas+ , testAuthorFull+ , testAuthorSeveral+ , testSeveralAuthors+ , testNoAuthor+ , testCreatorsNoAuthor+ , testCreatorsNoAuthorPubDate+ , testCapsTitle+ , testColon+ , testBracketTitle+ , testNoTitle+ , testAllPunctuation+ , testPubYear+ , testPubYearAny+ , testPubYearUnwanted+ , testMagAeon+ , testMagAEon+ , testMagApexLong+ , testMagApexShort+ , testChallengingDestinyShort+ , testChallengingDestinyLong+ , testAnalog+ , testAsimovs+ , testFantasyMagazine+ , testFsfShort+ , testFsfLong+ , testFsfAmpersand+ , testMagFutureOrbits+ , testGudShort+ , testGudLong+ , testGudVeryLong+ , testInterzoneShort+ , testInterzoneLong+ , testNemesisShort+ , testNemesisLong+ , testMagSomethingWicked+ , testMagSomethingWickedMonth+ , testSFBestOf+ , testBestSF+ , testYearsBest+ , testMagBlackStatic+ , testRageMachineMag+ , testEclipseMag+ , testBcs+ , testBkpFileAs+ , testBkpText+ , testBkpMissing+ , testMagUniverse+ , testMagClarkesworld+ , testLightspeedDate+ , testLightspeedIssue+ , testMagWeirdTales+ ]+++assertNewNameOpts :: Options -> String -> Metadata + -> (String, String) -> Assertion+assertNewNameOpts opts desc meta expected = do+ result <- runEN opts $ tryFormatting "" meta+ let actual = either (\em -> ("NO FORMATTER", em)) id result+ assertEqual desc expected actual+++assertNewName :: String -> Metadata -> (String, String) -> Assertion+assertNewName = assertNewNameOpts defaultOptions+++testAuthorMinimal :: Test+testAuthorMinimal = TestCase $+ assertNewName "minimal author" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Herman Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testAuthorOneName :: Test+testAuthorOneName = TestCase $+ assertNewName "author is a single word" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "Melville-MobyDick.epub"+ )+++testAuthorRole :: Test+testAuthorRole = TestCase $+ assertNewName "author with role" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Herman Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testAuthorFileas :: Test+testAuthorFileas = TestCase $+ assertNewName "author with file-as" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing+ (Just "Melville, Herman")+ "Herman Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testAuthorFull :: Test+testAuthorFull = TestCase $+ assertNewName "author fully filled out" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut")+ (Just "Melville, Herman")+ "Herman Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testAuthorSeveral :: Test+testAuthorSeveral = TestCase $+ assertNewName "several authors" meta expected+ where+ meta = emptyMetadata+ { metaCreators =+ [ MetaCreator (Just "aut") Nothing+ "James Patrick Kelly"+ , MetaCreator (Just "aut") (Just "Kessel, John")+ "John Kessel"+ , MetaCreator (Just "aut") Nothing+ "Jonathan Lethem"+ ]+ , metaTitles = [MetaTitle Nothing+ "Ninety Percent of Everything"]+ }+ expected =+ ( "book"+ , "Kelly_Kessel_Lethem-NinetyPercentOfEverything.epub"+ )+++testNoAuthor :: Test+testNoAuthor = TestCase $+ assertNewName "no creator(s) at all" meta expected+ where+ meta = emptyMetadata+ { metaCreators = []+ , metaTitles = [MetaTitle Nothing+ "Some Collection of Fine Stories, Volume 1"]+ }+ expected =+ ( "book"+ , "SomeCollectionOfFineStoriesVolume1.epub"+ )+++testCreatorsNoAuthor :: Test+testCreatorsNoAuthor = TestCase $+ assertNewName "creators, but no author(s) at all" meta expected+ where+ meta = emptyMetadata+ { metaCreators =+ [ MetaCreator (Just "edt") Nothing+ "Graham Spindlewest"+ , MetaCreator (Just "ill") Nothing+ "Eva Tunglewacker"+ ]+ , metaTitles = [MetaTitle Nothing+ "Some Collection of Fine Stories, Volume 1"]+ }+ expected =+ ( "book"+ , "SomeCollectionOfFineStoriesVolume1.epub"+ )+++testCreatorsNoAuthorPubDate :: Test+testCreatorsNoAuthorPubDate = TestCase $+ assertNewName "creators, but no author(s) at all, with pub date" + meta expected+ where+ meta = emptyMetadata+ { metaCreators =+ [ MetaCreator (Just "edt") Nothing+ "Graham Spindlewest"+ , MetaCreator (Just "ill") Nothing+ "Eva Tunglewacker"+ ]+ , metaTitles = [MetaTitle Nothing+ "Some Collection of Fine Stories, Volume 1"]+ , metaDates = [MetaDate (Just "publication")+ "2008"]+ }+ expected =+ ( "book"+ , "SomeCollectionOfFineStoriesVolume1_2008.epub"+ )+++testSeveralAuthors :: Test+testSeveralAuthors = TestCase $+ assertNewName "more than one author separated by & and/or and" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Yvonne Q. Anderson & Eva Tunglewacker and Jefferson Milner"]+ , metaTitles = [MetaTitle Nothing "Big Trouble"]+ }+ expected =+ ( "book"+ , "Anderson_Tunglewacker_Milner-BigTrouble.epub"+ )+++testCapsTitle :: Test+testCapsTitle = TestCase $+ assertNewName "title all caps" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Greg Bear"]+ , metaTitles = [MetaTitle Nothing "EON"]+ }+ expected =+ ( "book"+ , "BearGreg-Eon.epub"+ )+++testColon :: Test+testColon = TestCase $+ assertNewName "colon becomes underscore" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Ed Howdershelt"]+ , metaTitles = [MetaTitle Nothing + "Book 1: 3rd World Products, Inc."]+ }+ expected =+ ( "book"+ , "HowdersheltEd-Book1_3rdWorldProductsInc.epub"+ )+++testBracketTitle :: Test+testBracketTitle = TestCase $+ assertNewName "title with brackets" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Mercedes Lackey"]+ , metaTitles = [MetaTitle Nothing "SKitty [Shipscat series #1]"]+ }+ expected =+ ( "book"+ , "LackeyMercedes-Skitty_ShipscatSeries1.epub"+ )+++testNoTitle :: Test+testNoTitle = TestCase $+ assertNewName "missing title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Nobody McCrankypants"]+ }+ expected =+ ( "NO FORMATTER"+ , " [ERROR No formatter found]"+ )+++testAllPunctuation :: Test+testAllPunctuation = TestCase $+ assertNewName "big test of all punctuation" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Dino Morelli"]+ , metaTitles = [MetaTitle Nothing+ "The *crazy*: Sand-box. Of Smedley's discontent, fear & Malnourishment? (Maybe not!); [Part #2]"]+ }+ expected =+ ( "book"+ , "MorelliDino-TheCrazy_SandBoxOfSmedleysDiscontentFearAndMalnourishmentMaybeNot_Part2.epub"+ )+++testPubYear :: Test+testPubYear = TestCase $+ assertNewName "book with a publication year" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Jim Jones"]+ , metaTitles = [MetaTitle Nothing "A Timeless Story"]+ , metaDates = [MetaDate (Just "publication") "2003"]+ }+ expected =+ ( "book"+ , "JonesJim-ATimelessStory_2003.epub"+ )+++testPubYearAny :: Test+testPubYearAny = TestCase $+ assertNewNameOpts opts+ "book with original-publication attr and --any-date"+ meta expected+ where+ opts = defaultOptions { optPubYear = AnyDate }+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Jim Jones"]+ , metaTitles = [MetaTitle Nothing "A Timeless Story"]+ , metaDates = [MetaDate (Just "original-publication") "2003"]+ }+ expected =+ ( "book"+ , "JonesJim-ATimelessStory_2003.epub"+ )+++testPubYearUnwanted :: Test+testPubYearUnwanted = TestCase $+ assertNewNameOpts opts+ "book with a publication year but we don't want"+ meta expected+ where+ opts = defaultOptions { optPubYear = NoDate }+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Jim Jones"]+ , metaTitles = [MetaTitle Nothing "A Timeless Story"]+ , metaDates = [MetaDate (Just "original-publication") "2003"]+ }+ expected =+ ( "book"+ , "JonesJim-ATimelessStory.epub"+ )+++testMagAeon :: Test+testMagAeon = TestCase $+ assertNewName "Aeon magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "Aeon Authors"]+ , metaTitles = [MetaTitle Nothing "Aeon Eight"]+ }+ expected =+ ( "magAeon"+ , "AeonMagazine08.epub"+ )+++testMagAEon :: Test+testMagAEon = TestCase $+ assertNewName "AEon magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing "AEon Authors"]+ , metaTitles = [MetaTitle Nothing "Aeon Thirteen"]+ }+ expected =+ ( "magAeon"+ , "AeonMagazine13.epub"+ )+++testMagApexLong :: Test+testMagApexLong = TestCase $+ assertNewName "Apex Magazine, older, long title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Apex Authors"]+ , metaTitles = [MetaTitle Nothing+ "Apex Science Fiction and Horror Digest #9"]+ }+ expected =+ ( "magApex"+ , "ApexMagazine009.epub"+ )+++testMagApexShort :: Test+testMagApexShort = TestCase $+ assertNewName "Apex Magazine, newer, short title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Apex Authors"]+ , metaTitles = [MetaTitle Nothing+ "Apex Magazine Issue 17"]+ }+ expected =+ ( "magApex"+ , "ApexMagazine017.epub"+ )+++testChallengingDestinyShort :: Test+testChallengingDestinyShort = TestCase $+ assertNewName "Challenging Destiny Magazine, short title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Crystalline Sphere Authors"]+ , metaTitles = [MetaTitle Nothing+ "Challenging Destiny #23"]+ }+ expected =+ ( "magChallengingDestiny"+ , "ChallengingDestinyMagazine023.epub"+ )+++testChallengingDestinyLong :: Test+testChallengingDestinyLong = TestCase $+ assertNewName "Challenging Destiny Magazine, long title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Crystalline Sphere Authors"]+ , metaTitles = [MetaTitle Nothing + "Challenging Destiny #24: August 2007"]+ }+ expected =+ ( "magChallengingDestiny"+ , "ChallengingDestinyMagazine024.epub"+ )+++testAnalog :: Test+testAnalog = TestCase $+ assertNewName "Analog" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Dell Magazine Authors"]+ , metaTitles = [MetaTitle Nothing+ "Analog SFF, July-August 2003"]+ }+ expected =+ ( "magAnalog"+ , "AnalogSF2003-07_08.epub"+ )+++testAsimovs :: Test+testAsimovs = TestCase $+ assertNewName "Asimovs" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Dell Magazine Authors"]+ , metaTitles = [MetaTitle Nothing+ "Asimov's SF, August 2003"]+ }+ expected =+ ( "magAnalog"+ , "AsimovsSF2003-08.epub"+ )++testFantasyMagazine :: Test+testFantasyMagazine = TestCase $+ assertNewName "Fantasy Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators =+ [ MetaCreator (Just "aut") (Just "Howard, Kat & Tanzer, Molly & Beagle, Peter S. & Howard, Jonathan L. & Valentine, Genevieve & Vaughn, Carrie & Pilinovsky, Helen") "Kat Howard"+ , MetaCreator (Just "aut") Nothing "Molly Tanzer"+ , MetaCreator (Just "aut") Nothing "Peter S. Beagle"+ , MetaCreator (Just "aut") Nothing "Jonathan L. Howard"+ , MetaCreator (Just "aut") Nothing "Genevieve Valentine"+ , MetaCreator (Just "aut") Nothing "Carrie Vaughn"+ , MetaCreator (Just "aut") Nothing "Helen Pilinovsky"+ ]+ , metaTitles = [MetaTitle Nothing+ "Fantasy Magazine Issue 49"]+ }+ expected =+ ( "magFantasyMag"+ , "FantasyMagazine049.epub"+ )+++testFsfShort :: Test+testFsfShort = TestCase $+ assertNewName "FSF Magazine, short" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Spilogale Authors"]+ , metaTitles = [MetaTitle Nothing "FSF, April 2008"]+ }+ expected =+ ( "magFsf"+ , "FantasyScienceFiction2008-04.epub"+ )+++testFsfLong :: Test+testFsfLong = TestCase $+ assertNewName "FSF Magazine, long" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Spilogale Authors"]+ , metaTitles = [MetaTitle Nothing + "FSF Magazine, April 2006"]+ }+ expected =+ ( "magFsf"+ , "FantasyScienceFiction2006-04.epub"+ )+++testFsfAmpersand :: Test+testFsfAmpersand = TestCase $+ assertNewName "FSF Magazine, ampersand" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing+ "Spilogale"]+ , metaTitles = [MetaTitle Nothing "F & SF Dec 2003"]+ }+ expected =+ ( "magFsf"+ , "FantasyScienceFiction2003-12.epub"+ )+++testMagFutureOrbits :: Test+testMagFutureOrbits = TestCase $+ assertNewName "testMagFutureOrbits" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Vander Neut Publications, L.L.C."]+ , metaTitles = [MetaTitle Nothing + "Future Orbits Issue 5, June/July 2002"]+ }+ expected =+ ( "magFutureOrbits"+ , "FutureOrbitsMagazine05_2002-06_07.epub"+ )+++testGudShort :: Test+testGudShort = TestCase $+ assertNewName "Gud Magazine, short" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "GUD Magazine Authors"]+ , metaTitles = [MetaTitle Nothing + "GUD Magazine Issue 0 :: Spring 2007"]+ }+ expected =+ ( "magGud"+ , "GUDMagazine00.epub"+ )+++testGudLong :: Test+testGudLong = TestCase $+ assertNewName "Gud Magazine, long" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "GUD Magazine Authors, Jeff Somers, Jeremy Shipp"]+ , metaTitles = [MetaTitle Nothing + "GUD Magazine Issue 2 :: Spring 2008"]+ }+ expected =+ ( "magGud"+ , "GUDMagazine02.epub"+ )+++testGudVeryLong :: Test+testGudVeryLong = TestCase $+ assertNewName "Gud Magazine, very long" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "GUD Magazine Authors"]+ , metaTitles = [MetaTitle Nothing + "Greatest Uncommon Denominator Magazine Issue 4 :: Spring 2009"]+ }+ expected =+ ( "magGud"+ , "GUDMagazine04.epub"+ )+++testInterzoneShort :: Test+testInterzoneShort = TestCase $+ assertNewName "Interzone Magazine, short" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "TTA Press Authors"]+ , metaTitles = [MetaTitle Nothing + "Interzone SFF #212"]+ }+ expected =+ ( "magInterzone"+ , "InterzoneSFF212.epub"+ )+++testInterzoneLong :: Test+testInterzoneLong = TestCase $+ assertNewName "Interzone Magazine, long" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "TTA Press Authors"]+ , metaTitles = [MetaTitle Nothing + "Interzone Science Fiction and Fantasy Magazine #216"]+ }+ expected =+ ( "magInterzone"+ , "InterzoneSFF216.epub"+ )+++testNemesisShort :: Test+testNemesisShort = TestCase $+ assertNewName "Nemesis Magazine, short" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Stephen Adams"]+ , metaTitles = [MetaTitle Nothing + "Nemesis Magazine #2"]+ }+ expected =+ ( "magNemesis"+ , "NemesisMag002.epub"+ )+++testNemesisLong :: Test+testNemesisLong = TestCase $+ assertNewName "Nemesis Magazine, long" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Stephen Adams"]+ , metaTitles = [MetaTitle Nothing + "Nemesis Magazine #7: Featuring Victory Rose in Death Stalks the Ruins"]+ }+ expected =+ ( "magNemesis"+ , "NemesisMag007.epub"+ )+++testMagSomethingWicked :: Test+testMagSomethingWicked = TestCase $+ assertNewName "Something Wicked Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Something Wicked Authors"]+ , metaTitles = [MetaTitle Nothing + "Something Wicked SF and Horror Magazine #5"]+ }+ expected =+ ( "magSomethingWicked"+ , "SomethingWicked005.epub"+ )+++testMagSomethingWickedMonth :: Test+testMagSomethingWickedMonth = TestCase $+ assertNewName "Something Wicked Magazine, month in title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut")+ (Just "Authors, Something Wicked")+ "Something Wicked Authors"]+ , metaTitles = [MetaTitle Nothing + "Something Wicked #14 (October 2011)"]+ }+ expected =+ ( "magSomethingWicked"+ , "SomethingWicked014.epub"+ )+++testSFBestOf :: Test+testSFBestOf = TestCase $+ assertNewName "Science Fiction: The Best of the Year" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "Rich Horton"]+ , metaTitles = [MetaTitle Nothing + "Science Fiction: The Best of the Year, 2007 Edition"]+ }+ expected =+ ( "compOfTheYear"+ , "ScienceFiction_TheBestOfTheYear2007Edition.epub"+ )+++testBestSF :: Test+testBestSF = TestCase $+ assertNewName "The Best Science Fiction and Fantasy of the Year"+ meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut")+ (Just "Strahan, Jonathan")+ "Jonathan Strahan"]+ , metaTitles = [MetaTitle Nothing + "The Best Science Fiction and Fantasy of the Year: Volume 2"]+ }+ expected =+ ( "compOfTheYear"+ , "TheBestScienceFictionAndFantasyOfTheYear_Volume2.epub"+ )+++testYearsBest :: Test+testYearsBest = TestCase $+ assertNewName "The Year's Best SF" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing + "Rich Horton, Michael Swanwick, Karen Joy Fowler"]+ , metaTitles = [MetaTitle Nothing + "The Year's Best Science Fiction: 2008 Edition"]+ }+ expected =+ ( "compYearsBest"+ , "TheYearsBestScienceFiction_2008Edition.epub"+ )+++testMagBlackStatic :: Test+testMagBlackStatic = TestCase $+ assertNewName "Black Static Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator Nothing Nothing + "TTA Press Authors"]+ , metaTitles = [MetaTitle Nothing + "Black Static Horror Magazine #5"]+ }+ expected =+ ( "magBlackStatic"+ , "BlackStaticHorrorMagazine05.epub"+ )+++testRageMachineMag :: Test+testRageMachineMag = TestCase $+ assertNewName "Rage Machine Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "edt") Nothing + "G. W. Thomas"]+ , metaTitles = [MetaTitle Nothing + "Rage Machine Magazine #1--December 2005"]+ }+ expected =+ ( "magRageMachine"+ , "RageMachineMagazine1_2005-12.epub"+ )+++testEclipseMag :: Test+testEclipseMag = TestCase $+ assertNewName "Eclipse Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut")+ (Just "Strahan, Jonathan")+ "Jonathan Strahan"]+ , metaTitles = [MetaTitle Nothing + "Eclipse One"]+ }+ expected =+ ( "magEclipse"+ , "Eclipse01.epub"+ )+++testBcs :: Test+testBcs = TestCase $+ assertNewName "Beneath Ceaseless Skies Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = + [ MetaCreator (Just "aut")+ (Just "Tidwell, Erin A.")+ "Hoover, Kenneth Mark"+ , MetaCreator (Just "aut")+ (Just "Tidwell, Erin A.")+ "Tidwell, Erin A."+ ]+ , metaTitles = [MetaTitle Nothing + "Beneath Ceaseless Skies #32"]+ }+ expected =+ ( "magBcs"+ , "BeneathCeaselessSkies_Issue032.epub"+ )+++testBkpFileAs :: Test+testBkpFileAs = TestCase $+ assertNewNameOpts opts + "book publisher suffix requested and present in file-as"+ meta expected+ where+ opts = defaultOptions { optPublisher = True }+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Herman Melville"]+ , metaContributors = [MetaCreator (Just "bkp") (Just "acme") + "Acme Publishing, Inc."]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick_acme.epub"+ )+++testBkpText :: Test+testBkpText = TestCase $+ assertNewNameOpts opts + "book publisher suffix requested and present in text"+ meta expected+ where+ opts = defaultOptions { optPublisher = True }+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Herman Melville"]+ , metaContributors = [MetaCreator (Just "bkp") Nothing+ "Acme Publishing, Inc."]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testBkpMissing :: Test+testBkpMissing = TestCase $+ assertNewNameOpts opts + "book publisher suffix requested and not present"+ meta expected+ where+ opts = defaultOptions { optPublisher = True }+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Herman Melville"]+ , metaTitles = [MetaTitle Nothing "Moby Dick"]+ }+ expected =+ ( "book"+ , "MelvilleHerman-MobyDick.epub"+ )+++testMagUniverse :: Test+testMagUniverse = TestCase $+ assertNewNameOpts opts + "Jim Baen's Universe Magazine"+ meta expected+ where+ opts = defaultOptions { optPublisher = True }+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Jim Baen's Universe"]+ , metaTitles = [MetaTitle Nothing "Jim Baen's Universe-Vol 4 Num 6"]+ }+ expected =+ ( "magUniverse"+ , "JimBaensUniverseVol04Num06.epub"+ )+++testMagClarkesworld :: Test+testMagClarkesworld = TestCase $+ assertNewName "Clarkesworld Magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut")+ (Just "Kowal, Mary Robinette")+ "Mary Robinette Kowal"]+ , metaTitles = [MetaTitle Nothing+ "Clarkesworld Magazine - Issue 21"]+ }+ expected =+ ( "magClarkesworld"+ , "Clarkesworld021.epub"+ )+++testLightspeedDate :: Test+testLightspeedDate = TestCase $+ assertNewName "Lightspeed Magazine, date in title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") Nothing+ "Edited by John Joseph Adams"]+ , metaTitles = [MetaTitle Nothing + "Lightspeed Magazine, June 2010"]+ }+ expected =+ ( "magLightspeedDate"+ , "Lightspeed2010-06.epub"+ )+++testLightspeedIssue :: Test+testLightspeedIssue = TestCase $+ assertNewName "Lightspeed Magazine, issue number in title" meta expected+ where+ meta = emptyMetadata+ { metaCreators = [MetaCreator (Just "aut") (Just "Magazine, Lightspeed & Clark, Maggie & Valentine, Genevieve & Baxter, Stephen & Okorafor, Nnedi & Wilison, Daniel H. & Reed, Robert & Sedia, Ekaterina") "Lightspeed Magazine"]+ , metaTitles = [MetaTitle Nothing + "Lightspeed Magazine Issue 10"]+ }+ expected =+ ( "magLightspeedIssue"+ , "Lightspeed010.epub"+ )+++testMagWeirdTales :: Test+testMagWeirdTales = TestCase $+ assertNewName "Weird Tales magazine" meta expected+ where+ meta = emptyMetadata+ { metaCreators =+ [ MetaCreator (Just "aut") Nothing "VanderMeer"+ , MetaCreator (Just "aut") Nothing "Ann"+ , MetaCreator (Just "aut") Nothing "Spinrad"+ , MetaCreator (Just "aut") Nothing "Norman"+ ]+ , metaTitles = [MetaTitle Nothing + "Weird Tales #350"]+ }+ expected =+ ( "magWeirdTales"+ , "WeirdTales350.epub"+ )
+ testsuite/EpubTools/Test/EpubName/PubYear.hs view
@@ -0,0 +1,29 @@+-- Copyright: 2011 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++module EpubTools.Test.EpubName.PubYear+ ( pubYearTests+ )+ where++import Test.HUnit ( Test (..), assertEqual )++import EpubTools.EpubName.PubYear+++pubYearTests :: Test+pubYearTests = TestLabel "PubYear" $ TestList+ [ testExtractYear "2001-03-25T00:00:00" "2001"+ , testExtractYear "2007" "2007"+ , testExtractYear "Sat Nov 03 18:49:50 +0100 2007" "2007"+ , testExtractYear "2001-03-25 05:00:00+00:00" "2001"+ , testExtractYear "2009-11-19T07:00:00+00:00" "2009"+ , testExtractYear "2010-09-21" "2010"+ , testExtractYear "2010-02-14T21:47:47.682882+00:00" "2010"+ ]+++testExtractYear :: String -> String -> Test+testExtractYear src expected = TestCase $+ assertEqual src (extractYear src) (Just expected)
+ testsuite/EpubTools/test-epubname.hs view
@@ -0,0 +1,34 @@+-- Copyright: 2008-2011 Dino Morelli+-- License: BSD3 (see LICENSE)+-- Author: Dino Morelli <dino@ui3.info>++module Main+ where++import System.Exit+import Test.HUnit ( Counts (..), Test (..), runTestTT )++import EpubTools.Test.EpubName.Format+import EpubTools.Test.EpubName.PubYear+++main :: IO ()+main = do+ counts <- runTestTT tests+ exit $ testsPassed counts+++exit :: Bool -> IO ()+exit True = exitWith ExitSuccess+exit False = exitWith $ ExitFailure 1+++testsPassed :: Counts -> Bool+testsPassed (Counts _ _ e f) = (e == 0) && (f == 0)+++tests :: Test+tests = TestList+ [ formatTests+ , pubYearTests+ ]
− testsuite/epubname.hs
@@ -1,995 +0,0 @@--- Copyright: 2008-2011 Dino Morelli--- License: BSD3 (see LICENSE)--- Author: Dino Morelli <dino@ui3.info>--module Main- where--import Codec.Epub.Opf.Package.Metadata-import System.Exit-import Test.HUnit ( Counts (..), Test (..), assertEqual, runTestTT )-import Test.HUnit.Base ( Assertion )--import EpubTools.EpubName.Format ( tryFormatting )-import EpubTools.EpubName.Opts-import EpubTools.EpubName.Util---main :: IO ()-main = do- counts <- runTestTT tests- exit $ testsPassed counts---exit :: Bool -> IO ()-exit True = exitWith ExitSuccess-exit False = exitWith $ ExitFailure 1---testsPassed :: Counts -> Bool-testsPassed (Counts _ _ e f) = (e == 0) && (f == 0)---tests :: Test-tests = TestList- [ testAuthorMinimal- , testAuthorOneName- , testAuthorRole- , testAuthorFileas- , testAuthorFull- , testAuthorSeveral- , testSeveralAuthors- , testNoAuthor- , testCreatorsNoAuthor- , testCreatorsNoAuthorPubDate- , testCapsTitle- , testColon- , testBracketTitle- , testNoTitle- , testAllPunctuation- , testPubYear- , testPubYearUnwanted- , testMagAeon- , testMagAEon- , testMagApexLong- , testMagApexShort- , testChallengingDestinyShort- , testChallengingDestinyLong- , testAnalog- , testAsimovs- , testFantasyMagazine- , testFsfShort- , testFsfLong- , testFsfAmpersand- , testMagFutureOrbits- , testGudShort- , testGudLong- , testGudVeryLong- , testInterzoneShort- , testInterzoneLong- , testNemesisShort- , testNemesisLong- , testMagSomethingWicked- , testMagSomethingWickedMonth- , testSFBestOf- , testBestSF- , testYearsBest- , testMagBlackStatic- , testRageMachineMag- , testEclipseMag- , testBcs- , testBkpFileAs- , testBkpText- , testBkpMissing- , testMagUniverse- , testMagClarkesworld- , testLightspeedDate- , testLightspeedIssue- , testMagWeirdTales- ]---assertNewNameOpts :: Options -> String -> Metadata - -> (String, String) -> Assertion-assertNewNameOpts opts desc meta expected = do- result <- runEN opts $ tryFormatting "" meta- let actual = either (\em -> ("NO FORMATTER", em)) id result- assertEqual desc expected actual---assertNewName :: String -> Metadata -> (String, String) -> Assertion-assertNewName = assertNewNameOpts defaultOptions---testAuthorMinimal :: Test-testAuthorMinimal = TestCase $- assertNewName "minimal author" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Herman Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testAuthorOneName :: Test-testAuthorOneName = TestCase $- assertNewName "author is a single word" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "Melville-MobyDick.epub"- )---testAuthorRole :: Test-testAuthorRole = TestCase $- assertNewName "author with role" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Herman Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testAuthorFileas :: Test-testAuthorFileas = TestCase $- assertNewName "author with file-as" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing- (Just "Melville, Herman")- "Herman Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testAuthorFull :: Test-testAuthorFull = TestCase $- assertNewName "author fully filled out" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut")- (Just "Melville, Herman")- "Herman Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testAuthorSeveral :: Test-testAuthorSeveral = TestCase $- assertNewName "several authors" meta expected- where- meta = emptyMetadata- { metaCreators =- [ MetaCreator (Just "aut") Nothing- "James Patrick Kelly"- , MetaCreator (Just "aut") (Just "Kessel, John")- "John Kessel"- , MetaCreator (Just "aut") Nothing- "Jonathan Lethem"- ]- , metaTitles = [MetaTitle Nothing- "Ninety Percent of Everything"]- }- expected =- ( "book"- , "Kelly_Kessel_Lethem-NinetyPercentOfEverything.epub"- )---testNoAuthor :: Test-testNoAuthor = TestCase $- assertNewName "no creator(s) at all" meta expected- where- meta = emptyMetadata- { metaCreators = []- , metaTitles = [MetaTitle Nothing- "Some Collection of Fine Stories, Volume 1"]- }- expected =- ( "book"- , "SomeCollectionOfFineStoriesVolume1.epub"- )---testCreatorsNoAuthor :: Test-testCreatorsNoAuthor = TestCase $- assertNewName "creators, but no author(s) at all" meta expected- where- meta = emptyMetadata- { metaCreators =- [ MetaCreator (Just "edt") Nothing- "Graham Spindlewest"- , MetaCreator (Just "ill") Nothing- "Eva Tunglewacker"- ]- , metaTitles = [MetaTitle Nothing- "Some Collection of Fine Stories, Volume 1"]- }- expected =- ( "book"- , "SomeCollectionOfFineStoriesVolume1.epub"- )---testCreatorsNoAuthorPubDate :: Test-testCreatorsNoAuthorPubDate = TestCase $- assertNewName "creators, but no author(s) at all, with pub date" - meta expected- where- meta = emptyMetadata- { metaCreators =- [ MetaCreator (Just "edt") Nothing- "Graham Spindlewest"- , MetaCreator (Just "ill") Nothing- "Eva Tunglewacker"- ]- , metaTitles = [MetaTitle Nothing- "Some Collection of Fine Stories, Volume 1"]- , metaDates = [MetaDate (Just "original-publication")- "2008"]- }- expected =- ( "book"- , "SomeCollectionOfFineStoriesVolume1_2008.epub"- )---testSeveralAuthors :: Test-testSeveralAuthors = TestCase $- assertNewName "more than one author separated by & and/or and" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Yvonne Q. Anderson & Eva Tunglewacker and Jefferson Milner"]- , metaTitles = [MetaTitle Nothing "Big Trouble"]- }- expected =- ( "book"- , "Anderson_Tunglewacker_Milner-BigTrouble.epub"- )---testCapsTitle :: Test-testCapsTitle = TestCase $- assertNewName "title all caps" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Greg Bear"]- , metaTitles = [MetaTitle Nothing "EON"]- }- expected =- ( "book"- , "BearGreg-Eon.epub"- )---testColon :: Test-testColon = TestCase $- assertNewName "colon becomes underscore" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Ed Howdershelt"]- , metaTitles = [MetaTitle Nothing - "Book 1: 3rd World Products, Inc."]- }- expected =- ( "book"- , "HowdersheltEd-Book1_3rdWorldProductsInc.epub"- )---testBracketTitle :: Test-testBracketTitle = TestCase $- assertNewName "title with brackets" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Mercedes Lackey"]- , metaTitles = [MetaTitle Nothing "SKitty [Shipscat series #1]"]- }- expected =- ( "book"- , "LackeyMercedes-Skitty_ShipscatSeries1.epub"- )---testNoTitle :: Test-testNoTitle = TestCase $- assertNewName "missing title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Nobody McCrankypants"]- }- expected =- ( "NO FORMATTER"- , " [ERROR No formatter found]"- )---testAllPunctuation :: Test-testAllPunctuation = TestCase $- assertNewName "big test of all punctuation" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Dino Morelli"]- , metaTitles = [MetaTitle Nothing- "The *crazy*: Sand-box. Of Smedley's discontent, fear & Malnourishment? (Maybe not!); [Part #2]"]- }- expected =- ( "book"- , "MorelliDino-TheCrazy_SandBoxOfSmedleysDiscontentFearAndMalnourishmentMaybeNot_Part2.epub"- )---testPubYear :: Test-testPubYear = TestCase $- assertNewName "book with a publication year" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Jim Jones"]- , metaTitles = [MetaTitle Nothing "A Timeless Story"]- , metaDates = [MetaDate (Just "original-publication") "2003"]- }- expected =- ( "book"- , "JonesJim-ATimelessStory_2003.epub"- )---testPubYearUnwanted :: Test-testPubYearUnwanted = TestCase $- assertNewNameOpts opts- "book with a publication year but we don't want"- meta expected- where- opts = defaultOptions { optYear = False }- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Jim Jones"]- , metaTitles = [MetaTitle Nothing "A Timeless Story"]- , metaDates = [MetaDate (Just "original-publication") "2003"]- }- expected =- ( "book"- , "JonesJim-ATimelessStory.epub"- )---testMagAeon :: Test-testMagAeon = TestCase $- assertNewName "Aeon magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "Aeon Authors"]- , metaTitles = [MetaTitle Nothing "Aeon Eight"]- }- expected =- ( "magAeon"- , "AeonMagazine08.epub"- )---testMagAEon :: Test-testMagAEon = TestCase $- assertNewName "AEon magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing "AEon Authors"]- , metaTitles = [MetaTitle Nothing "Aeon Thirteen"]- }- expected =- ( "magAeon"- , "AeonMagazine13.epub"- )---testMagApexLong :: Test-testMagApexLong = TestCase $- assertNewName "Apex Magazine, older, long title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Apex Authors"]- , metaTitles = [MetaTitle Nothing- "Apex Science Fiction and Horror Digest #9"]- }- expected =- ( "magApex"- , "ApexMagazine009.epub"- )---testMagApexShort :: Test-testMagApexShort = TestCase $- assertNewName "Apex Magazine, newer, short title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Apex Authors"]- , metaTitles = [MetaTitle Nothing- "Apex Magazine Issue 17"]- }- expected =- ( "magApex"- , "ApexMagazine017.epub"- )---testChallengingDestinyShort :: Test-testChallengingDestinyShort = TestCase $- assertNewName "Challenging Destiny Magazine, short title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Crystalline Sphere Authors"]- , metaTitles = [MetaTitle Nothing- "Challenging Destiny #23"]- }- expected =- ( "magChallengingDestiny"- , "ChallengingDestinyMagazine023.epub"- )---testChallengingDestinyLong :: Test-testChallengingDestinyLong = TestCase $- assertNewName "Challenging Destiny Magazine, long title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Crystalline Sphere Authors"]- , metaTitles = [MetaTitle Nothing - "Challenging Destiny #24: August 2007"]- }- expected =- ( "magChallengingDestiny"- , "ChallengingDestinyMagazine024.epub"- )---testAnalog :: Test-testAnalog = TestCase $- assertNewName "Analog" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Dell Magazine Authors"]- , metaTitles = [MetaTitle Nothing- "Analog SFF, July-August 2003"]- }- expected =- ( "magAnalog"- , "AnalogSF2003-07_08.epub"- )---testAsimovs :: Test-testAsimovs = TestCase $- assertNewName "Asimovs" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Dell Magazine Authors"]- , metaTitles = [MetaTitle Nothing- "Asimov's SF, August 2003"]- }- expected =- ( "magAnalog"- , "AsimovsSF2003-08.epub"- )--testFantasyMagazine :: Test-testFantasyMagazine = TestCase $- assertNewName "Fantasy Magazine" meta expected- where- meta = emptyMetadata- { metaCreators =- [ MetaCreator (Just "aut") (Just "Howard, Kat & Tanzer, Molly & Beagle, Peter S. & Howard, Jonathan L. & Valentine, Genevieve & Vaughn, Carrie & Pilinovsky, Helen") "Kat Howard"- , MetaCreator (Just "aut") Nothing "Molly Tanzer"- , MetaCreator (Just "aut") Nothing "Peter S. Beagle"- , MetaCreator (Just "aut") Nothing "Jonathan L. Howard"- , MetaCreator (Just "aut") Nothing "Genevieve Valentine"- , MetaCreator (Just "aut") Nothing "Carrie Vaughn"- , MetaCreator (Just "aut") Nothing "Helen Pilinovsky"- ]- , metaTitles = [MetaTitle Nothing- "Fantasy Magazine Issue 49"]- }- expected =- ( "magFantasyMag"- , "FantasyMagazine049.epub"- )---testFsfShort :: Test-testFsfShort = TestCase $- assertNewName "FSF Magazine, short" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Spilogale Authors"]- , metaTitles = [MetaTitle Nothing "FSF, April 2008"]- }- expected =- ( "magFsf"- , "FantasyScienceFiction2008-04.epub"- )---testFsfLong :: Test-testFsfLong = TestCase $- assertNewName "FSF Magazine, long" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Spilogale Authors"]- , metaTitles = [MetaTitle Nothing - "FSF Magazine, April 2006"]- }- expected =- ( "magFsf"- , "FantasyScienceFiction2006-04.epub"- )---testFsfAmpersand :: Test-testFsfAmpersand = TestCase $- assertNewName "FSF Magazine, ampersand" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing- "Spilogale"]- , metaTitles = [MetaTitle Nothing "F & SF Dec 2003"]- }- expected =- ( "magFsf"- , "FantasyScienceFiction2003-12.epub"- )---testMagFutureOrbits :: Test-testMagFutureOrbits = TestCase $- assertNewName "testMagFutureOrbits" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Vander Neut Publications, L.L.C."]- , metaTitles = [MetaTitle Nothing - "Future Orbits Issue 5, June/July 2002"]- }- expected =- ( "magFutureOrbits"- , "FutureOrbitsMagazine05_2002-06_07.epub"- )---testGudShort :: Test-testGudShort = TestCase $- assertNewName "Gud Magazine, short" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "GUD Magazine Authors"]- , metaTitles = [MetaTitle Nothing - "GUD Magazine Issue 0 :: Spring 2007"]- }- expected =- ( "magGud"- , "GUDMagazine00.epub"- )---testGudLong :: Test-testGudLong = TestCase $- assertNewName "Gud Magazine, long" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "GUD Magazine Authors, Jeff Somers, Jeremy Shipp"]- , metaTitles = [MetaTitle Nothing - "GUD Magazine Issue 2 :: Spring 2008"]- }- expected =- ( "magGud"- , "GUDMagazine02.epub"- )---testGudVeryLong :: Test-testGudVeryLong = TestCase $- assertNewName "Gud Magazine, very long" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "GUD Magazine Authors"]- , metaTitles = [MetaTitle Nothing - "Greatest Uncommon Denominator Magazine Issue 4 :: Spring 2009"]- }- expected =- ( "magGud"- , "GUDMagazine04.epub"- )---testInterzoneShort :: Test-testInterzoneShort = TestCase $- assertNewName "Interzone Magazine, short" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "TTA Press Authors"]- , metaTitles = [MetaTitle Nothing - "Interzone SFF #212"]- }- expected =- ( "magInterzone"- , "InterzoneSFF212.epub"- )---testInterzoneLong :: Test-testInterzoneLong = TestCase $- assertNewName "Interzone Magazine, long" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "TTA Press Authors"]- , metaTitles = [MetaTitle Nothing - "Interzone Science Fiction and Fantasy Magazine #216"]- }- expected =- ( "magInterzone"- , "InterzoneSFF216.epub"- )---testNemesisShort :: Test-testNemesisShort = TestCase $- assertNewName "Nemesis Magazine, short" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Stephen Adams"]- , metaTitles = [MetaTitle Nothing - "Nemesis Magazine #2"]- }- expected =- ( "magNemesis"- , "NemesisMag002.epub"- )---testNemesisLong :: Test-testNemesisLong = TestCase $- assertNewName "Nemesis Magazine, long" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Stephen Adams"]- , metaTitles = [MetaTitle Nothing - "Nemesis Magazine #7: Featuring Victory Rose in Death Stalks the Ruins"]- }- expected =- ( "magNemesis"- , "NemesisMag007.epub"- )---testMagSomethingWicked :: Test-testMagSomethingWicked = TestCase $- assertNewName "Something Wicked Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Something Wicked Authors"]- , metaTitles = [MetaTitle Nothing - "Something Wicked SF and Horror Magazine #5"]- }- expected =- ( "magSomethingWicked"- , "SomethingWicked005.epub"- )---testMagSomethingWickedMonth :: Test-testMagSomethingWickedMonth = TestCase $- assertNewName "Something Wicked Magazine, month in title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut")- (Just "Authors, Something Wicked")- "Something Wicked Authors"]- , metaTitles = [MetaTitle Nothing - "Something Wicked #14 (October 2011)"]- }- expected =- ( "magSomethingWicked"- , "SomethingWicked014.epub"- )---testSFBestOf :: Test-testSFBestOf = TestCase $- assertNewName "Science Fiction: The Best of the Year" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "Rich Horton"]- , metaTitles = [MetaTitle Nothing - "Science Fiction: The Best of the Year, 2007 Edition"]- }- expected =- ( "compOfTheYear"- , "ScienceFiction_TheBestOfTheYear2007Edition.epub"- )---testBestSF :: Test-testBestSF = TestCase $- assertNewName "The Best Science Fiction and Fantasy of the Year"- meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut")- (Just "Strahan, Jonathan")- "Jonathan Strahan"]- , metaTitles = [MetaTitle Nothing - "The Best Science Fiction and Fantasy of the Year: Volume 2"]- }- expected =- ( "compOfTheYear"- , "TheBestScienceFictionAndFantasyOfTheYear_Volume2.epub"- )---testYearsBest :: Test-testYearsBest = TestCase $- assertNewName "The Year's Best SF" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing - "Rich Horton, Michael Swanwick, Karen Joy Fowler"]- , metaTitles = [MetaTitle Nothing - "The Year's Best Science Fiction: 2008 Edition"]- }- expected =- ( "compYearsBest"- , "TheYearsBestScienceFiction_2008Edition.epub"- )---testMagBlackStatic :: Test-testMagBlackStatic = TestCase $- assertNewName "Black Static Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator Nothing Nothing - "TTA Press Authors"]- , metaTitles = [MetaTitle Nothing - "Black Static Horror Magazine #5"]- }- expected =- ( "magBlackStatic"- , "BlackStaticHorrorMagazine05.epub"- )---testRageMachineMag :: Test-testRageMachineMag = TestCase $- assertNewName "Rage Machine Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "edt") Nothing - "G. W. Thomas"]- , metaTitles = [MetaTitle Nothing - "Rage Machine Magazine #1--December 2005"]- }- expected =- ( "magRageMachine"- , "RageMachineMagazine1_2005-12.epub"- )---testEclipseMag :: Test-testEclipseMag = TestCase $- assertNewName "Eclipse Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut")- (Just "Strahan, Jonathan")- "Jonathan Strahan"]- , metaTitles = [MetaTitle Nothing - "Eclipse One"]- }- expected =- ( "magEclipse"- , "Eclipse01.epub"- )---testBcs :: Test-testBcs = TestCase $- assertNewName "Beneath Ceaseless Skies Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = - [ MetaCreator (Just "aut")- (Just "Tidwell, Erin A.")- "Hoover, Kenneth Mark"- , MetaCreator (Just "aut")- (Just "Tidwell, Erin A.")- "Tidwell, Erin A."- ]- , metaTitles = [MetaTitle Nothing - "Beneath Ceaseless Skies #32"]- }- expected =- ( "magBcs"- , "BeneathCeaselessSkies_Issue032.epub"- )---testBkpFileAs :: Test-testBkpFileAs = TestCase $- assertNewNameOpts opts - "book publisher suffix requested and present in file-as"- meta expected- where- opts = defaultOptions { optPublisher = True }- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Herman Melville"]- , metaContributors = [MetaCreator (Just "bkp") (Just "acme") - "Acme Publishing, Inc."]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick_acme.epub"- )---testBkpText :: Test-testBkpText = TestCase $- assertNewNameOpts opts - "book publisher suffix requested and present in text"- meta expected- where- opts = defaultOptions { optPublisher = True }- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Herman Melville"]- , metaContributors = [MetaCreator (Just "bkp") Nothing- "Acme Publishing, Inc."]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testBkpMissing :: Test-testBkpMissing = TestCase $- assertNewNameOpts opts - "book publisher suffix requested and not present"- meta expected- where- opts = defaultOptions { optPublisher = True }- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Herman Melville"]- , metaTitles = [MetaTitle Nothing "Moby Dick"]- }- expected =- ( "book"- , "MelvilleHerman-MobyDick.epub"- )---testMagUniverse :: Test-testMagUniverse = TestCase $- assertNewNameOpts opts - "Jim Baen's Universe Magazine"- meta expected- where- opts = defaultOptions { optPublisher = True }- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Jim Baen's Universe"]- , metaTitles = [MetaTitle Nothing "Jim Baen's Universe-Vol 4 Num 6"]- }- expected =- ( "magUniverse"- , "JimBaensUniverseVol04Num06.epub"- )---testMagClarkesworld :: Test-testMagClarkesworld = TestCase $- assertNewName "Clarkesworld Magazine" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut")- (Just "Kowal, Mary Robinette")- "Mary Robinette Kowal"]- , metaTitles = [MetaTitle Nothing- "Clarkesworld Magazine - Issue 21"]- }- expected =- ( "magClarkesworld"- , "Clarkesworld021.epub"- )---testLightspeedDate :: Test-testLightspeedDate = TestCase $- assertNewName "Lightspeed Magazine, date in title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") Nothing- "Edited by John Joseph Adams"]- , metaTitles = [MetaTitle Nothing - "Lightspeed Magazine, June 2010"]- }- expected =- ( "magLightspeedDate"- , "Lightspeed2010-06.epub"- )---testLightspeedIssue :: Test-testLightspeedIssue = TestCase $- assertNewName "Lightspeed Magazine, issue number in title" meta expected- where- meta = emptyMetadata- { metaCreators = [MetaCreator (Just "aut") (Just "Magazine, Lightspeed & Clark, Maggie & Valentine, Genevieve & Baxter, Stephen & Okorafor, Nnedi & Wilison, Daniel H. & Reed, Robert & Sedia, Ekaterina") "Lightspeed Magazine"]- , metaTitles = [MetaTitle Nothing - "Lightspeed Magazine Issue 10"]- }- expected =- ( "magLightspeedIssue"- , "Lightspeed010.epub"- )---testMagWeirdTales :: Test-testMagWeirdTales = TestCase $- assertNewName "Weird Tales magazine" meta expected- where- meta = emptyMetadata- { metaCreators =- [ MetaCreator (Just "aut") Nothing "VanderMeer"- , MetaCreator (Just "aut") Nothing "Ann"- , MetaCreator (Just "aut") Nothing "Spinrad"- , MetaCreator (Just "aut") Nothing "Norman"- ]- , metaTitles = [MetaTitle Nothing - "Weird Tales #350"]- }- expected =- ( "magWeirdTales"- , "WeirdTales350.epub"- )