2 - Copyright (C) 2015-2016 Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
4 - This file is part of FuncTorrent.
6 - FuncTorrent is free software; you can redistribute it and/or modify
7 - it under the terms of the GNU General Public License as published by
8 - the Free Software Foundation; either version 3 of the License, or
9 - (at your option) any later version.
11 - FuncTorrent is distributed in the hope that it will be useful,
12 - but WITHOUT ANY WARRANTY; without even the implied warranty of
13 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 - GNU General Public License for more details.
16 - You should have received a copy of the GNU General Public License
17 - along with FuncTorrent; if not, see <http://www.gnu.org/licenses/>
20 {-# LANGUAGE OverloadedStrings #-}
22 module MetainfoSpec where
26 import FuncTorrent.Metainfo (Info(..), Metainfo(..), DynamicInfo(..), torrentToMetainfo)
27 import qualified Data.ByteString.Lazy.Char8 as BC (readFile, toStrict)
28 import qualified Data.ByteString as B
32 describe "Bencode" $ do
33 it "torrent-file-1" $ do
34 c <- BC.readFile "data/test1.torrent"
35 let (Right m) = torrentToMetainfo (BC.toStrict c)
36 length (announceList m) `shouldBe` 1
37 pieceLength (info m) `shouldBe` 524288
38 pieces (info m) `shouldSatisfy` (\p -> B.length p `mod` 20 == 0)
39 let (SingleFileInfo name' _ _) = dyninfo $ info m
40 name' `shouldNotBe` ""
41 it "torrent-file-4" $ do
42 c <- BC.readFile "data/test4.torrent"
43 let (Right m) = torrentToMetainfo (BC.toStrict c)
44 length (announceList m) `shouldBe` 3
45 let (MultiFileInfo _ files') = dyninfo $ info m
46 length files' `shouldNotBe` 1