@@ -6,7 +6,6 @@ import Test.HUnit
66
77import Data.Char
88import qualified Data.Map as M
9−import qualified Data.ByteString.Lazy.Char8 as B
109
1110import Text.Hakyll.CompressCSS
1211import Text.Hakyll.Util
@@ -16,37 +15,47 @@ import Text.Hakyll.File
1615
1716main = defaultMain tests
1817
19−tests = [ 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− ]
28−
29− , testGroup "Regex group" [ testCase "splitRegex 1" test_split_regex1
30− , testCase "splitRegex 2" test_split_regex2
31− ]
32−
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− ]
38−
39− , testGroup "Context group" [ testCase "renderDate 1" test_render_date1
40− , testCase "renderDate 2" test_render_date1
41− ]
42−
43− , testGroup "File group" [ testCase "toRoot 1" test_to_root1
44− , testCase "toRoot 2" test_to_root2
45− , testCase "toRoot 3" test_to_root3
46− , testProperty "havingExtension count" prop_having_extension_count
47− , testCase "havingExtension 1" test_having_extension1
48− , testCase "havingExtension 2" test_having_extension2
49− ]
18+tests = [ testGroup "Util group"
19+ [ 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+ ]
28+
29+ , testGroup "Regex group"
30+ [ testCase "splitRegex 1" test_split_regex1
31+ , testCase "splitRegex 2" test_split_regex2
32+ ]
33+
34+ , testGroup "CompressCSS group"
35+ [ testProperty "compressCSS length" prop_compress_css_length
36+ , testCase "compressCSS 1" test_compress_css1
37+ , testCase "compressCSS 2" test_compress_css2
38+ , testCase "compressCSS 3" test_compress_css3
39+ ]
40+
41+ , testGroup "Context group"
42+ [ testCase "renderDate 1" test_render_date1
43+ , testCase "renderDate 2" test_render_date1
44+ ]
45+
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
50+ , testCase "toRoot 1" test_to_root1
51+ , testCase "toRoot 2" test_to_root2
52+ , testCase "toRoot 3" test_to_root3
53+ , testCase "removeSpaces 1" test_remove_spaces1
54+ , testCase "removeSpaces 2" test_remove_spaces2
55+ , testProperty "havingExtension count" prop_having_extension_count
56+ , testCase "havingExtension 1" test_having_extension1
57+ , testCase "havingExtension 2" test_having_extension2
58+ ]
5059 ]
5160
5261-- Test that a string always becomes shorter when trimmed.
@@ -64,50 +73,71 @@ prop_trim_empty str = (all isSpace str) ==> null (trim str)
6473-- Strip HTML test cases.
6574test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
6675test_strip_html2 = stripHTML "text" @?= "text"
67−test_strip_html3 = stripHTML "<b>Hakyll</b> is an <i>awesome</i> web framework <img src=\"foo.png\" />" @?=
68− "Hakyll is an awesome web framework "
76+test_strip_html3 =
77+ stripHTML "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
78+ @?= "Hakyll, a website generator"
6979
7080-- 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>"
7283test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
7384
7485-- Split Regex test cases.
75−test_split_regex1 = split "," "1,2,3" @?= ["1", "2", "3"]
76−test_split_regex2 = split "," ",1,2," @?= ["1", "2"]
86+test_split_regex1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
87+test_split_regex2 = splitRegex "," ",1,2," @?= ["1", "2"]
7788
7889-- CSS compression should always decrease the text length.
7990prop_compress_css_length str = length str >= length (compressCSS str)
8091
8192-- Compress CSS test cases.
8293test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
83−test_compress_css2 = compressCSS "img {border :none;;;; }" @?= "img{border:none}"
84−test_compress_css3 = compressCSS "p {font-size : 90%;} h1 {color :white;;; }" @?= "p{font-size:90%}h1{color:white}"
94+test_compress_css2 = compressCSS "img {border :none;;;; }"
95+ @?= "img{border:none}"
96+test_compress_css3 =
97+ compressCSS "p {font-size : 90%;} h1 {color :white;;; }"
98+ @?= "p{font-size:90%}h1{color:white}"
8599
86100-- Date rendering test cases.
87−test_render_date1 = M.lookup (B.pack "date") rendered @?= Just (B.pack "December 30, 2009")
88− where rendered = renderDate "date"
89− "%B %e, %Y"
90− "Unknown date"
91− (M.singleton (B.pack "path")
92− (B.pack "2009-12-30-a-title.markdown"))
93−test_render_date2 = M.lookup (B.pack "date") rendered @?= Just (B.pack "Unknown date")
94− where rendered = renderDate "date"
95− "%B %e, %Y"
96− "Unknown date"
97− (M.singleton (B.pack "path")
98− (B.pack "2009-badness-30-a-title.markdown"))
101+test_render_date1 =
102+ M.lookup "date" rendered @?= Just "December 30, 2009"
103+ where
104+ rendered = renderDate "date" "%B %e, %Y" "Unknown date"
105+ (M.singleton "path" "2009-12-30-a-title.markdown")
106+
107+test_render_date2 = M.lookup "date" rendered @?= Just "Unknown date"
108+ where
109+ rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
110+ M.singleton "path" "2009-badness-30-a-title.markdown"
111+
112+-- toDestination test cases
113+test_to_destination1 = toDestination "/posts/foo.html"
114+ @?= "_site/posts/foo.html"
115+
116+test_to_destination2 = toDestination "$root/posts/foo.html"
117+ @?= "_site/posts/foo.html"
118+
119+test_to_destination3 = toDestination "foo.html" @?= "_site/foo.html"
120+
99121-- toRoot test cases
100122test_to_root1 = toRoot "/posts/foo.html" @?= ".."
101123test_to_root2 = toRoot "posts/foo.html" @?= ".."
102124test_to_root3 = toRoot "foo.html" @?= "."
103125
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"
131+
104132-- Add an extension, and test that they have that extension
105133prop_having_extension_count names extension =
106134 not (any ('.' `elem`) names || any (`elem` extension) "./\\")
107135 ==> havingExtension fullExtension withExtensions == withExtensions
108− where fullExtension = '.' : extension
109− withExtensions = map (++ fullExtension) names
136+ where
137+ fullExtension = '.' : extension
138+ withExtensions = map (++ fullExtension) names
110139
111140-- Having extension test cases
112141test_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"]
143+ @?= ["file.foo"]