diff options
author | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-31 11:25:59 +0400 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2013-10-31 11:25:59 +0400 |
commit | 01cef3fafc27d39d88c94cacdcd8e204c5f66b86 (patch) | |
tree | 01040aca19e49f4e7937383fef53b8c82bcec12b /tests/Data/Torrent/InfoHashSpec.hs | |
parent | c1fec260f47084300ac30de2e43d52966316a2c7 (diff) |
Merge bittorrent package with torrent-content
Diffstat (limited to 'tests/Data/Torrent/InfoHashSpec.hs')
-rw-r--r-- | tests/Data/Torrent/InfoHashSpec.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/Data/Torrent/InfoHashSpec.hs b/tests/Data/Torrent/InfoHashSpec.hs new file mode 100644 index 00000000..ba9ce9a4 --- /dev/null +++ b/tests/Data/Torrent/InfoHashSpec.hs | |||
@@ -0,0 +1,36 @@ | |||
1 | {-# OPTIONS -fno-warn-orphans #-} | ||
2 | module Data.Torrent.InfoHashSpec (spec) where | ||
3 | |||
4 | import Control.Applicative | ||
5 | import System.FilePath | ||
6 | import Test.Hspec | ||
7 | import Test.QuickCheck | ||
8 | import Test.QuickCheck.Instances () | ||
9 | |||
10 | import Data.Torrent | ||
11 | import Data.Torrent.InfoHash as IH | ||
12 | |||
13 | |||
14 | instance Arbitrary InfoHash where | ||
15 | arbitrary = IH.hash <$> arbitrary | ||
16 | |||
17 | type TestPair = (FilePath, String) | ||
18 | |||
19 | -- TODO add a few more torrents here | ||
20 | torrentList :: [TestPair] | ||
21 | torrentList = | ||
22 | [ ( "res" </> "dapper-dvd-amd64.iso.torrent" | ||
23 | , "0221caf96aa3cb94f0f58d458e78b0fc344ad8bf") | ||
24 | ] | ||
25 | |||
26 | infohashSpec :: (FilePath, String) -> Spec | ||
27 | infohashSpec (filepath, expectedHash) = do | ||
28 | it ("should match " ++ filepath) $ do | ||
29 | torrent <- fromFile filepath | ||
30 | let actualHash = show $ idInfoHash $ tInfoDict torrent | ||
31 | actualHash `shouldBe` expectedHash | ||
32 | |||
33 | spec :: Spec | ||
34 | spec = do | ||
35 | describe "info hash" $ do | ||
36 | mapM_ infohashSpec torrentList | ||