From 057b7fa4851591309ed7de11d7d748779444d92b Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 1 Apr 2010 12:27:27 +0200 Subject: Moved Arbitrary Template instance to tests. This way, the code for Text.Hakyll.Internal.Template is cleaner, and our library does not depend on QuickCheck anymore. --- src/Text/Hakyll/Internal/Template.hs | 36 ++---------------------------------- 1 file changed, 2 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/Text/Hakyll/Internal/Template.hs b/src/Text/Hakyll/Internal/Template.hs index 2a9b588..8b4d6c7 100644 --- a/src/Text/Hakyll/Internal/Template.hs +++ b/src/Text/Hakyll/Internal/Template.hs @@ -1,5 +1,5 @@ module Text.Hakyll.Internal.Template - ( Template + ( Template (..) , fromString , readTemplate , substitute @@ -11,14 +11,11 @@ import qualified Data.Map as M import Data.List (isPrefixOf) import Data.Char (isAlphaNum) import Data.Binary -import Control.Monad (liftM, liftM2, replicateM) -import Control.Applicative ((<$>)) +import Control.Monad (liftM, liftM2) import Data.Maybe (fromMaybe) import System.FilePath (()) import Control.Monad.Reader (liftIO) -import Test.QuickCheck - import Text.Hakyll.Context (Context) import Text.Hakyll.HakyllMonad (Hakyll) import Text.Hakyll.Internal.Cache @@ -91,32 +88,3 @@ instance Binary Template where 2 -> liftM EscapeCharacter get 3 -> return End _ -> error "Error reading template" - --- | Generate arbitrary templates from a given length. -arbitraryTemplate :: Int -> Gen Template -arbitraryTemplate 0 = return End -arbitraryTemplate length' = oneof [ do chunk <- chunk' - Chunk chunk <$> template' - , do key <- key' - Identifier key <$> template' - , EscapeCharacter <$> template' - ] - where - template' = arbitraryTemplate (length' - 1) - -- Generate keys. - key' = do l <- choose (5, 10) - replicateM l $ choose ('a', 'z') - -- Generate non-empty chunks. - chunk' = do string <- arbitrary - let sanitized = filter (/= '$') string - return $ if null sanitized then "foo" - else sanitized - --- | Make @Template@ testable. -instance Arbitrary Template where - arbitrary = choose (0, 20) >>= arbitraryTemplate - - shrink (Chunk chunk template) = [template, Chunk chunk End] - shrink (Identifier key template) = [template, Identifier key End] - shrink (EscapeCharacter template) = [template, EscapeCharacter End] - shrink End = [] -- cgit v1.2.3