diff options
Diffstat (limited to 'tests/Data/Torrent/MetainfoSpec.hs')
-rw-r--r-- | tests/Data/Torrent/MetainfoSpec.hs | 78 |
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 #-} | ||
3 | module Data.Torrent.MetainfoSpec (spec) where | ||
4 | |||
5 | import Control.Applicative | ||
6 | import Data.ByteString as BS | ||
7 | import Data.ByteString.Lazy as BL | ||
8 | import Data.BEncode | ||
9 | import Data.Maybe | ||
10 | import Data.Time | ||
11 | import Network.URI | ||
12 | import Test.Hspec | ||
13 | import Test.QuickCheck | ||
14 | import Test.QuickCheck.Instances () | ||
15 | |||
16 | import Data.Torrent | ||
17 | import Data.Torrent.LayoutSpec () | ||
18 | import Network.BitTorrent.Core.NodeInfoSpec () | ||
19 | |||
20 | {----------------------------------------------------------------------- | ||
21 | -- Common | ||
22 | -----------------------------------------------------------------------} | ||
23 | |||
24 | data T a = T | ||
25 | |||
26 | prop_properBEncode :: Show a => BEncode a => Eq a | ||
27 | => T a -> a -> IO () | ||
28 | prop_properBEncode _ expected = actual `shouldBe` Right expected | ||
29 | where | ||
30 | actual = decode $ BL.toStrict $ encode expected | ||
31 | |||
32 | instance Arbitrary URI where | ||
33 | arbitrary = pure $ fromJust | ||
34 | $ parseURI "http://exsample.com:80/123365_asd" | ||
35 | |||
36 | {----------------------------------------------------------------------- | ||
37 | -- Instances | ||
38 | -----------------------------------------------------------------------} | ||
39 | |||
40 | instance Arbitrary HashList where | ||
41 | arbitrary = HashList <$> arbitrary | ||
42 | |||
43 | instance Arbitrary PieceInfo where | ||
44 | arbitrary = PieceInfo <$> arbitrary <*> arbitrary | ||
45 | |||
46 | instance Arbitrary InfoDict where | ||
47 | arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary | ||
48 | |||
49 | pico :: Gen (Maybe NominalDiffTime) | ||
50 | pico = oneof | ||
51 | [ pure Nothing | ||
52 | , (Just . fromIntegral) <$> (arbitrary :: Gen Int) | ||
53 | ] | ||
54 | |||
55 | instance 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 | |||
66 | spec :: Spec | ||
67 | spec = 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) | ||