]> git.rkrishnan.org Git - functorrent.git/blob - test/BencodeTests.hs
8e54e93e1e431de55175092bad4e560eaa654b99
[functorrent.git] / test / BencodeTests.hs
1 module BencodeTests (tests) where
2
3 import FuncTorrent.Bencode (encode, decode, BVal(..))
4
5 import Test.Hspec
6 import Test.QuickCheck
7 import Data.ByteString.Char8 (unpack, pack)
8
9 propEncodeDecode :: BVal -> Bool
10 propEncodeDecode bval = let encoded = encode bval
11                             decoded = decode encoded
12                         in Right bval == decoded
13
14 tests :: IO ()
15 tests = hspec $ do
16   describe "BVal tests" $ do
17     it "encode/decode bstr tests" $ do
18       property $ \s ->
19         let encoded = encode (Bstr s)
20             decoded = decode encoded
21         in Right (Bstr s) == decoded
22     it "encode/decode bint tests" $ do
23       property $ \i ->
24         let encoded = encode (Bint i)
25             decoded = decode encoded
26         in Right (Bint i) == decoded
27     it "encode/decode blist tests" $ do
28       property $ \bval ->
29         let encoded = encode (Blist (take 1 bval))
30             decoded = decode encoded
31         in Right (Blist (take 1 bval)) == decoded
32     -- it "encode/decode" $ do
33     --   property $ \bval ->
34     --     let encoded = encode bval
35     --         decoded = decode encoded
36     --     in Right bval == decoded