summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSam T <pxqr.sta@gmail.com>2013-08-26 05:12:18 +0400
committerSam T <pxqr.sta@gmail.com>2013-08-26 05:12:18 +0400
commit46bdd60f94fe2f9eedf6fc14146bccf41348e5bd (patch)
tree377bbc62de1d3ef6a9af10cd96fa65330bde11e3 /tests
parent97a6f7ccc7fc87279e8046f9e49061619d8dcdd8 (diff)
+ Added tests for generic decode & record selectors.
Diffstat (limited to 'tests')
-rw-r--r--tests/properties.hs21
1 files changed, 19 insertions, 2 deletions
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 @@
1{-# LANGUAGE DeriveGeneric #-} 1{-# LANGUAGE DeriveGeneric #-}
2{-# OPTIONS -fno-warn-unused-binds #-}
2module Main (main) where 3module Main (main) where
3 4
4import Control.Applicative 5import Control.Applicative
@@ -39,14 +40,30 @@ instance Arbitrary a => Arbitrary (List a) where
39 , (10, Cons <$> arbitrary <*> arbitrary) 40 , (10, Cons <$> arbitrary <*> arbitrary)
40 ] 41 ]
41 42
43data FileInfo = FileInfo
44 { fiLength :: !Integer
45 , fiPath :: [B.ByteString]
46 , fiMD5Sum :: B.ByteString
47 } deriving (Show, Eq, Generic)
48
49instance BEncodable FileInfo
50
51instance Arbitrary FileInfo where
52 arbitrary = FileInfo <$> arbitrary <*> arbitrary <*> arbitrary
53
42data T a = T 54data T a = T
43 55
44prop_bencodable :: Eq a => BEncodable a => T a -> a -> Bool 56prop_bencodable :: Eq a => BEncodable a => T a -> a -> Bool
45prop_bencodable _ x = decoded (L.toStrict (encoded x)) == Right x 57prop_bencodable _ x = decoded (L.toStrict (encoded x)) == Right x
46 58
59-- All tests are (encode >>> decode = id)
47main :: IO () 60main :: IO ()
48main = defaultMain 61main = defaultMain
49 [ testProperty "encode >>> decode = id" prop_EncDec 62 [ testProperty "BEncode" prop_EncDec
50 , testProperty "generic encode >>> decode = id" $ 63
64 , testProperty "generic recordless" $
51 prop_bencodable (T :: T (List Int)) 65 prop_bencodable (T :: T (List Int))
66
67 , testProperty "generic records" $
68 prop_bencodable (T :: T FileInfo)
52 ] \ No newline at end of file 69 ] \ No newline at end of file