summaryrefslogtreecommitdiff
path: root/tests/Data/Torrent/MetainfoSpec.hs
diff options
context:
space:
mode:
authorSam Truzjan <pxqr.sta@gmail.com>2014-04-04 23:06:41 +0400
committerSam Truzjan <pxqr.sta@gmail.com>2014-04-04 23:06:41 +0400
commit7e597cd924d2149b10f900c7dc14ce6e1e321cb5 (patch)
tree195e86be7089a7f520b8356a5703274a14e3bd83 /tests/Data/Torrent/MetainfoSpec.hs
parent264a23390751a8c31e3f20f24c9019a19ef4adf0 (diff)
[Spec] Follow module layout changes in Torrent
Diffstat (limited to 'tests/Data/Torrent/MetainfoSpec.hs')
-rw-r--r--tests/Data/Torrent/MetainfoSpec.hs78
1 files changed, 0 insertions, 78 deletions
diff --git a/tests/Data/Torrent/MetainfoSpec.hs b/tests/Data/Torrent/MetainfoSpec.hs
deleted file mode 100644
index 1a8f97c7..00000000
--- a/tests/Data/Torrent/MetainfoSpec.hs
+++ /dev/null
@@ -1,78 +0,0 @@
1{-# LANGUAGE TypeSynonymInstances #-}
2{-# OPTIONS -fno-warn-orphans #-}
3module Data.Torrent.MetainfoSpec (spec) where
4
5import Control.Applicative
6import Data.ByteString as BS
7import Data.ByteString.Lazy as BL
8import Data.BEncode
9import Data.Maybe
10import Data.Time
11import Network.URI
12import Test.Hspec
13import Test.QuickCheck
14import Test.QuickCheck.Instances ()
15
16import Data.Torrent
17import Data.Torrent.LayoutSpec ()
18import Network.BitTorrent.Core.NodeInfoSpec ()
19
20{-----------------------------------------------------------------------
21-- Common
22-----------------------------------------------------------------------}
23
24data T a = T
25
26prop_properBEncode :: Show a => BEncode a => Eq a
27 => T a -> a -> IO ()
28prop_properBEncode _ expected = actual `shouldBe` Right expected
29 where
30 actual = decode $ BL.toStrict $ encode expected
31
32instance Arbitrary URI where
33 arbitrary = pure $ fromJust
34 $ parseURI "http://exsample.com:80/123365_asd"
35
36{-----------------------------------------------------------------------
37-- Instances
38-----------------------------------------------------------------------}
39
40instance Arbitrary HashList where
41 arbitrary = HashList <$> arbitrary
42
43instance Arbitrary PieceInfo where
44 arbitrary = PieceInfo <$> arbitrary <*> arbitrary
45
46instance Arbitrary InfoDict where
47 arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary
48
49pico :: Gen (Maybe NominalDiffTime)
50pico = oneof
51 [ pure Nothing
52 , (Just . fromIntegral) <$> (arbitrary :: Gen Int)
53 ]
54
55instance Arbitrary Torrent where
56 arbitrary = Torrent <$> arbitrary
57 <*> arbitrary <*> arbitrary <*> arbitrary
58 <*> pico <*> arbitrary <*> arbitrary
59 <*> arbitrary
60 <*> arbitrary <*> pure Nothing <*> arbitrary
61
62{-----------------------------------------------------------------------
63-- Spec
64-----------------------------------------------------------------------}
65
66spec :: Spec
67spec = do
68 describe "FileInfo" $ do
69 it "properly bencoded" $ property $
70 prop_properBEncode (T :: T (FileInfo BS.ByteString))
71
72 describe "LayoutInfo" $ do
73 it "properly bencoded" $ property $
74 prop_properBEncode (T :: T LayoutInfo)
75
76 describe "Torrent" $ do
77 it "property bencoded" $ property $
78 prop_properBEncode (T :: T Torrent)