bencoding 0.4.0.2 → 0.4.1.0
raw patch · 7 files changed
+81/−47 lines, 7 filesdep +hspecdep −test-frameworkdep −test-framework-quickcheck2
Dependencies added: hspec
Dependencies removed: test-framework, test-framework-quickcheck2
Files
- ChangeLog +32/−0
- bencoding.cabal +6/−6
- changelog +0/−7
- src/Data/BEncode.hs +1/−1
- src/Data/BEncode/BDict.hs +3/−2
- src/Data/BEncode/Internal.hs +7/−2
- tests/properties.hs +32/−29
+ ChangeLog view
@@ -0,0 +1,32 @@+2013-12-08 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.4.1.0: Expose parser and builder so it is possible to use+ parser incrementally.++2013-10-01 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.4.0.2: Minor fixes.++2013-10-01 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.4.0.1: Nothing changed.++2013-10-01 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.4.0.0: Faster dictionary conversion.++2013-09-28 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.3.0.0: Rename BEncode to BValue and BEncodable to BEncode.++2013-09-28 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.2.2.0: Arbitrary length integers. (by specification)++2013-08-26 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.2.0.0: Added default decoders/encoders using GHC Generics.++2013-06-09 Sam Truzjan <pxqr.sta@gmail.com>++ * 0.1.0.0: Initial version.
bencoding.cabal view
@@ -1,5 +1,5 @@ name: bencoding-version: 0.4.0.2+version: 0.4.1.0 license: BSD3 license-file: LICENSE author: Sam Truzjan@@ -18,7 +18,7 @@ A library for fast and easy encoding and decoding of BEncode data. extra-source-files: README.md- , changelog+ , ChangeLog source-repository head type: git@@ -29,7 +29,7 @@ type: git location: git://github.com/cobit/bencoding.git branch: master- tag: v0.4.0.2+ tag: v0.4.1.0 library default-language: Haskell2010@@ -63,10 +63,10 @@ , bytestring >= 0.10.0.2 , attoparsec >= 0.10 - , test-framework- , test-framework-quickcheck2- , QuickCheck , bencoding+ , hspec+ , QuickCheck+ ghc-options: -Wall -fno-warn-orphans
− changelog
@@ -1,7 +0,0 @@-* 0.1.0.0: Initial version.-* 0.2.0.0: Added default decoders/encoders using GHC Generics.-* 0.2.2.0: Arbitrary length integers. (by specification)-* 0.3.0.0: Rename BEncode to BValue and BEncodable to BEncode.-* 0.4.0.0: Faster dictionary conversion.-* 0.4.0.1: Nothing changed.-* 0.4.0.2: Minor fixes.
src/Data/BEncode.hs view
@@ -21,7 +21,7 @@ -- -- To serialize any other types we need to make conversion. To -- make conversion more convenient there is type class for it:--- 'BEncodable'. Any textual strings are considered as UTF8 encoded+-- 'BEncode'. Any textual strings are considered as UTF8 encoded -- 'Text'. -- -- The complete Augmented BNF syntax for bencoding format is:
src/Data/BEncode/BDict.hs view
@@ -5,8 +5,9 @@ -- Stability : stable -- Portability : portable ----- This module defines a simple key\/value list which both faster--- and more suitable for bencode dictionaries then just [(k,v)].+-- This module defines a simple key\/value list ordered by keys+-- which both faster and more suitable for bencode dictionaries than+-- just [(k,v)]. -- module Data.BEncode.BDict ( BKey
src/Data/BEncode/Internal.hs view
@@ -6,10 +6,15 @@ -- Portability : portable -- -- This module provides bencode values serialization. Normally, you--- don't need to import this module.+-- don't need to import this module, use 'Data.BEncode' instead. -- module Data.BEncode.Internal- ( parse+ ( -- * Parsing+ parser+ , parse++ -- * Rendering+ , builder , build , ppBEncode ) where
tests/properties.hs view
@@ -3,31 +3,33 @@ module Main (main) where import Control.Applicative-import qualified Data.ByteString as B-import qualified Data.ByteString.Lazy as L-import Test.Framework (defaultMain)-import Test.Framework.Providers.QuickCheck2 (testProperty)-import Test.QuickCheck+import Data.ByteString as BS+import Data.ByteString.Lazy as BL+import Data.List as L import GHC.Generics+import Test.QuickCheck+import Test.Hspec import Data.BEncode+import qualified Data.BEncode.BDict as BE -instance Arbitrary B.ByteString where- arbitrary = fmap B.pack arbitrary--instance Arbitrary BValue where- arbitrary = frequency- [ (50, BInteger <$> arbitrary)- , (40, BString <$> arbitrary)- , (5, BList <$> (arbitrary `suchThat` ((10 >) . length)))- ]+instance Arbitrary BS.ByteString where+ arbitrary = BS.pack <$> arbitrary +instance Arbitrary a => Arbitrary (BE.BDictMap a) where+ arbitrary = frequency+ [ (90, pure BE.Nil)+ , (10, BE.Cons <$> arbitrary <*> arbitrary <*> arbitrary)+ ] -prop_EncDec :: BValue -> Bool-prop_EncDec x = case decode (L.toStrict (encode x)) of- Left _ -> False- Right x' -> x == x'+instance Arbitrary BValue where+ arbitrary = frequency+ [ (30, BInteger <$> arbitrary)+ , (30, BString <$> arbitrary)+ , (20, BList <$> (arbitrary `suchThat` ((10 >) . L.length)))+ , (20, BDict <$> arbitrary)+ ] data List a = Cons a (List a) | Nil deriving (Show, Eq, Generic)@@ -42,8 +44,8 @@ data FileInfo = FileInfo { fiLength :: !Integer- , fiPath :: [B.ByteString]- , fiMD5Sum :: B.ByteString+ , fiPath :: [BS.ByteString]+ , fiMD5Sum :: BS.ByteString } deriving (Show, Eq, Generic) instance BEncode FileInfo@@ -54,16 +56,17 @@ data T a = T prop_bencodable :: Eq a => BEncode a => T a -> a -> Bool-prop_bencodable _ x = decode (L.toStrict (encode x)) == Right x+prop_bencodable _ x = decode (BL.toStrict (encode x)) == Right x --- All tests are (encode >>> decode = id) main :: IO ()-main = defaultMain- [ testProperty "BEncode" prop_EncDec+main = hspec $ do+ describe "BValue" $ do+ it "properly encoded" $ property $+ prop_bencodable (T :: T BValue) - , testProperty "generic recordless" $- prop_bencodable (T :: T (List Int))+ describe "BEncode" $ do+ it "generic recordless" $ property $+ prop_bencodable (T :: T (List Int)) - , testProperty "generic records" $- prop_bencodable (T :: T FileInfo)- ]+ it "generic records" $ property $+ prop_bencodable (T :: T FileInfo)