]> git.rkrishnan.org Git - functorrent.git/blob - test/Test.hs
Merge pull request #12 from jaseemabid/master
[functorrent.git] / test / Test.hs
1 {-# LANGUAGE OverloadedStrings #-}
2 module Main where
3
4 import Prelude hiding (readFile)
5 import Data.ByteString.Char8 (readFile)
6 import Data.Map.Strict (fromList)
7
8 import Test.Tasty
9 import Test.Tasty.HUnit
10
11 import FuncTorrent.Bencode (decode, BVal(..))
12
13
14
15 debian :: BVal
16 debian = Bdict (fromList [
17                  (Bstr "interval", Bint 900),
18                  (Bstr "peers", Bstr "U\EM\201e\200\213%;\FS\236V\206L\NAK\149+\202\154\US\183!\205\169\203\213\210xVkX\213\239\216\205\ESC\STX[\192\163\152.:>\210\240A\ESCWT\250g\161\ESC%X\195\241\192\200\213X\165=\223\SUB\225V\157\234\243\232\191\213)\137\242\200\213[\nT\195\183]@8\249\183\ESCo\202>\DLEG\234\EM\US+~z\225\216D\169\133H\196.\223\135a\177\229\189\ENQ\166]v\251\203\200\148m\141\200\213m\226\236\160\173\156N:\139\154Y\"\188\244/\186\154\219\203V\204o\204\187Pn(b\ESC\ACKD\187\142\217\227\240Gs\139\180\246YF\169#\173\200\213\185\ETX\135\186*\137X\198\224\202\200\213\183\157A\217#\219W\251\189\150\182XWr\202\174\&0i]:\ENQ\DLE\200\211Yf\tE'<^\159\DC3\222=\167_\FS1\176\229\170\217r:\135\SUB\225O\141\162&\139\222\136\169\&2H\214\143\187C\188\151\200\213Oo\218\&2\209\132>K\137\129\200\213\SO\204\DC4\156-PO\141\162\"_\211R\144\192\a\246\232\212\"\231\nP\204_\225\246\221\200\213|)\237fa*"),
19                  (Bstr "peers6", Bstr "")
20                 ])
21
22 testSimple :: TestTree
23 testSimple = testCase "Should parse regular torrent files" $ do
24                str <- readFile "./data/debian-7.8.0-amd64-CD-1.iso.cache"
25                case decode str of
26                  Right expected -> expected @?= debian
27                  Left _ -> error "Failed parsing test file"
28
29 unitTests :: TestTree
30 unitTests = testGroup "Unit tests" [testSimple]
31
32 tests :: TestTree
33 tests = testGroup "Tests" [unitTests]
34
35 main :: IO ()
36 main = defaultMain tests