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. --- tests/properties.hs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'tests') 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