on fb71a21 help sign in
hakyll/tests/Tests.hs
106 lines 5.0 kB history raw
1import Test.Framework (defaultMain, testGroup)
2import Test.Framework.Providers.QuickCheck2
3import Test.Framework.Providers.HUnit
4import Test.QuickCheck
5import Test.HUnit
7import Data.Char
8import qualified Data.Map as M
9import qualified Data.ByteString.Lazy.Char8 as B
11import Text.Hakyll.CompressCSS
12import Text.Hakyll.Util
13import Text.Hakyll.Regex
14import Text.Hakyll.Context
15import Text.Hakyll.File
17main = defaultMain tests
19tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
20 , testProperty "trim id" prop_trim_id
21 , testProperty "trim empty" prop_trim_empty
22 , testCase "stripHTML 1" test_strip_html1
23 , testCase "stripHTML 2" test_strip_html2
24 , testCase "stripHTML 3" test_strip_html3
25 , testCase "link 1" test_link1
26 , testCase "link 2" test_link2
27 ]
29 , testGroup "Regex group" [ testCase "split 1" test_split1
30 , testCase "split 2" test_split2
31 ]
33 , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
34 , testCase "compressCSS 1" test_compress_css1
35 , testCase "compressCSS 2" test_compress_css2
36 , testCase "compressCSS 3" test_compress_css3
37 ]
39 , testGroup "Context group" [ testCase "renderDate 1" test_render_date1
40 , testCase "renderDate 2" test_render_date1
41 ]
43 , testGroup "File group" [ testProperty "havingExtension count" prop_having_extension_count
44 , testCase "havingExtension 1" test_having_extension1
45 , testCase "havingExtension 2" test_having_extension2
46 ]
47 ]
49-- Test that a string always becomes shorter when trimmed.
50prop_trim_length str = length str >= length (trim str)
52-- Check that a string which does not start or end with a space is not trimmed.
53prop_trim_id str = (not $ null str)
54 && (not $ isSpace $ head str)
55 && (not $ isSpace $ last str)
56 ==> str == (trim str)
58-- An string of only spaces should be reduced to an empty string.
59prop_trim_empty str = (all isSpace str) ==> null (trim str)
61-- Strip HTML test cases.
62test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
63test_strip_html2 = stripHTML "text" @?= "text"
64test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <img src=\"foo.png\" />" @?=
65 "Hakyll is an awesome web framework "
67-- Link test cases.
68test_link1 = link "foo bar" "/foo/bar.html" @?= "<a href=\"/foo/bar.html\">foo bar</a>"
69test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
71-- Split test cases.
72test_split1 = split "," "1,2,3" @?= ["1", "2", "3"]
73test_split2 = split "," ",1,2," @?= ["1", "2"]
75-- CSS compression should always decrease the text length.
76prop_compress_css_length str = length str >= length (compressCSS str)
78-- Compress CSS test cases.
79test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
80test_compress_css2 = compressCSS "img {border :none;;;; }" @?= "img{border:none}"
81test_compress_css3 = compressCSS "p {font-size : 90%;} h1 {color :white;;; }" @?= "p{font-size:90%}h1{color:white}"
83-- Date rendering test cases.
84test_render_date1 = M.lookup (B.pack "date") rendered @?= Just (B.pack "December 30, 2009")
85 where rendered = renderDate "date"
86 "%B %e, %Y"
87 "Unknown date"
88 (M.singleton (B.pack "path")
89 (B.pack "2009-12-30-a-title.markdown"))
90test_render_date2 = M.lookup (B.pack "date") rendered @?= Just (B.pack "Unknown date")
91 where rendered = renderDate "date"
92 "%B %e, %Y"
93 "Unknown date"
94 (M.singleton (B.pack "path")
95 (B.pack "2009-badness-30-a-title.markdown"))
97-- Add an extension, and test that they have that extension
98prop_having_extension_count names extension =
99 not (any ('.' `elem`) names || any (`elem` extension) "./\\")
100 ==> havingExtension fullExtension withExtensions == withExtensions
101 where fullExtension = '.' : extension
102 withExtensions = map (++ fullExtension) names
104-- Having extension test cases
105test_having_extension1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
106test_having_extension2 = havingExtension ".foo" ["file.foo", "file.txt"] @?= ["file.foo"]