diff options
Diffstat (limited to 'tests/Network/BitTorrent/Tracker/MessageSpec.hs')
-rw-r--r-- | tests/Network/BitTorrent/Tracker/MessageSpec.hs | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/tests/Network/BitTorrent/Tracker/MessageSpec.hs b/tests/Network/BitTorrent/Tracker/MessageSpec.hs index 99518067..8a06aaba 100644 --- a/tests/Network/BitTorrent/Tracker/MessageSpec.hs +++ b/tests/Network/BitTorrent/Tracker/MessageSpec.hs | |||
@@ -3,14 +3,19 @@ module Network.BitTorrent.Tracker.MessageSpec (spec) where | |||
3 | 3 | ||
4 | import Control.Applicative | 4 | import Control.Applicative |
5 | import Data.BEncode as BE | 5 | import Data.BEncode as BE |
6 | import Data.ByteString.Char8 as BC | ||
6 | import Data.ByteString.Lazy as BL | 7 | import Data.ByteString.Lazy as BL |
8 | import Data.List as L | ||
7 | import Data.Maybe | 9 | import Data.Maybe |
8 | import Data.Word | 10 | import Data.Word |
11 | import Data.Text | ||
9 | import Network | 12 | import Network |
10 | import Network.URI | 13 | import Network.URI |
11 | import Test.Hspec | 14 | import Test.Hspec |
12 | import Test.QuickCheck | 15 | import Test.QuickCheck |
13 | --import Network.HTTP.Types.URI | 16 | import Test.QuickCheck.Gen |
17 | import Network.HTTP.Types.URI | ||
18 | import System.Random | ||
14 | 19 | ||
15 | import Data.Torrent.InfoHashSpec () | 20 | import Data.Torrent.InfoHashSpec () |
16 | import Data.Torrent.ProgressSpec () | 21 | import Data.Torrent.ProgressSpec () |
@@ -39,9 +44,27 @@ instance Arbitrary AnnounceQuery where | |||
39 | baseURI :: URI | 44 | baseURI :: URI |
40 | baseURI = fromJust $ parseURI "http://a" | 45 | baseURI = fromJust $ parseURI "http://a" |
41 | 46 | ||
47 | parseUriQuery :: URI -> [(Text, Text)] | ||
48 | parseUriQuery = filterMaybes . parseQueryText . BC.pack . uriQuery | ||
49 | where | ||
50 | filterMaybes :: [(a, Maybe b)] -> [(a, b)] | ||
51 | filterMaybes = catMaybes . L.map f | ||
52 | where | ||
53 | f (a, Nothing) = Nothing | ||
54 | f (a, Just b ) = Just (a, b) | ||
55 | |||
56 | test = do | ||
57 | let q = unGen arbitrary (mkStdGen 0) 0 | ||
58 | print $ renderAnnounceQuery baseURI q | ||
59 | print $ parseUriQuery $ renderAnnounceQuery baseURI q | ||
60 | |||
42 | spec :: Spec | 61 | spec :: Spec |
43 | spec = do | 62 | spec = do |
44 | describe "Announce" $ do | 63 | describe "Announce" $ do |
45 | return () | 64 | before test $ |
65 | it "properly url encoded" $ property $ \ q -> | ||
66 | parseAnnounceQuery (parseUriQuery (renderAnnounceQuery baseURI q)) | ||
67 | `shouldBe` Right q | ||
68 | |||
46 | describe "Scrape" $ do | 69 | describe "Scrape" $ do |
47 | return () | 70 | return () |