summaryrefslogtreecommitdiff
path: root/TypeInternals.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:05:31 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-01-04 21:05:31 -0400
commit759e860e4b6c514b74cafb2c0dd9c52c4d59316b (patch)
treeea09994423b910f2f1f91d46f9e84085f7088c8f /TypeInternals.hs
parentf1b747e6d9fae2b365f65fd43c6295da503218bd (diff)
add testcoverage target using hpc
added a test for key read and show
Diffstat (limited to 'TypeInternals.hs')
-rw-r--r--TypeInternals.hs18
1 files changed, 18 insertions, 0 deletions
diff --git a/TypeInternals.hs b/TypeInternals.hs
index 9acc06bb3..fe6e562f9 100644
--- a/TypeInternals.hs
+++ b/TypeInternals.hs
@@ -12,6 +12,7 @@ module TypeInternals where
import Control.Monad.State (StateT)
import Data.String.Utils
import qualified Data.Map as M
+import Test.QuickCheck
import qualified GitRepo as Git
import qualified GitQueue
@@ -57,6 +58,23 @@ instance Read Key where
b = head l
k = join ":" $ drop 1 l
+-- for quickcheck
+instance Arbitrary Key where
+ arbitrary = do
+ backendname <- arbitrary
+ keyname <- arbitrary
+ return $ Key (backendname, keyname)
+
+prop_idempotent_key_read_show :: Key -> Bool
+prop_idempotent_key_read_show k
+ -- filter out empty key or backend names
+ -- also backend names will not contain colons
+ | null kname || null bname || elem ':' bname = True
+ | otherwise = k == (read $ show k)
+ where
+ bname = backendName k
+ kname = keyName k
+
backendName :: Key -> BackendName
backendName (Key (b,_)) = b
keyName :: Key -> KeyName