From 2a4d3e941320c489d7359cde725031432ea96765 Mon Sep 17 00:00:00 2001 From: Sam Truzjan Date: Mon, 25 Nov 2013 07:56:51 +0400 Subject: Fix test --- tests/Data/Torrent/ClientSpec.hs | 5 ++++- tests/Data/Torrent/MagnetSpec.hs | 3 ++- tests/Data/Torrent/MetainfoSpec.hs | 24 +++++++++++++++++++----- 3 files changed, 25 insertions(+), 7 deletions(-) (limited to 'tests/Data/Torrent') diff --git a/tests/Data/Torrent/ClientSpec.hs b/tests/Data/Torrent/ClientSpec.hs index 0ff74f6f..4bc881c3 100644 --- a/tests/Data/Torrent/ClientSpec.hs +++ b/tests/Data/Torrent/ClientSpec.hs @@ -27,4 +27,7 @@ spec = do clientInfo "OP0123xxxxxxxxxxxxxx" `shouldBe` "Opera-123" it "decode ML donkey style peer id" $ do - clientInfo "-ML2.7.2-xxxxxxxxxxx" `shouldBe` "MLdonkey-0" \ No newline at end of file + clientInfo "-ML2.7.2-xxxxxxxxxxx" `shouldBe` "MLdonkey-0" + +-- TODO XBT, Bits on Wheels, Queen Bee, BitTyrant, TorrenTopia, +-- BitSpirit, Rufus, G3 Torrent, FlashGet \ No newline at end of file diff --git a/tests/Data/Torrent/MagnetSpec.hs b/tests/Data/Torrent/MagnetSpec.hs index 5adc6df7..3ecf8705 100644 --- a/tests/Data/Torrent/MagnetSpec.hs +++ b/tests/Data/Torrent/MagnetSpec.hs @@ -3,6 +3,7 @@ module Data.Torrent.MagnetSpec (spec) where import Control.Applicative import Data.Maybe +import Data.Monoid import Test.Hspec import Test.QuickCheck import Test.QuickCheck.Instances () @@ -23,7 +24,7 @@ instance Arbitrary URI where instance Arbitrary Magnet where arbitrary = Magnet <$> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary <*> arbitrary - <*> arbitrary <*> arbitrary <*> pure (error "arbitrary magnet") + <*> arbitrary <*> arbitrary <*> pure mempty magnetEncoding :: Magnet -> Bool magnetEncoding m = parseMagnet (renderMagnet m) == Just m diff --git a/tests/Data/Torrent/MetainfoSpec.hs b/tests/Data/Torrent/MetainfoSpec.hs index 297b28f1..636bb6b1 100644 --- a/tests/Data/Torrent/MetainfoSpec.hs +++ b/tests/Data/Torrent/MetainfoSpec.hs @@ -7,11 +7,13 @@ import Data.ByteString as BS import Data.ByteString.Lazy as BL import Data.BEncode import Data.Maybe +import Data.Time import Network.URI import Test.Hspec import Test.QuickCheck import Test.QuickCheck.Instances () +import Data.Torrent.Piece import Data.Torrent.Layout import Data.Torrent @@ -23,8 +25,8 @@ import Data.Torrent data T a = T prop_properBEncode :: Show a => BEncode a => Eq a - => T a -> a -> Bool -prop_properBEncode _ expected = actual == Right expected + => T a -> a -> IO () +prop_properBEncode _ expected = actual `shouldBe` Right expected where actual = decode $ BL.toStrict $ encode expected @@ -48,13 +50,25 @@ instance Arbitrary LayoutInfo where , MultiFile <$> arbitrary <*> arbitrary ] +instance Arbitrary HashArray where + arbitrary = HashArray <$> arbitrary + +instance Arbitrary PieceInfo where + arbitrary = PieceInfo <$> arbitrary <*> arbitrary + instance Arbitrary InfoDict where - arbitrary = undefined + arbitrary = infoDictionary <$> arbitrary <*> arbitrary <*> arbitrary + +pico :: Gen (Maybe NominalDiffTime) +pico = oneof + [ pure Nothing + , (Just . fromIntegral) <$> (arbitrary :: Gen Int) + ] instance Arbitrary Torrent where arbitrary = Torrent <$> arbitrary - <*> arbitrary <*> arbitrary <*> arbitrary - <*> arbitrary <*> arbitrary <*> arbitrary + <*> arbitrary <*> arbitrary <*> arbitrary + <*> pico <*> arbitrary <*> arbitrary <*> arbitrary <*> pure Nothing <*> arbitrary {----------------------------------------------------------------------- -- cgit v1.2.3