summaryrefslogtreecommitdiff
path: root/tests/Network/BitTorrent/Core/PeerIdSpec.hs
blob: 4b0c2398629f8f6b819103f739df585e3bfc54d2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
{-# OPTIONS -fno-warn-orphans #-}
module Network.BitTorrent.Core.PeerIdSpec (spec) where
import Control.Applicative
import Data.BEncode as BE
import Data.Text.Encoding as T
import Test.Hspec
import Test.QuickCheck
import Test.QuickCheck.Instances ()
import Network.BitTorrent.Core.PeerId


instance Arbitrary PeerId where
  arbitrary = oneof
    [ azureusStyle defaultClientId defaultVersionNumber
        <$> (T.encodeUtf8 <$> arbitrary)
    , shadowStyle  'X'             defaultVersionNumber
        <$> (T.encodeUtf8 <$> arbitrary)
    ]

spec :: Spec
spec = do
  describe "PeerId" $ do
    it "properly bencoded" $ do
      BE.decode "20:01234567890123456789"
        `shouldBe` Right ("01234567890123456789" :: PeerId)