@@ -1,92 +0,0 @@
1−module Page
2− ( pageGroup
3− ) where
4−
5−import qualified Data.Map as M
6−
7−import Control.Monad.Reader (runReaderT)
8−import Data.Binary
9−import Test.Framework (testGroup)
10−import Test.Framework.Providers.HUnit
11−import Test.Framework.Providers.QuickCheck2
12−import Test.HUnit
13−import System.Directory (getTemporaryDirectory, removeFile)
14−import System.FilePath ((</>))
15−
16−import Text.Hakyll.Page
17−import Text.Hakyll.Pandoc
18−import Text.Hakyll.Context
19−import Text.Hakyll.HakyllAction
20−import Text.Hakyll
21−
22−-- Page test group.
23−pageGroup = testGroup "Page"
24− [ testCase "test_readPage_1" test_readPage_1
25− , testCase "test_readPage_2" test_readPage_2
26− , testCase "test_readPage_3" test_readPage_3
27− , testCase "test_readPage_4" test_readPage_4
28− ]
29−
30−-- | An abstract function to test page reading.
31−test_readPage :: FilePath -- ^ Filename to give to the temporary file.
32− -> String -- ^ Content to put in the file.
33− -> (Context -> Bool) -- ^ Assertion to run on the result Context.
34− -> IO Bool -- ^ Result of the assertion.
35−test_readPage fileName content assertion = do
36− temporaryDir <- getTemporaryDirectory
37− let temporaryFile = temporaryDir </> fileName
38− writeFile temporaryFile content
39− page <- runDefaultHakyll (runHakyllAction $ createPage temporaryFile)
40− removeFile temporaryFile
41− return $ assertion page
42−
43−-- | readPage test case 1.
44−test_readPage_1 = test_readPage fileName content assertion @? "test_readPage_1"
45− where
46− fileName = "test_readPage_1.markdown"
47− content = unlines [ "---"
48− , "author: Eric Cartman"
49− , "---"
50− , "This is a simple test."
51− ]
52− assertion page = M.lookup "author" (unContext page) == Just "Eric Cartman"
53−
54−-- | readPage test case 2.
55−test_readPage_2 = test_readPage fileName content assertion @? "test_readPage_2"
56− where
57− fileName = "test_readPage_2.txt"
58− content = unlines [ "--- someSection"
59− , "This is a section."
60− , "---"
61− , "This is the body."
62− ]
63− assertion page =
64− let m = unContext page
65− in M.lookup "someSection" m == Just "This is a section.\n"
66− && M.lookup "body" m == Just "This is the body.\n"
67−
68−-- | readPage test case 3.
69−test_readPage_3 = test_readPage fileName content assertion @? "test_readPage_3"
70− where
71− fileName = "test_readPage_3.txt"
72− content = unlines [ "No metadata here, sorry."
73− ]
74− assertion page =
75− M.lookup "body" (unContext page) == Just "No metadata here, sorry.\n"
76−
77−-- | readPage test case 4.
78−test_readPage_4 = test_readPage fileName content assertion @? "test_readPage_4"
79− where
80− fileName = "test_readPage_4.txt"
81− content = unlines [ "--- section"
82− , "This is a section."
83− , "---"
84− , "Header"
85− , "------"
86− , "The header is not a separate section."
87− ]
88− assertion page = M.lookup "body" (unContext page) == Just body
89− body = unlines [ "Header"
90− , "------"
91− , "The header is not a separate section."
92− ]