]> git.rkrishnan.org Git - functorrent.git/commitdiff
Tests for decode
authorJaseem Abid <jaseemabid@gmail.com>
Sat, 21 Mar 2015 16:44:09 +0000 (22:14 +0530)
committerJaseem Abid <jaseemabid@gmail.com>
Sat, 21 Mar 2015 17:07:43 +0000 (22:37 +0530)
README
data/debian-7.8.0-amd64-CD-1.iso.cache [new file with mode: 0644]
functorrent.cabal
test/Test.hs [new file with mode: 0644]

diff --git a/README b/README
index 8aa501248103a168b84fc0958f8b3c6981851e67..5ab648c141b8f9cefa75aa5db7c7b6f8c1eb7d40 100644 (file)
--- 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 (file)
index 0000000..9086a9d
--- /dev/null
@@ -0,0 +1,3 @@
+d8:intervali900e5:peers300:U\19ÉeÈÕ%;\1cìVÎL\15\95\9a\1f·!Í©ËÕÒxVkXÕïØÍ\e\ 2[À£\98.:>ÒðA\eWTúg¡\e%XÃñÀÈÕX¥=ß\1aáV\9dêóè¿Õ)\89òÈÕ[
+T÷]@8ù·\eoÊ>\10\19\1f+~záØD©\85HÄ.ß\87a±å½\ 5¦]vûËÈ\94m\8dÈÕmâì ­\9cN:\8b\9aY"¼ô/º\9aÛËVÌoÌ»Pn(b\e\ 6\8eÙãðGs\8b´öYF©#­ÈÕ¹\ 3\87º*\89XÆàÊÈÕ·\9dAÙ#ÛWû½\96¶XWrÊ®0i]:\ 5\10ÈÓYf   E'<^\9f\13Þ=§_\1c1°åªÙr:\87\1aáO\8d¢&\8bÞ\88©2HÖ\8f»C¼\97ÈÕOoÚ2Ñ\84>K\89\81ÈÕ\ eÌ\14\9c-PO\8d¢"_ÓR\90À\aöèÔ"ç
+PÌ_áöÝÈÕ|)ífa*6:peers60:e
\ No newline at end of file
index e89c36c50d798d3bb34b8eba4fc23aae89d90037..ad385087ba6c79e58f5bc1e1b944abaa7d4e23f3 100644 (file)
@@ -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 (file)
index 0000000..5569d03
--- /dev/null
@@ -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