summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-26 14:10:10 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2010-03-26 14:10:10 +0100
commitc9e345808326c52de9e1a43b0364c0932115760d (patch)
treebf193f53a9a177dfbdc5673805a6e8fb5bd4fe26
parentc8dd9b7f74affe979d5bf988a041711672471537 (diff)
downloadhakyll-c9e345808326c52de9e1a43b0364c0932115760d.tar.gz
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.
-rw-r--r--.ghci1
-rw-r--r--hakyll.cabal2
-rw-r--r--src/Text/Hakyll/Internal/FileType.hs3
-rw-r--r--src/Text/Hakyll/Internal/Page.hs1
-rw-r--r--tests/CompressCss.hs11
-rw-r--r--tests/Context.hs37
-rw-r--r--tests/Main.hs3
-rw-r--r--tests/Page.hs49
8 files changed, 60 insertions, 47 deletions
diff --git a/.ghci b/.ghci
new file mode 100644
index 0000000..17b7559
--- /dev/null
+++ b/.ghci
@@ -0,0 +1 @@
+:set -isrc -itests
diff --git a/hakyll.cabal b/hakyll.cabal
index c4e7a3c..1e0bdd3 100644
--- a/hakyll.cabal
+++ b/hakyll.cabal
@@ -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
diff --git a/src/Text/Hakyll/Internal/FileType.hs b/src/Text/Hakyll/Internal/FileType.hs
index e3a73cd..e762e9a 100644
--- a/src/Text/Hakyll/Internal/FileType.hs
+++ b/src/Text/Hakyll/Internal/FileType.hs
@@ -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.
diff --git a/src/Text/Hakyll/Internal/Page.hs b/src/Text/Hakyll/Internal/Page.hs
index 8500693..8f1b9d6 100644
--- a/src/Text/Hakyll/Internal/Page.hs
+++ b/src/Text/Hakyll/Internal/Page.hs
@@ -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
diff --git a/tests/CompressCss.hs b/tests/CompressCss.hs
index 38b9b28..164df59 100644
--- a/tests/CompressCss.hs
+++ b/tests/CompressCss.hs
@@ -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}"
diff --git a/tests/Context.hs b/tests/Context.hs
deleted file mode 100644
index d8d0504..0000000
--- a/tests/Context.hs
+++ /dev/null
@@ -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")
diff --git a/tests/Main.hs b/tests/Main.hs
index a2fc8e5..2c2717a 100644
--- a/tests/Main.hs
+++ b/tests/Main.hs
@@ -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
diff --git a/tests/Page.hs b/tests/Page.hs
index 705b6ba..1eb8e86 100644
--- a/tests/Page.hs
+++ b/tests/Page.hs
@@ -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"