summaryrefslogtreecommitdiff
path: root/tests/Hakyll/Core
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-10-29 15:01:58 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-10-29 15:01:58 +0100
commite5c97d978bf34bdc98d97bf42ee2be29a5af4242 (patch)
tree723e4e0798d2d0111076cc8ca610c23f009b5e2c /tests/Hakyll/Core
parent5f805f1e32ccbbfc6ac917c8caa1f48382d04101 (diff)
downloadhakyll-e5c97d978bf34bdc98d97bf42ee2be29a5af4242.tar.gz
Pick Store from the develop branch
Diffstat (limited to 'tests/Hakyll/Core')
-rw-r--r--tests/Hakyll/Core/Store/Tests.hs81
1 files changed, 41 insertions, 40 deletions
diff --git a/tests/Hakyll/Core/Store/Tests.hs b/tests/Hakyll/Core/Store/Tests.hs
index 53ad74e..3188c30 100644
--- a/tests/Hakyll/Core/Store/Tests.hs
+++ b/tests/Hakyll/Core/Store/Tests.hs
@@ -1,67 +1,68 @@
+--------------------------------------------------------------------------------
{-# LANGUAGE OverloadedStrings #-}
module Hakyll.Core.Store.Tests
( tests
) where
-import Control.Applicative ((<$>))
-import Control.Monad (replicateM)
-import Test.Framework
-import Test.Framework.Providers.QuickCheck2
-import Test.Framework.Providers.HUnit
-import Test.QuickCheck
-import Test.QuickCheck.Monadic
-import qualified Test.HUnit as H
+--------------------------------------------------------------------------------
+import Data.Typeable (typeOf)
+import Test.Framework
+import Test.Framework.Providers.HUnit
+import Test.Framework.Providers.QuickCheck2
+import qualified Test.HUnit as H
+import Test.QuickCheck
+import Test.QuickCheck.Monadic
-import Hakyll.Core.Identifier
-import Hakyll.Core.Store
-import TestSuite.Util
+--------------------------------------------------------------------------------
+import qualified Hakyll.Core.Store as Store
+import TestSuite.Util
+
+
+--------------------------------------------------------------------------------
tests :: [Test]
tests =
- [ testProperty "simple storeGet . storeSet" simpleSetGet
- , testProperty "persistent storeGet . storeSet" persistentSetGet
- , testCase "WrongType storeGet . storeSet" wrongType
+ [ testProperty "simple get . set" simpleSetGet
+ , testProperty "persistent get . set" persistentSetGet
+ , testCase "WrongType get . set" wrongType
]
+
+--------------------------------------------------------------------------------
simpleSetGet :: Property
simpleSetGet = monadicIO $ do
- identifier <- parseIdentifier . unFileName <$> pick arbitrary
- FileName name <- pick arbitrary
+ key <- pick arbitrary
value <- pick arbitrary
store <- run $ makeStoreTest
- run $ storeSet store name identifier (value :: String)
- value' <- run $ storeGet store name identifier
- assert $ Found value == value'
+ run $ Store.set store key (value :: String)
+ value' <- run $ Store.get store key
+ assert $ Store.Found value == value'
+
+--------------------------------------------------------------------------------
persistentSetGet :: Property
persistentSetGet = monadicIO $ do
- identifier <- parseIdentifier . unFileName <$> pick arbitrary
- FileName name <- pick arbitrary
- value <- pick arbitrary
+ key <- pick arbitrary
+ value <- pick arbitrary
store1 <- run $ makeStoreTest
- run $ storeSet store1 name identifier (value :: String)
+ run $ Store.set store1 key (value :: String)
-- Now Create another store from the same dir to test persistence
store2 <- run $ makeStoreTest
- value' <- run $ storeGet store2 name identifier
- assert $ Found value == value'
+ value' <- run $ Store.get store2 key
+ assert $ Store.Found value == value'
+
+--------------------------------------------------------------------------------
wrongType :: H.Assertion
wrongType = do
store <- makeStoreTest
-- Store a string and try to fetch an int
- storeSet store "foo" "bar" ("qux" :: String)
- value <- storeGet store "foo" "bar" :: IO (StoreGet Int)
- H.assert $ case value of WrongType _ _ -> True
- _ -> False
-
-newtype FileName = FileName {unFileName :: String}
- deriving (Show)
-
-instance Arbitrary FileName where
- arbitrary = do
- length' <- choose (5, 100)
- str <- replicateM length' $ elements cs
- return $ FileName str
- where
- cs = ['a' .. 'z'] ++ ['A' .. 'Z'] ++ ['0' .. '9'] ++ ".- "
+ Store.set store ["foo", "bar"] ("qux" :: String)
+ value <- Store.get store ["foo", "bar"] :: IO (Store.Result Int)
+ print value
+ H.assert $ case value of
+ Store.WrongType e t ->
+ e == typeOf (undefined :: Int) &&
+ t == typeOf (undefined :: String)
+ _ -> False