From: Jaseem Abid Date: Sat, 21 Mar 2015 16:44:09 +0000 (+0530) Subject: Tests for decode X-Git-Url: https://git.rkrishnan.org/components/com_hotproperty/css/flags/about.html?a=commitdiff_plain;h=7b5257db477f06b0838d25aed1bd0f26ce25a0aa;p=functorrent.git Tests for decode --- diff --git a/README b/README index 8aa5012..5ab648c 100644 --- a/README +++ b/README @@ -11,7 +11,7 @@ clone the repo; cd functorrent; 1. cabal sandbox init 2. wget http://www.stackage.org/lts/cabal.config -3. cabal install --only-dependencies +3. cabal install --only-dependencies --enable-tests 4. cabal build # binaries in ./dist/built/functorrent/* Goals diff --git a/data/debian-7.8.0-amd64-CD-1.iso.cache b/data/debian-7.8.0-amd64-CD-1.iso.cache new file mode 100644 index 0000000..9086a9d --- /dev/null +++ b/data/debian-7.8.0-amd64-CD-1.iso.cache @@ -0,0 +1,3 @@ +d8:intervali900e5:peers300:UÉeÈÕ%;ìVÎL•+ʚ·!Í©ËÕÒxVkXÕïØÍ[À£˜.:>ÒðAWTúg¡%XÃñÀÈÕX¥=ßáVêóè¿Õ)‰òÈÕ[ +T÷]@8ù·oÊ>Gê+~záØD©…HÄ.߇a±å½¦]vûËȔmÈÕmâì ­œN:‹šY"¼ô/ºšÛËVÌoÌ»Pn(bD»ŽÙãðGs‹´öYF©#­ÈÕ¹‡º*‰XÆàÊÈÕ·AÙ#ÛWû½–¶XWrÊ®0i]:ÈÓYf E'<^ŸÞ=§_1°åªÙr:‡áO¢&‹Þˆ©2H֏»C¼—ÈÕOoÚ2ф>K‰ÈÕÌœ-PO¢"_ÓRÀöèÔ"ç +PÌ_áöÝÈÕ|)ífa*6:peers60:e \ No newline at end of file diff --git a/functorrent.cabal b/functorrent.cabal index e89c36c..ad38508 100644 --- a/functorrent.cabal +++ b/functorrent.cabal @@ -26,8 +26,9 @@ library hs-source-dirs: src ghc-options: -Wall -fwarn-incomplete-patterns default-language: Haskell2010 - build-depends: base, - HTTP, + build-depends: HTTP, + HUnit, + base, base16-bytestring, binary, bytestring, @@ -35,7 +36,9 @@ library cryptohash, doctest, network-uri, - parsec + parsec, + tasty, + tasty-hunit executable functorrent main-is: Main.hs @@ -43,8 +46,8 @@ executable functorrent hs-source-dirs: src ghc-options: -Wall -fwarn-incomplete-patterns default-language: Haskell2010 - build-depends: base, - HTTP, + build-depends: HTTP, + base, base16-bytestring, binary, bytestring, @@ -53,3 +56,16 @@ executable functorrent doctest, network-uri, parsec + +test-suite lisper-test + type: exitcode-stdio-1.0 + default-language: Haskell2010 + hs-source-dirs: test + main-is: Test.hs + build-depends: HUnit, + base, + bytestring, + containers, + functorrent, + tasty, + tasty-hunit diff --git a/test/Test.hs b/test/Test.hs new file mode 100644 index 0000000..5569d03 --- /dev/null +++ b/test/Test.hs @@ -0,0 +1,36 @@ +{-# LANGUAGE OverloadedStrings #-} +module Main where + +import Prelude hiding (readFile) +import Data.ByteString.Char8 (readFile) +import Data.Map.Strict (fromList) + +import Test.Tasty +import Test.Tasty.HUnit + +import FuncTorrent.Bencode (decode, BVal(..)) + + + +debian :: BVal +debian = Bdict (fromList [ + (Bstr "interval", Bint 900), + (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*"), + (Bstr "peers6", Bstr "") + ]) + +testSimple :: TestTree +testSimple = testCase "Should parse regular torrent files" $ do + str <- readFile "./data/debian-7.8.0-amd64-CD-1.iso.cache" + case decode str of + Right expected -> expected @?= debian + Left _ -> error "Failed parsing test file" + +unitTests :: TestTree +unitTests = testGroup "Unit tests" [testSimple] + +tests :: TestTree +tests = testGroup "Tests" [unitTests] + +main :: IO () +main = defaultMain tests