@@ -6,7 +6,6 @@ import Test.HUnit
7import Data.Char
7import Data.Char
8import qualified Data.Map as M
8import qualified Data.Map as M
9−import qualified Data.ByteString.Lazy.Char8 as B
11import Text.Hakyll.CompressCSS
10import Text.Hakyll.CompressCSS
12import Text.Hakyll.Util
11import Text.Hakyll.Util
@@ -16,37 +15,47 @@ import Text.Hakyll.File
17main = defaultMain tests
16main = defaultMain tests
18+tests = [ testGroup "Util group"
19−tests = [ testGroup "Util group" [ testProperty "trim length" prop_trim_length
19+ [ testProperty "trim length" prop_trim_length
20− , testProperty "trim id" prop_trim_id
20+ , testProperty "trim id" prop_trim_id
21− , testProperty "trim empty" prop_trim_empty
21+ , testProperty "trim empty" prop_trim_empty
22− , testCase "stripHTML 1" test_strip_html1
22+ , testCase "stripHTML 1" test_strip_html1
23− , testCase "stripHTML 2" test_strip_html2
23+ , testCase "stripHTML 2" test_strip_html2
24− , testCase "stripHTML 3" test_strip_html3
24+ , testCase "stripHTML 3" test_strip_html3
25− , testCase "link 1" test_link1
25+ , testCase "link 1" test_link1
26− , testCase "link 2" test_link2
26+ , testCase "link 2" test_link2
29+ , testGroup "Regex group"
29− , testGroup "Regex group" [ testCase "splitRegex 1" test_split_regex1
30+ [ testCase "splitRegex 1" test_split_regex1
30− , testCase "splitRegex 2" test_split_regex2
31+ , testCase "splitRegex 2" test_split_regex2
34+ , testGroup "CompressCSS group"
33− , testGroup "CompressCSS group" [ testProperty "compressCSS length" prop_compress_css_length
35+ [ testProperty "compressCSS length" prop_compress_css_length
34− , testCase "compressCSS 1" test_compress_css1
36+ , testCase "compressCSS 1" test_compress_css1
35− , testCase "compressCSS 2" test_compress_css2
37+ , testCase "compressCSS 2" test_compress_css2
36− , testCase "compressCSS 3" test_compress_css3
38+ , testCase "compressCSS 3" test_compress_css3
41+ , testGroup "Context group"
39− , testGroup "Context group" [ testCase "renderDate 1" test_render_date1
42+ [ testCase "renderDate 1" test_render_date1
40− , testCase "renderDate 2" test_render_date1
43+ , testCase "renderDate 2" test_render_date1
46+ , testGroup "File group"
47+ [ testCase "toDestination 1" test_to_destination1
48+ , testCase "toDestination 2" test_to_destination2
49+ , testCase "toDestination 3" test_to_destination3
43− , testGroup "File group" [ testCase "toRoot 1" test_to_root1
50+ , testCase "toRoot 1" test_to_root1
44− , testCase "toRoot 2" test_to_root2
51+ , testCase "toRoot 2" test_to_root2
45− , testCase "toRoot 3" test_to_root3
52+ , testCase "toRoot 3" test_to_root3
53+ , testCase "removeSpaces 1" test_remove_spaces1
54+ , testCase "removeSpaces 2" test_remove_spaces2
46− , testProperty "havingExtension count" prop_having_extension_count
55+ , testProperty "havingExtension count" prop_having_extension_count
47− , testCase "havingExtension 1" test_having_extension1
56+ , testCase "havingExtension 1" test_having_extension1
48− , testCase "havingExtension 2" test_having_extension2
57+ , testCase "havingExtension 2" test_having_extension2
52-- Test that a string always becomes shorter when trimmed.
61-- Test that a string always becomes shorter when trimmed.
@@ -64,50 +73,71 @@ prop_trim_empty str = (all isSpace str) ==> null (trim str)
64-- Strip HTML test cases.
73-- Strip HTML test cases.
65test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
74test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
66test_strip_html2 = stripHTML "text" @?= "text"
75test_strip_html2 = stripHTML "text" @?= "text"
67−test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <img src=\"foo.png\" />" @?=
77+ stripHTML "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
68− "Hakyll is an awesome web framework "
78+ @?= "Hakyll, a website generator"
70-- Link test cases.
80-- Link test cases.
71−test_link1 = link "foo bar" "/foo/bar.html" @?= "<a href=\"/foo/bar.html\">foo bar</a>"
81+test_link1 = link "foo bar" "/foo/bar.html"
82+ @?= "<a href=\"/foo/bar.html\">foo bar</a>"
72test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
83test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
74-- Split Regex test cases.
85-- Split Regex test cases.
75−test_split_regex1 = split "," "1,2,3" @?= ["1", "2", "3"]
86+test_split_regex1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
76−test_split_regex2 = split "," ",1,2," @?= ["1", "2"]
87+test_split_regex2 = splitRegex "," ",1,2," @?= ["1", "2"]
78-- CSS compression should always decrease the text length.
89-- CSS compression should always decrease the text length.
79prop_compress_css_length str = length str >= length (compressCSS str)
90prop_compress_css_length str = length str >= length (compressCSS str)
81-- Compress CSS test cases.
92-- Compress CSS test cases.
82test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
93test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
83−test_compress_css2 = compressCSS "img {border :none;;;; }" @?= "img{border:none}"
94+test_compress_css2 = compressCSS "img {border :none;;;; }"
95+ @?= "img{border:none}"
84−test_compress_css3 = compressCSS "p {font-size : 90%;} h1 {color :white;;; }" @?= "p{font-size:90%}h1{color:white}"
97+ compressCSS "p {font-size : 90%;} h1 {color :white;;; }"
98+ @?= "p{font-size:90%}h1{color:white}"
86-- Date rendering test cases.
100-- Date rendering test cases.
87−test_render_date1 = M.lookup (B.pack "date") rendered @?= Just (B.pack "December 30, 2009")
102+ M.lookup "date" rendered @?= Just "December 30, 2009"
88− where rendered = renderDate "date"
104+ rendered = renderDate "date" "%B %e, %Y" "Unknown date"
91− (M.singleton (B.pack "path")
92− (B.pack "2009-12-30-a-title.markdown"))
105+ (M.singleton "path" "2009-12-30-a-title.markdown")
93−test_render_date2 = M.lookup (B.pack "date") rendered @?= Just (B.pack "Unknown date")
107+test_render_date2 = M.lookup "date" rendered @?= Just "Unknown date"
94− where rendered = renderDate "date"
109+ rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
97− (M.singleton (B.pack "path")
98− (B.pack "2009-badness-30-a-title.markdown"))
110+ M.singleton "path" "2009-badness-30-a-title.markdown"
112+-- toDestination test cases
113+test_to_destination1 = toDestination "/posts/foo.html"
114+ @?= "_site/posts/foo.html"
116+test_to_destination2 = toDestination "$root/posts/foo.html"
117+ @?= "_site/posts/foo.html"
119+test_to_destination3 = toDestination "foo.html" @?= "_site/foo.html"
99-- toRoot test cases
121-- toRoot test cases
100test_to_root1 = toRoot "/posts/foo.html" @?= ".."
122test_to_root1 = toRoot "/posts/foo.html" @?= ".."
101test_to_root2 = toRoot "posts/foo.html" @?= ".."
123test_to_root2 = toRoot "posts/foo.html" @?= ".."
102test_to_root3 = toRoot "foo.html" @?= "."
124test_to_root3 = toRoot "foo.html" @?= "."
126+-- removeSpaces test cases
127+test_remove_spaces1 = removeSpaces "$root/tags/random crap.html"
128+ @?= "$root/tags/random-crap.html"
129+test_remove_spaces2 = removeSpaces "another simple example.zip"
130+ @?= "another-simple-example.zip"
104-- Add an extension, and test that they have that extension
132-- Add an extension, and test that they have that extension
105prop_having_extension_count names extension =
133prop_having_extension_count names extension =
106 not (any ('.' `elem`) names || any (`elem` extension) "./\\")
134 not (any ('.' `elem`) names || any (`elem` extension) "./\\")
107 ==> havingExtension fullExtension withExtensions == withExtensions
135 ==> havingExtension fullExtension withExtensions == withExtensions
108− where fullExtension = '.' : extension
137+ fullExtension = '.' : extension
109− withExtensions = map (++ fullExtension) names
138+ withExtensions = map (++ fullExtension) names
111-- Having extension test cases
140-- Having extension test cases
112test_having_extension1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
141test_having_extension1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
113−test_having_extension2 = havingExtension ".foo" ["file.foo", "file.txt"] @?= ["file.foo"]
142+test_having_extension2 = havingExtension ".foo" ["file.foo", "file.txt"]