diff options
-rw-r--r-- | src/Hakyll/Core/Store.hs | 21 | ||||
-rw-r--r-- | tests/Hakyll/Core/Store/Tests.hs | 16 |
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 |