diff options
author | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-26 14:10:10 +0100 |
---|---|---|
committer | Jasper Van der Jeugt <jaspervdj@gmail.com> | 2010-03-26 14:10:10 +0100 |
commit | c9e345808326c52de9e1a43b0364c0932115760d (patch) | |
tree | bf193f53a9a177dfbdc5673805a6e8fb5bd4fe26 /tests | |
parent | c8dd9b7f74affe979d5bf988a041711672471537 (diff) | |
download | hakyll-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.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CompressCss.hs | 11 | ||||
-rw-r--r-- | tests/Context.hs | 37 | ||||
-rw-r--r-- | tests/Main.hs | 3 | ||||
-rw-r--r-- | tests/Page.hs | 49 |
4 files changed, 54 insertions, 46 deletions
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" |