on master help sign in
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.

commitc9e345808326c52de9e1a43b0364c0932115760d authorJasper Van der Jeugt <jaspervdj@gmail.com> dateFri 26 Mar 2010, 14:10 (17 years ago) parentc8dd9b7
8 files changed+60−47
.ghci+1 hakyll.cabal+1−1 src/Text/Hakyll/Internal/FileType.hs+3 src/Text/Hakyll/Internal/Page.hs+1 tests/CompressCss.hs+9−2 tests/Context.hs−37 tests/Main.hs+1−2 tests/Page.hs+44−5
.ghcinew file+1
@@ -0,0 +1 @@
1+:set -isrc -itests
hakyll.cabal+1−1
@@ -55,9 +55,9 @@ library
5555 Text.Hakyll.Util
5656 Text.Hakyll.Tags
5757 Text.Hakyll.Feed
58+ other-modules: Paths_hakyll
5859 Text.Hakyll.Internal.Cache
5960 Text.Hakyll.Internal.CompressCss
6061 Text.Hakyll.Internal.FileType
6162 Text.Hakyll.Internal.Page
6263 Text.Hakyll.Internal.Template
63− other-modules: Paths_hakyll
src/Text/Hakyll/Internal/FileType.hs+3
@@ -14,6 +14,7 @@ data FileType = Html
1414 | LiterateHaskellMarkdown
1515 | Markdown
1616 | ReStructuredText
17+ | Text
1718 | UnknownFileType
1819 deriving (Eq, Ord, Show, Read)
1920
@@ -33,6 +34,8 @@ getFileType = getFileType' . takeExtension
3334 getFileType' ".mkdwn" = Markdown
3435 getFileType' ".rst" = ReStructuredText
3536 getFileType' ".tex" = LaTeX
37+ getFileType' ".text" = Text
38+ getFileType' ".txt" = Text
3639 getFileType' _ = UnknownFileType
3740
3841-- | Check if a certain @FileType@ is renderable.
src/Text/Hakyll/Internal/Page.hs+1
@@ -38,6 +38,7 @@ writerOptions = defaultWriterOptions
3838-- | Get a render function for a given extension.
3939getRenderFunction :: FileType -> (String -> String)
4040getRenderFunction Html = id
41+getRenderFunction Text = id
4142getRenderFunction fileType = writeHtmlString writerOptions
4243 . readFunction fileType (readOptions fileType)
4344 where
tests/CompressCss.hs+9−2
@@ -1,3 +1,4 @@
1+-- | Module testing @Text.Hakyll.Internal.CompressCss@.
12module CompressCss
23 ( compressCssGroup
34 ) where
@@ -21,15 +22,21 @@ compressCssGroup = testGroup "CompressCss"
2122 , testCase "test_compressCss_4" test_compressCss_4
2223 ]
2324
24−-- Css compression should always decrease the text length.
25+-- | Css compression should always decrease the text length.
2526prop_compressCss_length str = length str >= length (compressCss str)
2627
27−-- Compress Css test cases.
28+-- | compressCss test case 1.
2829test_compressCss_1 = compressCss "a { \n color : red; }" @?= "a{color:red}"
30+
31+-- | compressCss test case 2.
2932test_compressCss_2 = compressCss "img {border :none;;;; }"
3033 @?= "img{border:none}"
34+
35+-- | compressCss test case 3.
3136test_compressCss_3 =
3237 compressCss "p {font-size : 90%;} h1 {color :white;;; }"
3338 @?= "p{font-size:90%}h1{color:white}"
39+
40+-- | compressCss test case 4.
3441test_compressCss_4 = compressCss "a { /* /* red is pretty cool */ color: red; }"
3542 @?= "a{color:red}"
tests/Context.hsdeleted−37
@@ -1,37 +0,0 @@
1−module Context
2− ( contextGroup
3− ) where
4−
5−import qualified Data.Map as M
6−
7−import Test.QuickCheck
8−import Test.Framework (testGroup)
9−import Test.Framework.Providers.HUnit
10−import Test.Framework.Providers.QuickCheck2
11−import Test.HUnit
12−
13−import Text.Hakyll.Context
14−
15−-- Context test group.
16−contextGroup = testGroup "Context"
17− [ testCase "test_renderDate_1" test_renderDate_1
18− , testCase "test_renderDate_2" test_renderDate_2
19− , testCase "test_changeExtension_1" test_changeExtension_1
20− ]
21−
22−-- Date rendering test cases.
23−test_renderDate_1 =
24− M.lookup "date" rendered @?= Just "December 30, 2009"
25− where
26− rendered = renderDate "date" "%B %e, %Y" "Unknown date"
27− (M.singleton "path" "2009-12-30-a-title.markdown")
28−
29−test_renderDate_2 = M.lookup "date" rendered @?= Just "Unknown date"
30− where
31− rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
32− M.singleton "path" "2009-badness-30-a-title.markdown"
33−
34−-- changeExtension test cases.
35−test_changeExtension_1 = M.lookup "url" rendered @?= Just "foo.php"
36− where
37− rendered = changeExtension "php" (M.singleton "url" "foo.html")
tests/Main.hs+1−2
@@ -5,15 +5,14 @@ import Test.Framework.Providers.HUnit
55import Test.Framework.Providers.QuickCheck2
66
77import CompressCss
8−import Context
98import File
109import Page
1110import Regex
1211import Template
1312import Util
1413
14+-- | Run all tests.
1515main = defaultMain [ compressCssGroup
16− , contextGroup
1716 , fileGroup
1817 , pageGroup
1918 , regexGroup
tests/Page.hs+44−5
@@ -4,19 +4,58 @@ module Page
44
55import qualified Data.Map as M
66
7+import Control.Monad.Reader (runReaderT)
78import Data.Binary
89import Test.Framework (testGroup)
910import Test.Framework.Providers.HUnit
1011import Test.Framework.Providers.QuickCheck2
1112import Test.HUnit
13+import System.Directory (getTemporaryDirectory, removeFile)
14+import System.FilePath ((</>))
1215
13−import Text.Hakyll.Page
16+import Text.Hakyll.Internal.Page
17+import Text.Hakyll.Context
18+import Text.Hakyll.HakyllAction
19+import Text.Hakyll
1420
1521-- Page test group.
1622pageGroup = testGroup "Page"
17− [ testProperty "prop_page_encode_id" prop_page_encode_id
23+ [ testCase "test_readPage_1" test_readPage_1
24+ , testCase "test_readPage_2" test_readPage_2
1825 ]
1926
20−-- Test encoding/decoding of pages.
21−prop_page_encode_id :: Page -> Bool
22−prop_page_encode_id page = decode (encode page) == page
27+-- | An abstract function to test page reading.
28+test_readPage :: FilePath -- ^ Filename to give to the temporary file.
29+ -> String -- ^ Content to put in the file.
30+ -> (Context -> Bool) -- ^ Assertion to run on the result Context.
31+ -> IO Bool -- ^ Result of the assertion.
32+test_readPage fileName content assertion = do
33+ temporaryDir <- getTemporaryDirectory
34+ let temporaryFile = temporaryDir </> fileName
35+ writeFile temporaryFile content
36+ page <- runReaderT (readPage temporaryFile) defaultHakyllConfiguration
37+ removeFile temporaryFile
38+ return $ assertion page
39+
40+-- | readPage test case 1.
41+test_readPage_1 = test_readPage fileName content assertion @? "test_readPage_1"
42+ where
43+ fileName = "test_readPage_1.markdown"
44+ content = unlines [ "---"
45+ , "author: Eric Cartman"
46+ , "---"
47+ , "This is a simple test."
48+ ]
49+ assertion page = M.lookup "author" page == Just "Eric Cartman"
50+
51+-- | readPage test case 2.
52+test_readPage_2 = test_readPage fileName content assertion @? "test_readPage_2"
53+ where
54+ fileName = "test_readPage_2.txt"
55+ content = unlines [ "--- someSection"
56+ , "This is a section."
57+ , "---"
58+ , "This is the body."
59+ ]
60+ assertion page = M.lookup "someSection" page == Just "This is a section.\n"
61+ && M.lookup "body" page == Just "This is the body.\n"