summaryrefslogtreecommitdiff
path: root/Types/Key.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-02-27 21:42:07 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-02-27 21:42:07 -0400
commitca59b87b11c01c417a7b3b8f0cf15426e6fadcfb (patch)
tree36c342a8ae999986aabf51d6a3371515e9ac1dfd /Types/Key.hs
parentf54b34a6e6cb000d3117106fd19c13ef9dc7f38f (diff)
move Arbitrary instances out of Test and into modules that define the types
This is possible now that we build-depend on QuickCheck.
Diffstat (limited to 'Types/Key.hs')
-rw-r--r--Types/Key.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/Types/Key.hs b/Types/Key.hs
index ecdf7b842..e955725c7 100644
--- a/Types/Key.hs
+++ b/Types/Key.hs
@@ -17,6 +17,8 @@ module Types.Key (
) where
import System.Posix.Types
+import Test.QuickCheck
+import Utility.QuickCheck ()
import Common
@@ -74,5 +76,12 @@ file2key s = if key == Just stubKey then Nothing else key
addfield 'm' k v = Just k { keyMtime = readish v }
addfield _ _ _ = Nothing
+instance Arbitrary Key where
+ arbitrary = Key
+ <$> arbitrary
+ <*> (listOf1 $ elements ['A'..'Z']) -- BACKEND
+ <*> ((abs <$>) <$> arbitrary) -- size cannot be negative
+ <*> arbitrary
+
prop_idempotent_key_encode :: Key -> Bool
prop_idempotent_key_encode k = Just k == (file2key . key2file) k