From 46bdd60f94fe2f9eedf6fc14146bccf41348e5bd Mon Sep 17 00:00:00 2001 From: Sam T Date: Mon, 26 Aug 2013 05:12:18 +0400 Subject: + Added tests for generic decode & record selectors. --- TODO.org | 2 +- src/Data/BEncode.hs | 3 ++- tests/properties.hs | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/TODO.org b/TODO.org index c174d42..6c0c22f 100644 --- a/TODO.org +++ b/TODO.org @@ -1,4 +1,4 @@ * DONE generic decode -* TODO tests for generics with record selectors +* DONE tests for generics with record selectors * TODO documentation * TODO v0.1.1.0 (reason: Dict ty syn exposed) diff --git a/src/Data/BEncode.hs b/src/Data/BEncode.hs index 87321f2..e270525 100644 --- a/src/Data/BEncode.hs +++ b/src/Data/BEncode.hs @@ -227,7 +227,8 @@ instance (GBEncodable a Dict, GBEncodable b Dict) gto (a :*: b) = gto a <> gto b {-# INLINE gfrom #-} - gfrom = error "gfrom: not implemented" + -- Just look at this! >.< + gfrom dict = (:*:) <$> gfrom dict <*> gfrom dict instance (GBEncodable a e, GBEncodable b e) diff --git a/tests/properties.hs b/tests/properties.hs index 23371ba..12f3dfc 100644 --- a/tests/properties.hs +++ b/tests/properties.hs @@ -1,4 +1,5 @@ {-# LANGUAGE DeriveGeneric #-} +{-# OPTIONS -fno-warn-unused-binds #-} module Main (main) where import Control.Applicative @@ -39,14 +40,30 @@ instance Arbitrary a => Arbitrary (List a) where , (10, Cons <$> arbitrary <*> arbitrary) ] +data FileInfo = FileInfo + { fiLength :: !Integer + , fiPath :: [B.ByteString] + , fiMD5Sum :: B.ByteString + } deriving (Show, Eq, Generic) + +instance BEncodable FileInfo + +instance Arbitrary FileInfo where + arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary + data T a = T prop_bencodable :: Eq a => BEncodable a => T a -> a -> Bool prop_bencodable _ x = decoded (L.toStrict (encoded x)) == Right x +-- All tests are (encode >>> decode = id) main :: IO () main = defaultMain - [ testProperty "encode >>> decode = id" prop_EncDec - , testProperty "generic encode >>> decode = id" $ + [ testProperty "BEncode" prop_EncDec + + , testProperty "generic recordless" $ prop_bencodable (T :: T (List Int)) + + , testProperty "generic records" $ + prop_bencodable (T :: T FileInfo) ] \ No newline at end of file -- cgit v1.2.3