Added .txt
support, tests update.
- Pure text files are now supported. - We now hide the Internal modules. - Tests should be run through ghci. - Added testing of page reading.
This commit is contained in:
parent
c8dd9b7f74
commit
c9e3458083
8 changed files with 60 additions and 47 deletions
1
.ghci
Normal file
1
.ghci
Normal file
|
@ -0,0 +1 @@
|
|||
:set -isrc -itests
|
|
@ -55,9 +55,9 @@ library
|
|||
Text.Hakyll.Util
|
||||
Text.Hakyll.Tags
|
||||
Text.Hakyll.Feed
|
||||
other-modules: Paths_hakyll
|
||||
Text.Hakyll.Internal.Cache
|
||||
Text.Hakyll.Internal.CompressCss
|
||||
Text.Hakyll.Internal.FileType
|
||||
Text.Hakyll.Internal.Page
|
||||
Text.Hakyll.Internal.Template
|
||||
other-modules: Paths_hakyll
|
||||
|
|
|
@ -14,6 +14,7 @@ data FileType = Html
|
|||
| LiterateHaskellMarkdown
|
||||
| Markdown
|
||||
| ReStructuredText
|
||||
| Text
|
||||
| UnknownFileType
|
||||
deriving (Eq, Ord, Show, Read)
|
||||
|
||||
|
@ -33,6 +34,8 @@ getFileType = getFileType' . takeExtension
|
|||
getFileType' ".mkdwn" = Markdown
|
||||
getFileType' ".rst" = ReStructuredText
|
||||
getFileType' ".tex" = LaTeX
|
||||
getFileType' ".text" = Text
|
||||
getFileType' ".txt" = Text
|
||||
getFileType' _ = UnknownFileType
|
||||
|
||||
-- | Check if a certain @FileType@ is renderable.
|
||||
|
|
|
@ -38,6 +38,7 @@ writerOptions = defaultWriterOptions
|
|||
-- | Get a render function for a given extension.
|
||||
getRenderFunction :: FileType -> (String -> String)
|
||||
getRenderFunction Html = id
|
||||
getRenderFunction Text = id
|
||||
getRenderFunction fileType = writeHtmlString writerOptions
|
||||
. readFunction fileType (readOptions fileType)
|
||||
where
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
-- | Module testing @Text.Hakyll.Internal.CompressCss@.
|
||||
module CompressCss
|
||||
( compressCssGroup
|
||||
) where
|
||||
|
@ -21,15 +22,21 @@ compressCssGroup = testGroup "CompressCss"
|
|||
, testCase "test_compressCss_4" test_compressCss_4
|
||||
]
|
||||
|
||||
-- Css compression should always decrease the text length.
|
||||
-- | Css compression should always decrease the text length.
|
||||
prop_compressCss_length str = length str >= length (compressCss str)
|
||||
|
||||
-- Compress Css test cases.
|
||||
-- | compressCss test case 1.
|
||||
test_compressCss_1 = compressCss "a { \n color : red; }" @?= "a{color:red}"
|
||||
|
||||
-- | compressCss test case 2.
|
||||
test_compressCss_2 = compressCss "img {border :none;;;; }"
|
||||
@?= "img{border:none}"
|
||||
|
||||
-- | compressCss test case 3.
|
||||
test_compressCss_3 =
|
||||
compressCss "p {font-size : 90%;} h1 {color :white;;; }"
|
||||
@?= "p{font-size:90%}h1{color:white}"
|
||||
|
||||
-- | compressCss test case 4.
|
||||
test_compressCss_4 = compressCss "a { /* /* red is pretty cool */ color: red; }"
|
||||
@?= "a{color:red}"
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
module Context
|
||||
( contextGroup
|
||||
) where
|
||||
|
||||
import qualified Data.Map as M
|
||||
|
||||
import Test.QuickCheck
|
||||
import Test.Framework (testGroup)
|
||||
import Test.Framework.Providers.HUnit
|
||||
import Test.Framework.Providers.QuickCheck2
|
||||
import Test.HUnit
|
||||
|
||||
import Text.Hakyll.Context
|
||||
|
||||
-- Context test group.
|
||||
contextGroup = testGroup "Context"
|
||||
[ testCase "test_renderDate_1" test_renderDate_1
|
||||
, testCase "test_renderDate_2" test_renderDate_2
|
||||
, testCase "test_changeExtension_1" test_changeExtension_1
|
||||
]
|
||||
|
||||
-- Date rendering test cases.
|
||||
test_renderDate_1 =
|
||||
M.lookup "date" rendered @?= Just "December 30, 2009"
|
||||
where
|
||||
rendered = renderDate "date" "%B %e, %Y" "Unknown date"
|
||||
(M.singleton "path" "2009-12-30-a-title.markdown")
|
||||
|
||||
test_renderDate_2 = M.lookup "date" rendered @?= Just "Unknown date"
|
||||
where
|
||||
rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
|
||||
M.singleton "path" "2009-badness-30-a-title.markdown"
|
||||
|
||||
-- changeExtension test cases.
|
||||
test_changeExtension_1 = M.lookup "url" rendered @?= Just "foo.php"
|
||||
where
|
||||
rendered = changeExtension "php" (M.singleton "url" "foo.html")
|
|
@ -5,15 +5,14 @@ import Test.Framework.Providers.HUnit
|
|||
import Test.Framework.Providers.QuickCheck2
|
||||
|
||||
import CompressCss
|
||||
import Context
|
||||
import File
|
||||
import Page
|
||||
import Regex
|
||||
import Template
|
||||
import Util
|
||||
|
||||
-- | Run all tests.
|
||||
main = defaultMain [ compressCssGroup
|
||||
, contextGroup
|
||||
, fileGroup
|
||||
, pageGroup
|
||||
, regexGroup
|
||||
|
|
|
@ -4,19 +4,58 @@ module Page
|
|||
|
||||
import qualified Data.Map as M
|
||||
|
||||
import Control.Monad.Reader (runReaderT)
|
||||
import Data.Binary
|
||||
import Test.Framework (testGroup)
|
||||
import Test.Framework.Providers.HUnit
|
||||
import Test.Framework.Providers.QuickCheck2
|
||||
import Test.HUnit
|
||||
import System.Directory (getTemporaryDirectory, removeFile)
|
||||
import System.FilePath ((</>))
|
||||
|
||||
import Text.Hakyll.Page
|
||||
import Text.Hakyll.Internal.Page
|
||||
import Text.Hakyll.Context
|
||||
import Text.Hakyll.HakyllAction
|
||||
import Text.Hakyll
|
||||
|
||||
-- Page test group.
|
||||
pageGroup = testGroup "Page"
|
||||
[ testProperty "prop_page_encode_id" prop_page_encode_id
|
||||
[ testCase "test_readPage_1" test_readPage_1
|
||||
, testCase "test_readPage_2" test_readPage_2
|
||||
]
|
||||
|
||||
-- Test encoding/decoding of pages.
|
||||
prop_page_encode_id :: Page -> Bool
|
||||
prop_page_encode_id page = decode (encode page) == page
|
||||
-- | An abstract function to test page reading.
|
||||
test_readPage :: FilePath -- ^ Filename to give to the temporary file.
|
||||
-> String -- ^ Content to put in the file.
|
||||
-> (Context -> Bool) -- ^ Assertion to run on the result Context.
|
||||
-> IO Bool -- ^ Result of the assertion.
|
||||
test_readPage fileName content assertion = do
|
||||
temporaryDir <- getTemporaryDirectory
|
||||
let temporaryFile = temporaryDir </> fileName
|
||||
writeFile temporaryFile content
|
||||
page <- runReaderT (readPage temporaryFile) defaultHakyllConfiguration
|
||||
removeFile temporaryFile
|
||||
return $ assertion page
|
||||
|
||||
-- | readPage test case 1.
|
||||
test_readPage_1 = test_readPage fileName content assertion @? "test_readPage_1"
|
||||
where
|
||||
fileName = "test_readPage_1.markdown"
|
||||
content = unlines [ "---"
|
||||
, "author: Eric Cartman"
|
||||
, "---"
|
||||
, "This is a simple test."
|
||||
]
|
||||
assertion page = M.lookup "author" page == Just "Eric Cartman"
|
||||
|
||||
-- | readPage test case 2.
|
||||
test_readPage_2 = test_readPage fileName content assertion @? "test_readPage_2"
|
||||
where
|
||||
fileName = "test_readPage_2.txt"
|
||||
content = unlines [ "--- someSection"
|
||||
, "This is a section."
|
||||
, "---"
|
||||
, "This is the body."
|
||||
]
|
||||
assertion page = M.lookup "someSection" page == Just "This is a section.\n"
|
||||
&& M.lookup "body" page == Just "This is the body.\n"
|
||||
|
|
Loading…
Reference in a new issue