@@ -11,10 +11,11 @@ import qualified Data.Map as M
1111import Data.List (isPrefixOf)
1212import Data.Char (isSpace)
1313import Data.Maybe (fromMaybe)
14−import Control.Monad (liftM)
14+import Control.Monad (liftM, replicateM)
1515import Control.Monad.Reader (liftIO)
1616import System.FilePath (takeExtension, (</>))
1717
18+import Test.QuickCheck
1819import Text.Pandoc
1920import Data.Binary
2021
@@ -29,7 +30,7 @@ import Text.Hakyll.Regex (substituteRegex, matchesRegex)
2930-- | A Page is basically key-value mapping. Certain keys have special
3031-- meanings, like for example url, body and title.
3132data Page = Page Context
32− deriving (Show, Read)
33+ deriving (Show, Read, Eq)
3334
3435-- | Create a Page from a key-value mapping.
3536fromContext :: Context -> Page
@@ -156,3 +157,17 @@ instance Renderable Page where
156157instance Binary Page where
157158 put (Page context) = put $ M.toAscList context
158159 get = liftM (Page . M.fromAscList) get
160+
161+-- | Generate an arbitrary page.
162+arbitraryPage :: Gen Page
163+arbitraryPage = do keys <- listOf key'
164+ values <- arbitrary
165+ return $ Page $ M.fromList $ zip keys values
166+ where
167+ key' = do l <- choose (5, 10)
168+ replicateM l $ choose ('a', 'z')
169+
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