summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-25 15:12:20 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-01-25 15:12:20 +0100
commit8e78fe04f69f3d3ff444518844f6755fd379a6aa (patch)
tree635a91673c3207fb780fc3b3c272978b9c76cf2c /src
parentd41500758f884a4e7a54a4696a2a521b4465242f (diff)
downloadhakyll-8e78fe04f69f3d3ff444518844f6755fd379a6aa.tar.gz
Made Arbitrary Page instance.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Hakyll/Page.hs19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Text/Hakyll/Page.hs b/src/Text/Hakyll/Page.hs
index 7aa6a25..8741cd6 100644
--- a/src/Text/Hakyll/Page.hs
+++ b/src/Text/Hakyll/Page.hs
@@ -11,10 +11,11 @@ import qualified Data.Map as M
import Data.List (isPrefixOf)
import Data.Char (isSpace)
import Data.Maybe (fromMaybe)
-import Control.Monad (liftM)
+import Control.Monad (liftM, replicateM)
import Control.Monad.Reader (liftIO)
import System.FilePath (takeExtension, (</>))
+import Test.QuickCheck
import Text.Pandoc
import Data.Binary
@@ -29,7 +30,7 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
-- | A Page is basically key-value mapping. Certain keys have special
-- meanings, like for example url, body and title.
data Page = Page Context
- deriving (Show, Read)
+ deriving (Show, Read, Eq)
-- | Create a Page from a key-value mapping.
fromContext :: Context -> Page
@@ -156,3 +157,17 @@ instance Renderable Page where
instance Binary Page where
put (Page context) = put $ M.toAscList context
get = liftM (Page . M.fromAscList) get
+
+-- | Generate an arbitrary page.
+arbitraryPage :: Gen Page
+arbitraryPage = do keys <- listOf key'
+ values <- arbitrary
+ return $ Page $ M.fromList $ zip keys values
+ where
+ key' = do l <- choose (5, 10)
+ replicateM l $ choose ('a', 'z')
+
+-- Make pages testable
+instance Arbitrary Page where
+ arbitrary = arbitraryPage
+ shrink (Page context) = map (Page . flip M.delete context) $ M.keys context