X-Git-Url: https://git.rkrishnan.org/?p=functorrent.git;a=blobdiff_plain;f=test%2FMetainfoTests.hs;fp=test%2FMetainfoTests.hs;h=9f1a2e23b19d7dec2f58765030221df6e73dff44;hp=86aa0ff14b5632dece355c52a2f72be23c666a2d;hb=e25e6620e9b648284b07c065199d3732e3360472;hpb=4861358f5573fb9ed27eda0dda72dd2ba1022e84 diff --git a/test/MetainfoTests.hs b/test/MetainfoTests.hs index 86aa0ff..9f1a2e2 100644 --- a/test/MetainfoTests.hs +++ b/test/MetainfoTests.hs @@ -24,26 +24,46 @@ module MetainfoTests where import Prelude hiding (readFile) import FuncTorrent.Metainfo + +import Control.Monad (liftM) import Test.Hspec import Data.ByteString (readFile) tests :: IO () -tests = hspec $ do - describe "read and interpret a torrent file 1" $ do - it "valid torrent file" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") - it "valid announce list" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - case torrentToMetainfo fc of - Left _ -> pending - Right metainfo -> do - announceList metainfo `shouldSatisfy` (not . null) - it "valid piece length" $ do - fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" - case torrentToMetainfo fc of - Left _ -> pending - Right metainfo -> do - let (Just info') = info metainfo - pieceLength info' `shouldBe` (524288 :: Integer) +tests = do + fc <- readFile "data/debian-7.8.0-amd64-CD-1.iso.torrent" + let minfo = torrentToMetainfo fc + putStrLn $ show minfo + hspec $ do + describe "read and interpret a torrent file 1" $ do + it "valid torrent file" $ do + (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") + it "valid announce list" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + announceList metainfo `shouldSatisfy` (not . null) + it "valid piece length" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just info') = info metainfo + pieceLength info' `shouldBe` (524288 :: Integer) + it "Not a multifile torrent" $ do + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just i) = info metainfo + (length (filemeta i)) `shouldSatisfy` (== 0) + describe "read and interpret a multifile torrent file" $ do + it "valid multifile torrent file" $ do + fc <- readFile "data/multifile.torrent" + (torrentToMetainfo fc) `shouldNotBe` (Left "parse error") + it "valid multifile torrent with multiple files" $ do + fc <- readFile "data/multifile.torrent" + case torrentToMetainfo fc of + Left _ -> pending + Right metainfo -> do + let (Just i) = info metainfo + (length (filemeta i)) `shouldSatisfy` (> 1)