on master help sign in
Remove old tests for now
commiteabc26812d5deb6ef818c20b2ed4c4d07e14feaa authorJasper Van der Jeugt <jaspervdj@gmail.com> dateThu 23 Dec 2010, 14:32 (16 years ago) parentad67121
7 files changed−366
tests/CompressCss.hs−42 tests/File.hs−62 tests/Main.hs−22 tests/Page.hs−92 tests/Regex.hs−24 tests/Template.hs−70 tests/Util.hs−54
tests/CompressCss.hsdeleted−42
@@ -1,42 +0,0 @@
1−-- | Module testing @Text.Hakyll.Internal.CompressCss@.
2−module CompressCss
3− ( compressCssGroup
4− ) where
5−
6−import qualified Data.Map as M
7−
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−
14−import Text.Hakyll.Internal.CompressCss
15−
16−-- CompressCss test group.
17−compressCssGroup = testGroup "CompressCss"
18− [ testProperty "prop_compressCss_length" prop_compressCss_length
19− , testCase "test_compressCss_1" test_compressCss_1
20− , testCase "test_compressCss_2" test_compressCss_2
21− , testCase "test_compressCss_3" test_compressCss_3
22− , testCase "test_compressCss_4" test_compressCss_4
23− ]
24−
25−-- | Css compression should always decrease the text length.
26−prop_compressCss_length str = length str >= length (compressCss str)
27−
28−-- | compressCss test case 1.
29−test_compressCss_1 = compressCss "a { \n color : red; }" @?= "a{color:red}"
30−
31−-- | compressCss test case 2.
32−test_compressCss_2 = compressCss "img {border :none;;;; }"
33− @?= "img{border:none}"
34−
35−-- | compressCss test case 3.
36−test_compressCss_3 =
37− compressCss "p {font-size : 90%;} h1 {color :white;;; }"
38− @?= "p{font-size:90%}h1{color:white}"
39−
40−-- | compressCss test case 4.
41−test_compressCss_4 = compressCss "a { /* /* red is pretty cool */ color: red; }"
42− @?= "a{color:red}"
tests/File.hsdeleted−62
@@ -1,62 +0,0 @@
1−module File
2− ( fileGroup
3− ) where
4−
5−import qualified Data.Map as M
6−
7−import Control.Applicative ((<$>))
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 Test.QuickCheck
14−
15−import Text.Hakyll (runDefaultHakyll)
16−import Text.Hakyll.File
17−
18−-- File test group.
19−fileGroup = testGroup "File"
20− [ testCase "test_toRoot_1" test_toRoot_1
21− , testCase "test_toRoot_2" test_toRoot_2
22− , testCase "test_toRoot_3" test_toRoot_3
23− , testCase "test_inHakyllDirectory_1" test_inHakyllDirectory_1
24− , testCase "test_inHakyllDirectory_2" test_inHakyllDirectory_2
25− , testCase "test_inHakyllDirectory_3" test_inHakyllDirectory_3
26− , testCase "test_inHakyllDirectory_4" test_inHakyllDirectory_4
27− , testCase "test_removeSpaces_1" test_removeSpaces_1
28− , testCase "test_removeSpaces_2" test_removeSpaces_2
29− , testCase "test_havingExtension_1" test_havingExtension_1
30− , testCase "test_havingExtension_2" test_havingExtension_2
31− ]
32−
33−
34−-- toRoot test cases
35−test_toRoot_1 = toRoot "/posts/foo.html" @?= ".."
36−test_toRoot_2 = toRoot "posts/foo.html" @?= ".."
37−test_toRoot_3 = toRoot "foo.html" @?= "."
38−
39−-- inHakyllDirectory test cases
40−test_inHakyllDirectory_1 =
41− (runDefaultHakyll $ inHakyllDirectory "_site/foo.html")
42− @? "test_inHakyllDirectory_1"
43−test_inHakyllDirectory_2 =
44− (not <$> (runDefaultHakyll $ inHakyllDirectory "posts/foo.html"))
45− @? "test_inHakyllDirectory_2"
46−test_inHakyllDirectory_3 =
47− (not <$> (runDefaultHakyll $ inHakyllDirectory "index.html"))
48− @? "test_inHakyllDirectory_3"
49−test_inHakyllDirectory_4 =
50− (runDefaultHakyll $ inHakyllDirectory "_cache/index.html")
51− @? "test_inHakyllDirectory_4"
52−
53−-- removeSpaces test cases
54−test_removeSpaces_1 = removeSpaces "$root/tags/random crap.html"
55− @?= "$root/tags/random-crap.html"
56−test_removeSpaces_2 = removeSpaces "another simple example.zip"
57− @?= "another-simple-example.zip"
58−
59−-- Having extension test cases
60−test_havingExtension_1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
61−test_havingExtension_2 = havingExtension ".foo" ["file.foo", "file.txt"]
62− @?= ["file.foo"]
tests/Main.hsdeleted−22
@@ -1,22 +0,0 @@
1−module Main where
2−
3−import Test.Framework (defaultMain, testGroup)
4−import Test.Framework.Providers.HUnit
5−import Test.Framework.Providers.QuickCheck2
6−
7−import CompressCss
8−import File
9−import Page
10−import Regex
11−import Template
12−import Util
13−
14−-- | Run all tests.
15−main :: IO ()
16−main = defaultMain [ compressCssGroup
17− , fileGroup
18− , pageGroup
19− , regexGroup
20− , templateGroup
21− , utilGroup
22− ]
tests/Page.hsdeleted−92
@@ -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− ]
tests/Regex.hsdeleted−24
@@ -1,24 +0,0 @@
1−module Regex
2− ( regexGroup
3− ) where
4−
5−import qualified Data.Map as M
6−
7−import Data.Binary
8−import Test.Framework (testGroup)
9−import Test.Framework.Providers.HUnit
10−import Test.Framework.Providers.QuickCheck2
11−import Test.HUnit
12−import Test.QuickCheck
13−
14−import Text.Hakyll.Regex
15−
16−-- Regex test group.
17−regexGroup = testGroup "Regex"
18− [ testCase "test_splitRegex_1" test_splitRegex_1
19− , testCase "test_splitRegex_2" test_splitRegex_2
20− ]
21−
22−-- Split Regex test cases.
23−test_splitRegex_1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
24−test_splitRegex_2 = splitRegex "," ",1,2," @?= ["1", "2"]
tests/Template.hsdeleted−70
@@ -1,70 +0,0 @@
1−module Template
2− ( templateGroup
3− ) where
4−
5−import qualified Data.Map as M
6−import Control.Applicative ((<$>))
7−import Control.Monad (replicateM)
8−import Data.Monoid (mempty)
9−
10−import Data.Binary
11−import Test.Framework (testGroup)
12−import Test.Framework.Providers.HUnit
13−import Test.Framework.Providers.QuickCheck2
14−import Test.HUnit
15−import Test.QuickCheck
16−
17−import Text.Hakyll.Context (Context (..))
18−import Text.Hakyll.Internal.Template
19−import Text.Hakyll.Internal.Template.Template
20−
21−-- Template test group.
22−templateGroup = testGroup "Template"
23− [ testProperty "prop_template_encode_id" prop_template_encode_id
24− , testProperty "prop_substitute_id" prop_substitute_id
25− , testCase "test_substitute_1" test_substitute_1
26− , testCase "test_substitute_2" test_substitute_2
27− ]
28−
29−-- | Generate arbitrary templates from a given length.
30−--
31−instance Arbitrary TemplateElement where
32− arbitrary = oneof
33− -- Random chunk
34− [ Chunk <$> do
35− string <- arbitrary
36− let sanitized = filter (/= '$') string
37− return $ if null sanitized then "foo" else sanitized
38− -- Random identifier
39− , fmap Identifier $
40− choose (5, 10) >>= flip replicateM (choose ('a', 'z'))
41− -- Escape character
42− , return EscapeCharacter
43− ]
44−
45−-- | Make @Template@ testable.
46−instance Arbitrary Template where
47− arbitrary = Template <$> arbitrary
48− shrink = map Template . shrink . unTemplate
49−
50−-- Test encoding/decoding of templates.
51−prop_template_encode_id :: Template -> Bool
52−prop_template_encode_id template = decode (encode template) == template
53−
54−-- Check we get the same sting with empty substitutions.
55−prop_substitute_id string =
56− regularSubstitute (fromString string) mempty == string
57−
58−-- substitute test case 1.
59−test_substitute_1 =
60− finalSubstitute template context @?= "Banana costs $4."
61− where
62− template = fromString "$product costs $$$price."
63− context = Context $ M.fromList [("product", "Banana"), ("price", "4")]
64−
65−-- substitute test case 2.
66−test_substitute_2 =
67− regularSubstitute template context @?= "$$root is a special key."
68− where
69− template = fromString "$$root is a special $thing."
70− context = Context $ M.fromList [("root", "foo"), ("thing", "key")]
tests/Util.hsdeleted−54
@@ -1,54 +0,0 @@
1−module Util
2− ( utilGroup
3− ) where
4−
5−import Data.Char
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.Util
14−
15−-- Util test group.
16−utilGroup = testGroup "Util"
17− [ testProperty "prop_trim_length" prop_trim_length
18− , testProperty "prop_trim_id" prop_trim_id
19− , testProperty "prop_stripHtml_length" prop_stripHtml_length
20− , testProperty "prop_stripHtml_id" prop_stripHtml_id
21− , testCase "test_stripHtml_1" test_stripHtml_1
22− , testCase "test_stripHtml_2" test_stripHtml_2
23− , testCase "test_stripHtml_3" test_stripHtml_3
24− , testCase "test_link_1" test_link_1
25− , testCase "test_link_2" test_link_2
26− ]
27−
28−-- Test that a string always becomes shorter when trimmed.
29−prop_trim_length str = length str >= length (trim str)
30−
31−-- Check that a string which does not start or end with a space is not trimmed.
32−prop_trim_id str = (not $ null str) && isAlreadyTrimmed ==> str == (trim str)
33− where
34− isAlreadyTrimmed :: Bool
35− isAlreadyTrimmed = (not $ isSpace $ head str) && (not $ isSpace $ last str)
36−
37−-- Check that a stripped string is shorter.
38−prop_stripHtml_length str = length str >= length (stripHtml str)
39−
40−-- Check that strings without tags remain untouched.
41−prop_stripHtml_id str = (not $ any (`elem` ['>', '<']) str)
42− ==> str == stripHtml str
43−
44−-- Strip Html test cases.
45−test_stripHtml_1 = stripHtml "<b>text</b>" @?= "text"
46−test_stripHtml_2 = stripHtml "text" @?= "text"
47−test_stripHtml_3 =
48− stripHtml "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
49− @?= "Hakyll, a website generator"
50−
51−-- Link test cases.
52−test_link_1 = link "foo bar" "/foo/bar.html"
53− @?= "<a href=\"/foo/bar.html\">foo bar</a>"
54−test_link_2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"