summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoxx <noxx@noxx-inferno.(none)>2013-05-04 15:42:28 +0300
committernoxx <noxx@noxx-inferno.(none)>2013-05-04 15:42:28 +0300
commitf4ee3e7fcb0817098643c6b34cab92466584680a (patch)
treebfee8395df134a5263e6512a196bb42914f90948
parent0f779a8c53039829030eb984528974d80372002d (diff)
downloadhakyll-f4ee3e7fcb0817098643c6b34cab92466584680a.tar.gz
Created tests and fixed isMember function
-rw-r--r--src/Hakyll/Core/Store.hs21
-rw-r--r--tests/Hakyll/Core/Store/Tests.hs16
2 files changed, 26 insertions, 11 deletions
diff --git a/src/Hakyll/Core/Store.hs b/src/Hakyll/Core/Store.hs
index eb2d742..b2c61a0 100644
--- a/src/Hakyll/Core/Store.hs
+++ b/src/Hakyll/Core/Store.hs
@@ -102,13 +102,13 @@ cacheLookup (Store _ (Just lru)) key = do
--------------------------------------------------------------------------------
-cacheIsMember :: Store -> String -> Bool
-cacheIsMember (Store _ Nothing) _ = False
-cacheIsMember (Store _ (Just lru)) key =
- let res = Lru.lookup key lru in
- case Just res of
- Nothing -> False
- _ -> True
+cacheIsMember :: Store -> String -> IO Bool
+cacheIsMember (Store _ Nothing) _ = return False
+cacheIsMember (Store _ (Just lru)) key = do
+ res <- Lru.lookup key lru
+ case res of
+ Nothing -> return False
+ _ -> return True
--------------------------------------------------------------------------------
@@ -165,10 +165,9 @@ get store identifier = do
--------------------------------------------------------------------------------
-- | Strict function
isMember :: Store -> [String] -> IO Bool
-isMember store identifier
- | cacheIsMember store key = return True
- | otherwise = doesFileExist path
-
+isMember store identifier = do
+ inCache <- cacheIsMember store key
+ if inCache then return True else doesFileExist path
where
key = hash identifier
path = storeDirectory store </> key
diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs
index 95140e3..389d7fd 100644
--- a/tests/Hakyll/Core/Store/Tests.hs
+++ b/tests/Hakyll/Core/Store/Tests.hs
@@ -26,6 +26,7 @@ tests = testGroup "Hakyll.Core.Store.Tests"
[ testProperty "simple get . set" simpleSetGet
, testProperty "persistent get . set" persistentSetGet
, testCase "WrongType get . set" wrongType
+ , testCase "isMembertest . set" isMembertest
]
@@ -68,3 +69,18 @@ wrongType = do
t == typeOf (undefined :: String)
_ -> False
cleanTestEnv
+
+
+--------------------------------------------------------------------------------
+
+isMembertest :: H.Assertion
+isMembertest = do
+ store <- newTestStore
+ Store.set store ["foo", "bar"] ("qux" :: String)
+ --value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
+ good <- Store.isMember store ["foo", "bar"]
+
+ bad <- Store.isMember store ["foo", "baz"]
+ H.assert good
+ H.assert (not bad)
+ cleanTestEnv \ No newline at end of file