@@ -1,140 +0,0 @@
1−import Data.Char
2−import qualified Data.Map as M
3−
4−import Test.Framework (defaultMain, testGroup)
5−import Test.Framework.Providers.QuickCheck2
6−import Test.Framework.Providers.HUnit
7−import Test.QuickCheck
8−import Test.HUnit
9−
10−import Text.Hakyll.CompressCSS
11−import Text.Hakyll.Util
12−import Text.Hakyll.Regex
13−import Text.Hakyll.Context
14−import Text.Hakyll.File
15−
16−main = defaultMain tests
17−
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− , testCase "compressCSS 4" test_compress_css4
40− ]
41−
42− , testGroup "Context group"
43− [ testCase "renderDate 1" test_render_date1
44− , testCase "renderDate 2" test_render_date1
45− , testCase "changeExtension 1" test_change_extension1
46− ]
47−
48− , testGroup "File group"
49− [ testCase "toRoot 1" test_to_root1
50− , testCase "toRoot 2" test_to_root2
51− , testCase "toRoot 3" test_to_root3
52− , testCase "removeSpaces 1" test_remove_spaces1
53− , testCase "removeSpaces 2" test_remove_spaces2
54− -- , testProperty "havingExtension count" prop_having_extension_count
55− , testCase "havingExtension 1" test_having_extension1
56− , testCase "havingExtension 2" test_having_extension2
57− ]
58− ]
59−
60−-- Test that a string always becomes shorter when trimmed.
61−prop_trim_length str = length str >= length (trim str)
62−
63−-- Check that a string which does not start or end with a space is not trimmed.
64−prop_trim_id str = isAlreadyTrimmed ==> str == (trim str)
65− where
66− isAlreadyTrimmed :: Bool
67− isAlreadyTrimmed = (not $ isSpace $ head str) && (not $ isSpace $ last str)
68−
69−-- An string of only spaces should be reduced to an empty string.
70−prop_trim_empty str = (all isSpace str) ==> null (trim str)
71−
72−-- Strip HTML test cases.
73−test_strip_html1 = stripHTML "<b>text</b>" @?= "text"
74−test_strip_html2 = stripHTML "text" @?= "text"
75−test_strip_html3 =
76− stripHTML "<b>Hakyll</b>, a <i>website</i> generator<img src=\"foo.png\" />"
77− @?= "Hakyll, a website generator"
78−
79−-- Link test cases.
80−test_link1 = link "foo bar" "/foo/bar.html"
81− @?= "<a href=\"/foo/bar.html\">foo bar</a>"
82−test_link2 = link "back home" "/" @?= "<a href=\"/\">back home</a>"
83−
84−-- Split Regex test cases.
85−test_split_regex1 = splitRegex "," "1,2,3" @?= ["1", "2", "3"]
86−test_split_regex2 = splitRegex "," ",1,2," @?= ["1", "2"]
87−
88−-- CSS compression should always decrease the text length.
89−prop_compress_css_length str = length str >= length (compressCSS str)
90−
91−-- Compress CSS test cases.
92−test_compress_css1 = compressCSS "a { \n color : red; }" @?= "a{color:red}"
93−test_compress_css2 = compressCSS "img {border :none;;;; }"
94− @?= "img{border:none}"
95−test_compress_css3 =
96− compressCSS "p {font-size : 90%;} h1 {color :white;;; }"
97− @?= "p{font-size:90%}h1{color:white}"
98−test_compress_css4 = compressCSS "a { /* /* red is pretty cool */ color: red; }"
99− @?= "a{color:red}"
100−
101−-- Date rendering test cases.
102−test_render_date1 =
103− M.lookup "date" rendered @?= Just "December 30, 2009"
104− where
105− rendered = renderDate "date" "%B %e, %Y" "Unknown date"
106− (M.singleton "path" "2009-12-30-a-title.markdown")
107−
108−test_render_date2 = M.lookup "date" rendered @?= Just "Unknown date"
109− where
110− rendered = renderDate "date" "%B %e, %Y" "Unknown date" $
111− M.singleton "path" "2009-badness-30-a-title.markdown"
112−
113−-- changeExtension test cases.
114−test_change_extension1 = M.lookup "url" rendered @?= Just "foo.php"
115− where
116− rendered = changeExtension "php" (M.singleton "url" "foo.html")
117−
118−-- toRoot test cases
119−test_to_root1 = toRoot "/posts/foo.html" @?= ".."
120−test_to_root2 = toRoot "posts/foo.html" @?= ".."
121−test_to_root3 = toRoot "foo.html" @?= "."
122−
123−-- removeSpaces test cases
124−test_remove_spaces1 = removeSpaces "$root/tags/random crap.html"
125− @?= "$root/tags/random-crap.html"
126−test_remove_spaces2 = removeSpaces "another simple example.zip"
127− @?= "another-simple-example.zip"
128−
129−-- Add an extension, and test that they have that extension
130−prop_having_extension_count names extension =
131− not (any ('.' `elem`) names || any (`elem` extension) "./\\")
132− ==> havingExtension fullExtension withExtensions == withExtensions
133− where
134− fullExtension = '.' : extension
135− withExtensions = map (++ fullExtension) names
136−
137−-- Having extension test cases
138−test_having_extension1 = havingExtension ".foo" ["file.bar", "file.txt"] @?= []
139−test_having_extension2 = havingExtension ".foo" ["file.foo", "file.txt"]
140− @?= ["file.foo"]