summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO.org2
-rw-r--r--src/Data/BEncode.hs3
-rw-r--r--tests/properties.hs21
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 @@
1* DONE generic decode 1* DONE generic decode
2* TODO tests for generics with record selectors 2* DONE tests for generics with record selectors
3* TODO documentation 3* TODO documentation
4* TODO v0.1.1.0 (reason: Dict ty syn exposed) 4* 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)
227 gto (a :*: b) = gto a <> gto b 227 gto (a :*: b) = gto a <> gto b
228 228
229 {-# INLINE gfrom #-} 229 {-# INLINE gfrom #-}
230 gfrom = error "gfrom: not implemented" 230 -- Just look at this! >.<
231 gfrom dict = (:*:) <$> gfrom dict <*> gfrom dict
231 232
232 233
233instance (GBEncodable a e, GBEncodable b e) 234instance (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 @@
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