@@ -11,10 +11,11 @@ import qualified Data.Map as M
11import Data.List (isPrefixOf)
11import Data.List (isPrefixOf)
12import Data.Char (isSpace)
12import Data.Char (isSpace)
13import Data.Maybe (fromMaybe)
13import Data.Maybe (fromMaybe)
14−import Control.Monad (liftM)
14+import Control.Monad (liftM, replicateM)
15import Control.Monad.Reader (liftIO)
15import Control.Monad.Reader (liftIO)
16import System.FilePath (takeExtension, (</>))
16import System.FilePath (takeExtension, (</>))
18+import Test.QuickCheck
18import Text.Pandoc
19import Text.Pandoc
19import Data.Binary
20import Data.Binary
@@ -29,7 +30,7 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
29-- | A Page is basically key-value mapping. Certain keys have special
30-- | A Page is basically key-value mapping. Certain keys have special
30-- meanings, like for example url, body and title.
31-- meanings, like for example url, body and title.
31data Page = Page Context
32data Page = Page Context
32− deriving (Show, Read)
33+ deriving (Show, Read, Eq)
34-- | Create a Page from a key-value mapping.
35-- | Create a Page from a key-value mapping.
35fromContext :: Context -> Page
36fromContext :: Context -> Page
@@ -156,3 +157,17 @@ instance Renderable Page where
156instance Binary Page where
157instance Binary Page where
157 put (Page context) = put $ M.toAscList context
158 put (Page context) = put $ M.toAscList context
158 get = liftM (Page . M.fromAscList) get
159 get = liftM (Page . M.fromAscList) get
161+-- | Generate an arbitrary page.
162+arbitraryPage :: Gen Page
163+arbitraryPage = do keys <- listOf key'
165+ return $ Page $ M.fromList $ zip keys values
167+ key' = do l <- choose (5, 10)
168+ replicateM l $ choose ('a', 'z')
170+-- Make pages testable
171+instance Arbitrary Page where
172+ arbitrary = arbitraryPage
173+ shrink (Page context) = map (Page . flip M.delete context) $ M.keys context