summaryrefslogtreecommitdiff
path: root/tests/Data/Torrent/MetainfoSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Data/Torrent/MetainfoSpec.hs')
-rw-r--r--tests/Data/Torrent/MetainfoSpec.hs80
1 files changed, 0 insertions, 80 deletions
diff --git a/tests/Data/Torrent/MetainfoSpec.hs b/tests/Data/Torrent/MetainfoSpec.hs
deleted file mode 100644
index 369c5e0f..00000000
--- a/tests/Data/Torrent/MetainfoSpec.hs
+++ /dev/null
@@ -1,80 +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.Piece
17import Data.Torrent.Layout
18import Data.Torrent
19import Data.Torrent.LayoutSpec ()
20import Network.BitTorrent.Core.NodeInfoSpec ()
21
22{-----------------------------------------------------------------------
23-- Common
24-----------------------------------------------------------------------}
25
26data T a = T
27
28prop_properBEncode :: Show a => BEncode a => Eq a
29 => T a -> a -> IO ()
30prop_properBEncode _ expected = actual `shouldBe` Right expected
31 where
32 actual = decode $ BL.toStrict $ encode expected
33
34instance Arbitrary URI where
35 arbitrary = pure $ fromJust
36 $ parseURI "http://exsample.com:80/123365_asd"
37
38{-----------------------------------------------------------------------
39-- Instances
40-----------------------------------------------------------------------}
41
42instance Arbitrary HashList where
43 arbitrary = HashList <$> arbitrary
44
45instance Arbitrary PieceInfo where
46 arbitrary = PieceInfo <$> arbitrary <*> arbitrary
47
48instance Arbitrary InfoDict where
49 arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary
50
51pico :: Gen (Maybe NominalDiffTime)
52pico = oneof
53 [ pure Nothing
54 , (Just . fromIntegral) <$> (arbitrary :: Gen Int)
55 ]
56
57instance Arbitrary Torrent where
58 arbitrary = Torrent <$> arbitrary
59 <*> arbitrary <*> arbitrary <*> arbitrary
60 <*> pico <*> arbitrary <*> arbitrary
61 <*> arbitrary
62 <*> arbitrary <*> pure Nothing <*> arbitrary
63
64{-----------------------------------------------------------------------
65-- Spec
66-----------------------------------------------------------------------}
67
68spec :: Spec
69spec = do
70 describe "FileInfo" $ do
71 it "properly bencoded" $ property $
72 prop_properBEncode (T :: T (FileInfo BS.ByteString))
73
74 describe "LayoutInfo" $ do
75 it "properly bencoded" $ property $
76 prop_properBEncode (T :: T LayoutInfo)
77
78 describe "Torrent" $ do
79 it "property bencoded" $ property $
80 prop_properBEncode (T :: T Torrent)