summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Network/BitTorrent/Core/PeerIdSpec.hs9
-rw-r--r--tests/Network/BitTorrent/Tracker/MessageSpec.hs12
2 files changed, 9 insertions, 12 deletions
diff --git a/tests/Network/BitTorrent/Core/PeerIdSpec.hs b/tests/Network/BitTorrent/Core/PeerIdSpec.hs
index 7153ef68..4e9f1655 100644
--- a/tests/Network/BitTorrent/Core/PeerIdSpec.hs
+++ b/tests/Network/BitTorrent/Core/PeerIdSpec.hs
@@ -1,15 +1,18 @@
1module Network.BitTorrent.Core.PeerIdSpec (spec) where 1module Network.BitTorrent.Core.PeerIdSpec (spec) where
2import Control.Applicative 2import Control.Applicative
3import Data.Text.Encoding as T
3import Test.Hspec 4import Test.Hspec
4import Test.QuickCheck 5import Test.QuickCheck
5import Test.QuickCheck.Instances 6import Test.QuickCheck.Instances ()
6import Network.BitTorrent.Core.PeerId 7import Network.BitTorrent.Core.PeerId
7 8
8 9
9instance Arbitrary PeerId where 10instance Arbitrary PeerId where
10 arbitrary = oneof 11 arbitrary = oneof
11 [ azureusStyle defaultClientId defaultVersionNumber <$> arbitrary 12 [ azureusStyle defaultClientId defaultVersionNumber
12 , shadowStyle 'X' defaultVersionNumber <$> arbitrary 13 <$> pure ""
14-- , shadowStyle 'X' defaultVersionNumber
15-- <$> (T.encodeUtf8 <$> arbitrary)
13 ] 16 ]
14 17
15spec :: Spec 18spec :: Spec
diff --git a/tests/Network/BitTorrent/Tracker/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/MessageSpec.hs
index 8a06aaba..2a882c5d 100644
--- a/tests/Network/BitTorrent/Tracker/MessageSpec.hs
+++ b/tests/Network/BitTorrent/Tracker/MessageSpec.hs
@@ -44,8 +44,8 @@ instance Arbitrary AnnounceQuery where
44baseURI :: URI 44baseURI :: URI
45baseURI = fromJust $ parseURI "http://a" 45baseURI = fromJust $ parseURI "http://a"
46 46
47parseUriQuery :: URI -> [(Text, Text)] 47parseUriQuery :: URI -> SimpleQuery
48parseUriQuery = filterMaybes . parseQueryText . BC.pack . uriQuery 48parseUriQuery = filterMaybes . parseQuery . BC.pack . uriQuery
49 where 49 where
50 filterMaybes :: [(a, Maybe b)] -> [(a, b)] 50 filterMaybes :: [(a, Maybe b)] -> [(a, b)]
51 filterMaybes = catMaybes . L.map f 51 filterMaybes = catMaybes . L.map f
@@ -53,16 +53,10 @@ parseUriQuery = filterMaybes . parseQueryText . BC.pack . uriQuery
53 f (a, Nothing) = Nothing 53 f (a, Nothing) = Nothing
54 f (a, Just b ) = Just (a, b) 54 f (a, Just b ) = Just (a, b)
55 55
56test = do
57 let q = unGen arbitrary (mkStdGen 0) 0
58 print $ renderAnnounceQuery baseURI q
59 print $ parseUriQuery $ renderAnnounceQuery baseURI q
60
61spec :: Spec 56spec :: Spec
62spec = do 57spec = do
63 describe "Announce" $ do 58 describe "Announce" $ do
64 before test $ 59 it "properly url encoded" $ property $ \ q ->
65 it "properly url encoded" $ property $ \ q ->
66 parseAnnounceQuery (parseUriQuery (renderAnnounceQuery baseURI q)) 60 parseAnnounceQuery (parseUriQuery (renderAnnounceQuery baseURI q))
67 `shouldBe` Right q 61 `shouldBe` Right q
68 62