diff options
Diffstat (limited to 'tests/Data/Torrent/MetainfoSpec.hs')
-rw-r--r-- | tests/Data/Torrent/MetainfoSpec.hs | 80 |
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 #-} | ||
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.Piece | ||
17 | import Data.Torrent.Layout | ||
18 | import Data.Torrent | ||
19 | import Data.Torrent.LayoutSpec () | ||
20 | import Network.BitTorrent.Core.NodeInfoSpec () | ||
21 | |||
22 | {----------------------------------------------------------------------- | ||
23 | -- Common | ||
24 | -----------------------------------------------------------------------} | ||
25 | |||
26 | data T a = T | ||
27 | |||
28 | prop_properBEncode :: Show a => BEncode a => Eq a | ||
29 | => T a -> a -> IO () | ||
30 | prop_properBEncode _ expected = actual `shouldBe` Right expected | ||
31 | where | ||
32 | actual = decode $ BL.toStrict $ encode expected | ||
33 | |||
34 | instance Arbitrary URI where | ||
35 | arbitrary = pure $ fromJust | ||
36 | $ parseURI "http://exsample.com:80/123365_asd" | ||
37 | |||
38 | {----------------------------------------------------------------------- | ||
39 | -- Instances | ||
40 | -----------------------------------------------------------------------} | ||
41 | |||
42 | instance Arbitrary HashList where | ||
43 | arbitrary = HashList <$> arbitrary | ||
44 | |||
45 | instance Arbitrary PieceInfo where | ||
46 | arbitrary = PieceInfo <$> arbitrary <*> arbitrary | ||
47 | |||
48 | instance Arbitrary InfoDict where | ||
49 | arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary | ||
50 | |||
51 | pico :: Gen (Maybe NominalDiffTime) | ||
52 | pico = oneof | ||
53 | [ pure Nothing | ||
54 | , (Just . fromIntegral) <$> (arbitrary :: Gen Int) | ||
55 | ] | ||
56 | |||
57 | instance 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 | |||
68 | spec :: Spec | ||
69 | spec = 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) | ||