diff options
author | Daniel Gröber <dxld@darkboxed.org> | 2013-12-25 19:34:35 +0000 |
---|---|---|
committer | Sam Truzjan <pxqr.sta@gmail.com> | 2014-01-04 21:03:11 +0400 |
commit | cc8f393c447b53724ebdcbd8f86301d530550dcc (patch) | |
tree | 830d78fc13d466be01b79d88a86817e4ad40a106 /tests/Network | |
parent | 648283c992ca2036f31dcb2041686d90e92e0d40 (diff) |
Add tests for instance Serialize IP
Diffstat (limited to 'tests/Network')
-rw-r--r-- | tests/Network/BitTorrent/Core/PeerAddrSpec.hs | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/tests/Network/BitTorrent/Core/PeerAddrSpec.hs b/tests/Network/BitTorrent/Core/PeerAddrSpec.hs index 1bc8d4b4..abb90183 100644 --- a/tests/Network/BitTorrent/Core/PeerAddrSpec.hs +++ b/tests/Network/BitTorrent/Core/PeerAddrSpec.hs | |||
@@ -99,7 +99,7 @@ spec = do | |||
99 | `shouldBe` | 99 | `shouldBe` |
100 | "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10" | 100 | "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10" |
101 | 101 | ||
102 | it "properly serialized iso" $ property $ \ ip -> | 102 | it "properly serialized (iso)" $ property $ \ ip -> |
103 | S.decode (S.encode ip) `shouldBe` Right (ip :: IPv6) | 103 | S.decode (S.encode ip) `shouldBe` Right (ip :: IPv6) |
104 | 104 | ||
105 | it "properly bencoded" $ do | 105 | it "properly bencoded" $ do |
@@ -125,6 +125,25 @@ spec = do | |||
125 | 125 | ||
126 | 126 | ||
127 | describe "Peer IP" $ do | 127 | describe "Peer IP" $ do |
128 | it "properly serialized IPv6" $ do | ||
129 | S.decode "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10" | ||
130 | `shouldBe` | ||
131 | Right ("102:304:506:708:90a:b0c:d0e:f10" :: IP) | ||
132 | |||
133 | S.encode ("102:304:506:708:90a:b0c:d0e:f10" :: IP) | ||
134 | `shouldBe` | ||
135 | "\x1\x2\x3\x4\x5\x6\x7\x8\x9\xa\xb\xc\xd\xe\xf\x10" | ||
136 | |||
137 | it "properly serialized (iso) IPv6" $ property $ \ ip -> | ||
138 | S.decode (S.encode ip) `shouldBe` Right (ip :: IP) | ||
139 | |||
140 | it "properly serialized IPv4" $ do | ||
141 | S.decode "\x1\x2\x3\x4" `shouldBe` Right (IPv4 $ toIPv4 [1, 2, 3, 4]) | ||
142 | S.encode (toIPv4 [1, 2, 3, 4]) `shouldBe` "\x1\x2\x3\x4" | ||
143 | |||
144 | it "properly serialized (iso) IPv4" $ property $ \ ip -> do | ||
145 | S.decode (S.encode ip) `shouldBe` Right (ip :: IP) | ||
146 | |||
128 | it "properly bencoded" $ do | 147 | it "properly bencoded" $ do |
129 | BE.decode "11:168.192.0.1" `shouldBe` | 148 | BE.decode "11:168.192.0.1" `shouldBe` |
130 | Right (IPv4 (toIPv4 [168, 192, 0, 1])) | 149 | Right (IPv4 (toIPv4 [168, 192, 0, 1])) |